sigwait.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <errno.h>
  15. #include <signal.h>
  16. #define __need_NULL
  17. #include <stddef.h>
  18. #include <sysdep-cancel.h>
  19. #include <sys/syscall.h>
  20. #include <bits/libc-lock.h>
  21. extern int __syscall_rt_sigtimedwait (const sigset_t *, siginfo_t *,
  22. const struct timespec *, size_t);
  23. /* Return any pending signal or wait for one for the given time. */
  24. static __inline__ int
  25. do_sigwait (const sigset_t *set, int *sig)
  26. {
  27. int ret;
  28. /* XXX The size argument hopefully will have to be changed to the
  29. real size of the user-level sigset_t. */
  30. #ifdef INTERNAL_SYSCALL
  31. INTERNAL_SYSCALL_DECL (err);
  32. ret = INTERNAL_SYSCALL (rt_sigtimedwait, err, 4, set,
  33. NULL, NULL, _NSIG / 8);
  34. if (! INTERNAL_SYSCALL_ERROR_P (ret, err))
  35. {
  36. *sig = ret;
  37. ret = 0;
  38. }
  39. else
  40. ret = INTERNAL_SYSCALL_ERRNO (ret, err);
  41. #else
  42. ret = INLINE_SYSCALL (rt_sigtimedwait, 4, set,
  43. NULL, NULL, _NSIG / 8);
  44. if (ret != -1)
  45. {
  46. *sig = ret;
  47. ret = 0;
  48. }
  49. else
  50. ret = errno;
  51. #endif
  52. return ret;
  53. }
  54. #ifndef SHARED
  55. weak_extern (__pthread_sigwait)
  56. #endif
  57. int
  58. sigwait (const sigset_t *set, int *sig)
  59. {
  60. #ifndef NOT_IN_libc
  61. return __libc_maybe_call2 (pthread_sigwait, (set, sig),
  62. do_sigwait (set, sig));
  63. #else
  64. return do_sigwait (set, sig);
  65. #endif
  66. }
  67. strong_alias(sigwait, __libc_sigwait)
  68. /* Cancellation is handled in __pthread_sigwait. */
  69. LIBC_CANCEL_HANDLED ();