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