sigwait.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 (set, sig)
  60. const sigset_t *set;
  61. int *sig;
  62. {
  63. #ifndef NOT_IN_libc
  64. return __libc_maybe_call2 (pthread_sigwait, (set, sig),
  65. do_sigwait (set, sig));
  66. #else
  67. return do_sigwait (set, sig);
  68. #endif
  69. }
  70. libc_hidden_def (__sigwait)
  71. weak_alias (__sigwait, sigwait)
  72. strong_alias (__sigwait, __libc_sigwait)
  73. /* Cancellation is handled in __pthread_sigwait. */
  74. LIBC_CANCEL_HANDLED ();