sigwait.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Copyright (C) 1997, 1998, 2000, 2002, 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <errno.h>
  16. #include <signal.h>
  17. #define __need_NULL
  18. #include <stddef.h>
  19. #include <sysdep-cancel.h>
  20. #include <sys/syscall.h>
  21. #include <bits/libc-lock.h>
  22. extern int __syscall_rt_sigtimedwait (const sigset_t *, siginfo_t *,
  23. const struct timespec *, size_t);
  24. /* Return any pending signal or wait for one for the given time. */
  25. static __inline__ int
  26. do_sigwait (const sigset_t *set, int *sig)
  27. {
  28. int ret;
  29. /* XXX The size argument hopefully will have to be changed to the
  30. real size of the user-level sigset_t. */
  31. #ifdef INTERNAL_SYSCALL
  32. INTERNAL_SYSCALL_DECL (err);
  33. ret = INTERNAL_SYSCALL (rt_sigtimedwait, err, 4, set,
  34. NULL, NULL, _NSIG / 8);
  35. if (! INTERNAL_SYSCALL_ERROR_P (ret, err))
  36. {
  37. *sig = ret;
  38. ret = 0;
  39. }
  40. else
  41. ret = INTERNAL_SYSCALL_ERRNO (ret, err);
  42. #else
  43. ret = INLINE_SYSCALL (rt_sigtimedwait, 4, set,
  44. NULL, NULL, _NSIG / 8);
  45. if (ret != -1)
  46. {
  47. *sig = ret;
  48. ret = 0;
  49. }
  50. else
  51. ret = errno;
  52. #endif
  53. return ret;
  54. }
  55. #ifndef SHARED
  56. weak_extern (__pthread_sigwait)
  57. #endif
  58. int
  59. sigwait (const sigset_t *set, int *sig)
  60. {
  61. #ifndef NOT_IN_libc
  62. return __libc_maybe_call2 (pthread_sigwait, (set, sig),
  63. do_sigwait (set, sig));
  64. #else
  65. return do_sigwait (set, sig);
  66. #endif
  67. }
  68. strong_alias(sigwait, __libc_sigwait)
  69. /* Cancellation is handled in __pthread_sigwait. */
  70. LIBC_CANCEL_HANDLED ();