sigwait.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <bp-checks.h>
  22. #include <bits/libc-lock.h>
  23. extern int __syscall_rt_sigtimedwait (const sigset_t *, siginfo_t *,
  24. const struct timespec *, size_t);
  25. /* Return any pending signal or wait for one for the given time. */
  26. static __inline__ int
  27. do_sigwait (const sigset_t *set, int *sig)
  28. {
  29. int ret;
  30. /* XXX The size argument hopefully will have to be changed to the
  31. real size of the user-level sigset_t. */
  32. #ifdef INTERNAL_SYSCALL
  33. INTERNAL_SYSCALL_DECL (err);
  34. ret = INTERNAL_SYSCALL (rt_sigtimedwait, err, 4, CHECK_SIGSET (set),
  35. NULL, NULL, _NSIG / 8);
  36. if (! INTERNAL_SYSCALL_ERROR_P (ret, err))
  37. {
  38. *sig = ret;
  39. ret = 0;
  40. }
  41. else
  42. ret = INTERNAL_SYSCALL_ERRNO (ret, err);
  43. #else
  44. ret = INLINE_SYSCALL (rt_sigtimedwait, 4, CHECK_SIGSET (set),
  45. NULL, NULL, _NSIG / 8);
  46. if (ret != -1)
  47. {
  48. *sig = ret;
  49. ret = 0;
  50. }
  51. else
  52. ret = errno;
  53. #endif
  54. return ret;
  55. }
  56. #ifndef SHARED
  57. weak_extern (__pthread_sigwait)
  58. #endif
  59. int
  60. __sigwait (set, sig)
  61. const sigset_t *set;
  62. int *sig;
  63. {
  64. #ifndef NOT_IN_libc
  65. return __libc_maybe_call2 (pthread_sigwait, (set, sig),
  66. do_sigwait (set, sig));
  67. #else
  68. return do_sigwait (set, sig);
  69. #endif
  70. }
  71. libc_hidden_def (__sigwait)
  72. weak_alias (__sigwait, sigwait)
  73. strong_alias (__sigwait, __libc_sigwait)
  74. /* Cancellation is handled in __pthread_sigwait. */
  75. LIBC_CANCEL_HANDLED ();