sigaction.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <features.h>
  16. #include <errno.h>
  17. #include <signal.h>
  18. #include <string.h>
  19. #include <sys/syscall.h>
  20. /* Experimentally off - libc_hidden_proto(memcpy) */
  21. /* The difference here is that the sigaction structure used in the
  22. kernel is not the same as we use in the libc. Therefore we must
  23. translate it here. */
  24. #include <bits/kernel_sigaction.h>
  25. #ifndef LIBC_SIGACTION
  26. extern __typeof(sigaction) __libc_sigaction;
  27. #endif
  28. #if defined __NR_rt_sigaction
  29. /* If ACT is not NULL, change the action for SIG to *ACT.
  30. If OACT is not NULL, put the old action for SIG in *OACT. */
  31. int
  32. __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  33. {
  34. int result;
  35. struct kernel_sigaction kact, koact;
  36. if (act) {
  37. kact.k_sa_handler = act->sa_handler;
  38. memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
  39. kact.sa_flags = act->sa_flags;
  40. # ifdef HAVE_SA_RESTORER
  41. kact.sa_restorer = act->sa_restorer;
  42. # endif
  43. }
  44. /* XXX The size argument hopefully will have to be changed to the
  45. real size of the user-level sigset_t. */
  46. result = __syscall_rt_sigaction(sig,
  47. act ? __ptrvalue (&kact) : NULL,
  48. oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
  49. if (oact && result >= 0) {
  50. oact->sa_handler = koact.k_sa_handler;
  51. memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
  52. oact->sa_flags = koact.sa_flags;
  53. # ifdef HAVE_SA_RESTORER
  54. oact->sa_restorer = koact.sa_restorer;
  55. # endif
  56. }
  57. return result;
  58. }
  59. #else
  60. /* If ACT is not NULL, change the action for SIG to *ACT.
  61. If OACT is not NULL, put the old action for SIG in *OACT. */
  62. int
  63. __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  64. {
  65. int result;
  66. struct old_kernel_sigaction kact, koact;
  67. if (act) {
  68. kact.k_sa_handler = act->sa_handler;
  69. kact.sa_mask = act->sa_mask.__val[0];
  70. kact.sa_flags = act->sa_flags;
  71. # ifdef HAVE_SA_RESTORER
  72. kact.sa_restorer = act->sa_restorer;
  73. # endif
  74. }
  75. result = __syscall_sigaction(sig,
  76. act ? __ptrvalue (&kact) : NULL,
  77. oact ? __ptrvalue (&koact) : NULL);
  78. if (oact && result >= 0) {
  79. oact->sa_handler = koact.k_sa_handler;
  80. oact->sa_mask.__val[0] = koact.sa_mask;
  81. oact->sa_flags = koact.sa_flags;
  82. # ifdef HAVE_SA_RESTORER
  83. oact->sa_restorer = koact.sa_restorer;
  84. # endif
  85. }
  86. return result;
  87. }
  88. #endif
  89. #ifndef LIBC_SIGACTION
  90. /* libc_hidden_proto(sigaction) */
  91. weak_alias(__libc_sigaction,sigaction)
  92. libc_hidden_weak(sigaction)
  93. #endif