sigaction.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright (C) 1997-2019 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 <errno.h>
  15. #include <signal.h>
  16. #include <string.h>
  17. #include <sysdep.h>
  18. #include <sys/syscall.h>
  19. /* New ports should not define the obsolete SA_RESTORER, however some
  20. architecture requires for compat mode and/or due old ABI. */
  21. #include <kernel_sigaction.h>
  22. #ifndef SA_RESTORER
  23. # define SET_SA_RESTORER(kact, act)
  24. # define RESET_SA_RESTORER(act, kact)
  25. #endif
  26. /* SPARC passes the restore function as an argument to rt_sigaction. */
  27. #ifndef STUB
  28. # define STUB(act, sigsetsize) (sigsetsize)
  29. #endif
  30. /* If ACT is not NULL, change the action for SIG to *ACT.
  31. If OACT is not NULL, put the old action for SIG in *OACT. */
  32. int
  33. __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  34. {
  35. int result;
  36. struct kernel_sigaction kact, koact;
  37. if (act)
  38. {
  39. kact.k_sa_handler = act->sa_handler;
  40. memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
  41. kact.sa_flags = act->sa_flags;
  42. SET_SA_RESTORER (&kact, act);
  43. }
  44. /* XXX The size argument hopefully will have to be changed to the
  45. real size of the user-level sigset_t. */
  46. result = INLINE_SYSCALL_CALL (rt_sigaction, sig,
  47. act ? &kact : NULL,
  48. oact ? &koact : NULL, STUB (act, _NSIG / 8));
  49. if (oact && result >= 0)
  50. {
  51. oact->sa_handler = koact.k_sa_handler;
  52. memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
  53. oact->sa_flags = koact.sa_flags;
  54. RESET_SA_RESTORER (oact, &koact);
  55. }
  56. return result;
  57. }
  58. libc_hidden_def (__libc_sigaction)
  59. #include <nptl/sigaction.c>