sigaction.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright (C) 1997-2000,2002,2003,2005,2006 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 <signal.h>
  15. #include <sys/syscall.h>
  16. #if defined __NR_rt_sigaction
  17. /* If ACT is not NULL, change the action for SIG to *ACT.
  18. If OACT is not NULL, put the old action for SIG in *OACT. */
  19. int
  20. __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
  21. {
  22. if (unlikely (sig == SIGCANCEL || sig == SIGSETXID)) {
  23. __set_errno (EINVAL);
  24. return -1;
  25. }
  26. /* NB: kernel (as of 2.6.25) will return EINVAL
  27. * if sizeof(act->sa_mask) does not match kernel's sizeof(sigset_t).
  28. * Try to catch this problem at uclibc build time: */
  29. struct BUG_sigset_size {
  30. int BUG_sigset_size
  31. [sizeof(act->sa_mask) == _NSIG / 8 ? 1 : -1];
  32. };
  33. return __syscall_rt_sigaction(sig, act, oact, sizeof(act->sa_mask));
  34. }
  35. #else
  36. # define __need_NULL
  37. # include <stddef.h>
  38. # include <bits/kernel_sigaction.h>
  39. /* If ACT is not NULL, change the action for SIG to *ACT.
  40. If OACT is not NULL, put the old action for SIG in *OACT. */
  41. int
  42. __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
  43. {
  44. int result;
  45. struct old_kernel_sigaction kact, koact;
  46. if (unlikely (sig == SIGCANCEL || sig == SIGSETXID)) {
  47. __set_errno (EINVAL);
  48. return -1;
  49. }
  50. if (act) {
  51. kact.k_sa_handler = act->sa_handler;
  52. kact.sa_mask = act->sa_mask.__val[0];
  53. kact.sa_flags = act->sa_flags;
  54. # ifdef HAVE_SA_RESTORER
  55. kact.sa_restorer = act->sa_restorer;
  56. # endif
  57. }
  58. result = __syscall_sigaction(sig,
  59. act ? &kact : NULL,
  60. oact ? &koact : NULL);
  61. if (oact && result >= 0) {
  62. oact->sa_handler = koact.k_sa_handler;
  63. oact->sa_mask.__val[0] = koact.sa_mask;
  64. oact->sa_flags = koact.sa_flags;
  65. # ifdef HAVE_SA_RESTORER
  66. oact->sa_restorer = koact.sa_restorer;
  67. # endif
  68. }
  69. return result;
  70. }
  71. #endif
  72. #ifndef LIBC_SIGACTION
  73. # ifndef __UCLIBC_HAS_THREADS__
  74. strong_alias(__libc_sigaction,sigaction)
  75. libc_hidden_def(sigaction)
  76. # else
  77. weak_alias(__libc_sigaction,sigaction)
  78. libc_hidden_weak(sigaction)
  79. # endif
  80. #endif