sigaction.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #include <bits/kernel_sigaction.h>
  21. #ifndef LIBC_SIGACTION
  22. extern __typeof(sigaction) __libc_sigaction;
  23. #endif
  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. /* NB: kernel (as of 2.6.25) will return EINVAL
  31. * if sizeof(act->sa_mask) does not match kernel's sizeof(sigset_t).
  32. * Try to catch this problem at uclibc build time: */
  33. struct BUG_sigset_size {
  34. int BUG_sigset_size
  35. [sizeof(act->sa_mask) == _NSIG / 8 ? 1 : -1];
  36. };
  37. return __syscall_rt_sigaction(sig, act, oact, sizeof(act->sa_mask));
  38. }
  39. #else
  40. /* If ACT is not NULL, change the action for SIG to *ACT.
  41. If OACT is not NULL, put the old action for SIG in *OACT. */
  42. int
  43. __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
  44. {
  45. int result;
  46. struct old_kernel_sigaction kact, koact;
  47. if (act) {
  48. kact.k_sa_handler = act->sa_handler;
  49. kact.sa_mask = act->sa_mask.__val[0];
  50. kact.sa_flags = act->sa_flags;
  51. # ifdef HAVE_SA_RESTORER
  52. kact.sa_restorer = act->sa_restorer;
  53. # endif
  54. }
  55. result = __syscall_sigaction(sig,
  56. act ? &kact : NULL,
  57. oact ? &koact : NULL);
  58. if (oact && result >= 0) {
  59. oact->sa_handler = koact.k_sa_handler;
  60. oact->sa_mask.__val[0] = koact.sa_mask;
  61. oact->sa_flags = koact.sa_flags;
  62. # ifdef HAVE_SA_RESTORER
  63. oact->sa_restorer = koact.sa_restorer;
  64. # endif
  65. }
  66. return result;
  67. }
  68. #endif
  69. #ifndef LIBC_SIGACTION
  70. weak_alias(__libc_sigaction,sigaction)
  71. libc_hidden_weak(sigaction)
  72. #endif