sigaction.c 2.5 KB

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