signal.in.h 11 KB

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