signal.in.h 14 KB

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