signal.in.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /* A GNU-like <signal.h>.
  2. Copyright (C) 2006-2011 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 <http://www.gnu.org/licenses/>. */
  13. #if __GNUC__ >= 3
  14. @PRAGMA_SYSTEM_HEADER@
  15. #endif
  16. @PRAGMA_COLUMNS@
  17. #include "config.h"
  18. #if defined __need_sig_atomic_t || defined __need_sigset_t
  19. /* Special invocation convention inside glibc header files. */
  20. # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
  21. #else
  22. /* Normal invocation convention. */
  23. #ifndef _@GUARD_PREFIX@_SIGNAL_H
  24. /* The include_next requires a split double-inclusion guard. */
  25. #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
  26. #ifndef _@GUARD_PREFIX@_SIGNAL_H
  27. #define _@GUARD_PREFIX@_SIGNAL_H
  28. /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
  29. /* The definition of _GL_ARG_NONNULL is copied here. */
  30. /* The definition of _GL_WARN_ON_USE is copied here. */
  31. /* Define pid_t, uid_t.
  32. Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>. */
  33. #include <sys/types.h>
  34. /* On AIX, sig_atomic_t already includes volatile. C99 requires that
  35. 'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
  36. Hence, redefine this to a non-volatile type as needed. */
  37. #if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
  38. # if !GNULIB_defined_sig_atomic_t
  39. typedef int rpl_sig_atomic_t;
  40. # undef sig_atomic_t
  41. # define sig_atomic_t rpl_sig_atomic_t
  42. # define GNULIB_defined_sig_atomic_t 1
  43. # endif
  44. #endif
  45. /* A set or mask of signals. */
  46. #if !@HAVE_SIGSET_T@
  47. # if !GNULIB_defined_sigset_t
  48. typedef unsigned int sigset_t;
  49. # define GNULIB_defined_sigset_t 1
  50. # endif
  51. #endif
  52. /* Define sighandler_t, the type of signal handlers. A GNU extension. */
  53. #if !@HAVE_SIGHANDLER_T@
  54. # ifdef __cplusplus
  55. extern "C" {
  56. # endif
  57. # if !GNULIB_defined_sighandler_t
  58. typedef void (*sighandler_t) (int);
  59. # define GNULIB_defined_sighandler_t 1
  60. # endif
  61. # ifdef __cplusplus
  62. }
  63. # endif
  64. #endif
  65. #if @GNULIB_SIGNAL_H_SIGPIPE@
  66. # ifndef SIGPIPE
  67. /* Define SIGPIPE to a value that does not overlap with other signals. */
  68. # define SIGPIPE 13
  69. # define GNULIB_defined_SIGPIPE 1
  70. /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
  71. 'write', 'stdio'. */
  72. # endif
  73. #endif
  74. /* Maximum signal number + 1. */
  75. #ifndef NSIG
  76. # if defined __TANDEM
  77. # define NSIG 32
  78. # endif
  79. #endif
  80. #if @GNULIB_SIGPROCMASK@
  81. # if !@HAVE_POSIX_SIGNALBLOCKING@
  82. /* Maximum signal number + 1. */
  83. # ifndef NSIG
  84. # define NSIG 32
  85. # endif
  86. /* This code supports only 32 signals. */
  87. # if !GNULIB_defined_verify_NSIG_constraint
  88. typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
  89. # define GNULIB_defined_verify_NSIG_constraint 1
  90. # endif
  91. # endif
  92. /* Test whether a given signal is contained in a signal set. */
  93. # if @HAVE_POSIX_SIGNALBLOCKING@
  94. /* This function is defined as a macro on MacOS X. */
  95. # if defined __cplusplus && defined GNULIB_NAMESPACE
  96. # undef sigismember
  97. # endif
  98. # else
  99. _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
  100. _GL_ARG_NONNULL ((1)));
  101. # endif
  102. _GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
  103. _GL_CXXALIASWARN (sigismember);
  104. /* Initialize a signal set to the empty set. */
  105. # if @HAVE_POSIX_SIGNALBLOCKING@
  106. /* This function is defined as a macro on MacOS X. */
  107. # if defined __cplusplus && defined GNULIB_NAMESPACE
  108. # undef sigemptyset
  109. # endif
  110. # else
  111. _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
  112. # endif
  113. _GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
  114. _GL_CXXALIASWARN (sigemptyset);
  115. /* Add a signal to a signal set. */
  116. # if @HAVE_POSIX_SIGNALBLOCKING@
  117. /* This function is defined as a macro on MacOS X. */
  118. # if defined __cplusplus && defined GNULIB_NAMESPACE
  119. # undef sigaddset
  120. # endif
  121. # else
  122. _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
  123. _GL_ARG_NONNULL ((1)));
  124. # endif
  125. _GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
  126. _GL_CXXALIASWARN (sigaddset);
  127. /* Remove a signal from a signal set. */
  128. # if @HAVE_POSIX_SIGNALBLOCKING@
  129. /* This function is defined as a macro on MacOS X. */
  130. # if defined __cplusplus && defined GNULIB_NAMESPACE
  131. # undef sigdelset
  132. # endif
  133. # else
  134. _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
  135. _GL_ARG_NONNULL ((1)));
  136. # endif
  137. _GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
  138. _GL_CXXALIASWARN (sigdelset);
  139. /* Fill a signal set with all possible signals. */
  140. # if @HAVE_POSIX_SIGNALBLOCKING@
  141. /* This function is defined as a macro on MacOS X. */
  142. # if defined __cplusplus && defined GNULIB_NAMESPACE
  143. # undef sigfillset
  144. # endif
  145. # else
  146. _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
  147. # endif
  148. _GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
  149. _GL_CXXALIASWARN (sigfillset);
  150. /* Return the set of those blocked signals that are pending. */
  151. # if !@HAVE_POSIX_SIGNALBLOCKING@
  152. _GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
  153. # endif
  154. _GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
  155. _GL_CXXALIASWARN (sigpending);
  156. /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
  157. Then, if SET is not NULL, affect the current set of blocked signals by
  158. combining it with *SET as indicated in OPERATION.
  159. In this implementation, you are not allowed to change a signal handler
  160. while the signal is blocked. */
  161. # if !@HAVE_POSIX_SIGNALBLOCKING@
  162. # define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
  163. # define SIG_SETMASK 1 /* blocked_set = *set; */
  164. # define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
  165. _GL_FUNCDECL_SYS (sigprocmask, int,
  166. (int operation, const sigset_t *set, sigset_t *old_set));
  167. # endif
  168. _GL_CXXALIAS_SYS (sigprocmask, int,
  169. (int operation, const sigset_t *set, sigset_t *old_set));
  170. _GL_CXXALIASWARN (sigprocmask);
  171. /* Install the handler FUNC for signal SIG, and return the previous
  172. handler. */
  173. # ifdef __cplusplus
  174. extern "C" {
  175. # endif
  176. # if !GNULIB_defined_function_taking_int_returning_void_t
  177. typedef void (*_gl_function_taking_int_returning_void_t) (int);
  178. # define GNULIB_defined_function_taking_int_returning_void_t 1
  179. # endif
  180. # ifdef __cplusplus
  181. }
  182. # endif
  183. # if !@HAVE_POSIX_SIGNALBLOCKING@
  184. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  185. # define signal rpl_signal
  186. # endif
  187. _GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
  188. (int sig, _gl_function_taking_int_returning_void_t func));
  189. _GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
  190. (int sig, _gl_function_taking_int_returning_void_t func));
  191. # else
  192. _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
  193. (int sig, _gl_function_taking_int_returning_void_t func));
  194. # endif
  195. _GL_CXXALIASWARN (signal);
  196. /* Raise signal SIG. */
  197. # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE
  198. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  199. # undef raise
  200. # define raise rpl_raise
  201. # endif
  202. _GL_FUNCDECL_RPL (raise, int, (int sig));
  203. _GL_CXXALIAS_RPL (raise, int, (int sig));
  204. # else
  205. _GL_CXXALIAS_SYS (raise, int, (int sig));
  206. # endif
  207. _GL_CXXALIASWARN (raise);
  208. #elif defined GNULIB_POSIXCHECK
  209. # undef sigaddset
  210. # if HAVE_RAW_DECL_SIGADDSET
  211. _GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
  212. "use the gnulib module sigprocmask for portability");
  213. # endif
  214. # undef sigdelset
  215. # if HAVE_RAW_DECL_SIGDELSET
  216. _GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
  217. "use the gnulib module sigprocmask for portability");
  218. # endif
  219. # undef sigemptyset
  220. # if HAVE_RAW_DECL_SIGEMPTYSET
  221. _GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
  222. "use the gnulib module sigprocmask for portability");
  223. # endif
  224. # undef sigfillset
  225. # if HAVE_RAW_DECL_SIGFILLSET
  226. _GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
  227. "use the gnulib module sigprocmask for portability");
  228. # endif
  229. # undef sigismember
  230. # if HAVE_RAW_DECL_SIGISMEMBER
  231. _GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
  232. "use the gnulib module sigprocmask for portability");
  233. # endif
  234. # undef sigpending
  235. # if HAVE_RAW_DECL_SIGPENDING
  236. _GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
  237. "use the gnulib module sigprocmask for portability");
  238. # endif
  239. # undef sigprocmask
  240. # if HAVE_RAW_DECL_SIGPROCMASK
  241. _GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
  242. "use the gnulib module sigprocmask for portability");
  243. # endif
  244. #endif /* @GNULIB_SIGPROCMASK@ */
  245. #if @GNULIB_SIGACTION@
  246. # if !@HAVE_SIGACTION@
  247. # if !@HAVE_SIGINFO_T@
  248. # if !GNULIB_defined_siginfo_types
  249. /* Present to allow compilation, but unsupported by gnulib. */
  250. union sigval
  251. {
  252. int sival_int;
  253. void *sival_ptr;
  254. };
  255. /* Present to allow compilation, but unsupported by gnulib. */
  256. struct siginfo_t
  257. {
  258. int si_signo;
  259. int si_code;
  260. int si_errno;
  261. pid_t si_pid;
  262. uid_t si_uid;
  263. void *si_addr;
  264. int si_status;
  265. long si_band;
  266. union sigval si_value;
  267. };
  268. typedef struct siginfo_t siginfo_t;
  269. # define GNULIB_defined_siginfo_types 1
  270. # endif
  271. # endif /* !@HAVE_SIGINFO_T@ */
  272. /* We assume that platforms which lack the sigaction() function also lack
  273. the 'struct sigaction' type, and vice versa. */
  274. # if !GNULIB_defined_struct_sigaction
  275. struct sigaction
  276. {
  277. union
  278. {
  279. void (*_sa_handler) (int);
  280. /* Present to allow compilation, but unsupported by gnulib. POSIX
  281. says that implementations may, but not must, make sa_sigaction
  282. overlap with sa_handler, but we know of no implementation where
  283. they do not overlap. */
  284. void (*_sa_sigaction) (int, siginfo_t *, void *);
  285. } _sa_func;
  286. sigset_t sa_mask;
  287. /* Not all POSIX flags are supported. */
  288. int sa_flags;
  289. };
  290. # define sa_handler _sa_func._sa_handler
  291. # define sa_sigaction _sa_func._sa_sigaction
  292. /* Unsupported flags are not present. */
  293. # define SA_RESETHAND 1
  294. # define SA_NODEFER 2
  295. # define SA_RESTART 4
  296. # define GNULIB_defined_struct_sigaction 1
  297. # endif
  298. _GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
  299. struct sigaction *restrict));
  300. # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
  301. # define sa_sigaction sa_handler
  302. # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
  303. _GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
  304. struct sigaction *restrict));
  305. _GL_CXXALIASWARN (sigaction);
  306. #elif defined GNULIB_POSIXCHECK
  307. # undef sigaction
  308. # if HAVE_RAW_DECL_SIGACTION
  309. _GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
  310. "use the gnulib module sigaction for portability");
  311. # endif
  312. #endif
  313. /* Some systems don't have SA_NODEFER. */
  314. #ifndef SA_NODEFER
  315. # define SA_NODEFER 0
  316. #endif
  317. #endif /* _@GUARD_PREFIX@_SIGNAL_H */
  318. #endif /* _@GUARD_PREFIX@_SIGNAL_H */
  319. #endif