sigaction.c 3.1 KB

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