sigtimedwait.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Copyright (C) 1997,1998,2000,2002,2003,2004 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 <pthreadP.h>
  15. #include <errno.h>
  16. #include <signal.h>
  17. #include <string.h>
  18. #include <sysdep-cancel.h>
  19. #include <sys/syscall.h>
  20. #ifdef __NR_rt_sigtimedwait
  21. static int
  22. do_sigtimedwait (const sigset_t *set, siginfo_t *info,
  23. const struct timespec *timeout)
  24. {
  25. #ifdef SIGCANCEL
  26. sigset_t tmpset;
  27. if (set != NULL
  28. && (__builtin_expect (__sigismember (set, SIGCANCEL), 0)
  29. # ifdef SIGSETXID
  30. || __builtin_expect (__sigismember (set, SIGSETXID), 0)
  31. # endif
  32. ))
  33. {
  34. /* Create a temporary mask without the bit for SIGCANCEL set. */
  35. // We are not copying more than we have to.
  36. memcpy (&tmpset, set, _NSIG / 8);
  37. __sigdelset (&tmpset, SIGCANCEL);
  38. # ifdef SIGSETXID
  39. __sigdelset (&tmpset, SIGSETXID);
  40. # endif
  41. set = &tmpset;
  42. }
  43. #endif
  44. /* XXX The size argument hopefully will have to be changed to the
  45. real size of the user-level sigset_t. */
  46. int result = INLINE_SYSCALL (rt_sigtimedwait, 4, set,
  47. info, timeout, _NSIG / 8);
  48. /* The kernel generates a SI_TKILL code in si_code in case tkill is
  49. used. tkill is transparently used in raise(). Since having
  50. SI_TKILL as a code is useful in general we fold the results
  51. here. */
  52. if (result != -1 && info != NULL && info->si_code == SI_TKILL)
  53. info->si_code = SI_USER;
  54. return result;
  55. }
  56. /* Return any pending signal or wait for one for the given time. */
  57. int
  58. __sigtimedwait (const sigset_t *set, siginfo_t *info,
  59. const struct timespec *timeout)
  60. {
  61. if (SINGLE_THREAD_P)
  62. return do_sigtimedwait (set, info, timeout);
  63. int oldtype = LIBC_CANCEL_ASYNC ();
  64. /* XXX The size argument hopefully will have to be changed to the
  65. real size of the user-level sigset_t. */
  66. int result = do_sigtimedwait (set, info, timeout);
  67. LIBC_CANCEL_RESET (oldtype);
  68. return result;
  69. }
  70. weak_alias (__sigtimedwait, sigtimedwait)
  71. #endif