sigaction.c 2.5 KB

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