sigtimedwait.c 2.7 KB

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