sig-handler.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Convenience declarations when working with <signal.h>.
  2. Copyright (C) 2008-2020 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program 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
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  13. #ifndef _GL_SIG_HANDLER_H
  14. #define _GL_SIG_HANDLER_H
  15. #include <signal.h>
  16. #ifndef _GL_INLINE_HEADER_BEGIN
  17. #error "Please include config.h first."
  18. #endif
  19. _GL_INLINE_HEADER_BEGIN
  20. #ifndef SIG_HANDLER_INLINE
  21. # define SIG_HANDLER_INLINE _GL_INLINE
  22. #endif
  23. /* Convenience type when working with signal handlers. */
  24. typedef void (*sa_handler_t) (int);
  25. /* Return the handler of a signal, as a sa_handler_t value regardless
  26. of its true type. The resulting function can be compared to
  27. special values like SIG_IGN but it is not portable to call it. */
  28. SIG_HANDLER_INLINE sa_handler_t _GL_ATTRIBUTE_PURE
  29. get_handler (struct sigaction const *a)
  30. {
  31. /* POSIX says that special values like SIG_IGN can only occur when
  32. action.sa_flags does not contain SA_SIGINFO. But in Linux 2.4,
  33. for example, sa_sigaction and sa_handler are aliases and a signal
  34. is ignored if sa_sigaction (after casting) equals SIG_IGN. In
  35. this case, this implementation relies on the fact that the two
  36. are aliases, and simply returns sa_handler. */
  37. return a->sa_handler;
  38. }
  39. _GL_INLINE_HEADER_END
  40. #endif /* _GL_SIG_HANDLER_H */