sigaction.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (C) 2004-2007 Atmel Corporation
  3. *
  4. * This file is subject to the terms and conditions of the GNU Lesser General
  5. * Public License. See the file "COPYING.LIB" in the main directory of this
  6. * archive for more details.
  7. */
  8. #include <errno.h>
  9. #include <signal.h>
  10. #include <string.h>
  11. #include <sys/syscall.h>
  12. #include <bits/kernel_sigaction.h>
  13. #define SA_RESTORER 0x04000000
  14. extern void __default_rt_sa_restorer(void);
  15. /* Experimentally off - libc_hidden_proto(memcpy) */
  16. extern __typeof(sigaction) __libc_sigaction;
  17. /*
  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. */
  21. int __libc_sigaction(int signum, const struct sigaction *act,
  22. struct sigaction *oldact)
  23. {
  24. struct kernel_sigaction kact, koact;
  25. int result;
  26. enum {
  27. SIGSET_MIN_SIZE = sizeof(kact.sa_mask) < sizeof(act->sa_mask)
  28. ? sizeof(kact.sa_mask) : sizeof(act->sa_mask)
  29. };
  30. if (act) {
  31. kact.k_sa_handler = act->sa_handler;
  32. memcpy(&kact.sa_mask, &act->sa_mask, SIGSET_MIN_SIZE);
  33. kact.sa_flags = act->sa_flags;
  34. if (kact.sa_flags & SA_RESTORER)
  35. kact.sa_restorer = act->sa_restorer;
  36. else
  37. kact.sa_restorer = __default_rt_sa_restorer;
  38. kact.sa_flags |= SA_RESTORER;
  39. }
  40. /* NB: kernel (as of 2.6.25) will return EINVAL
  41. * if sizeof(kact.sa_mask) does not match kernel's sizeof(sigset_t) */
  42. result = __syscall_rt_sigaction(signum,
  43. act ? &kact : NULL,
  44. oldact ? &koact : NULL,
  45. sizeof(kact.sa_mask));
  46. if (oldact && result >= 0) {
  47. oldact->sa_handler = koact.k_sa_handler;
  48. memcpy(&oldact->sa_mask, &koact.sa_mask, SIGSET_MIN_SIZE);
  49. oldact->sa_flags = koact.sa_flags;
  50. oldact->sa_restorer = koact.sa_restorer;
  51. }
  52. return result;
  53. }
  54. #ifndef LIBC_SIGACTION
  55. /* libc_hidden_proto(sigaction) */
  56. weak_alias(__libc_sigaction, sigaction)
  57. libc_hidden_weak(sigaction)
  58. #endif