sigaction.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Copyright (C) 1997, 1998, 1999, 2000 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 Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. 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. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. #include <errno.h>
  16. #include <signal.h>
  17. #include <string.h>
  18. #include <sys/syscall.h>
  19. #include <bits/kernel_sigaction.h>
  20. #if defined __NR_rt_sigaction
  21. /* If ACT is not NULL, change the action for SIG to *ACT.
  22. If OACT is not NULL, put the old action for SIG in *OACT. */
  23. int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  24. {
  25. int result;
  26. struct kernel_sigaction kact, koact;
  27. #ifdef SIGCANCEL
  28. if (sig == SIGCANCEL) {
  29. __set_errno (EINVAL);
  30. return -1;
  31. }
  32. #endif
  33. if (act) {
  34. kact.k_sa_handler = act->sa_handler;
  35. memcpy (&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
  36. kact.sa_flags = act->sa_flags;
  37. # ifdef HAVE_SA_RESTORER
  38. kact.sa_restorer = act->sa_restorer;
  39. # endif
  40. }
  41. /* XXX The size argument hopefully will have to be changed to the
  42. real size of the user-level sigset_t. */
  43. result = __syscall_rt_sigaction(sig, 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 (oact->sa_mask));
  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 __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  59. {
  60. int result;
  61. struct old_kernel_sigaction kact, koact;
  62. #ifdef SIGCANCEL
  63. if (sig == SIGCANCEL) {
  64. __set_errno (EINVAL);
  65. return -1;
  66. }
  67. #endif
  68. if (act) {
  69. kact.k_sa_handler = act->sa_handler;
  70. kact.sa_mask = act->sa_mask.__val[0];
  71. kact.sa_flags = act->sa_flags;
  72. # ifdef HAVE_SA_RESTORER
  73. kact.sa_restorer = act->sa_restorer;
  74. # endif
  75. }
  76. result = __syscall_sigaction(sig, 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. weak_alias(__libc_sigaction, sigaction)