sigaction.c 3.2 KB

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