signal.in.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. /* A GNU-like <signal.h>.
  2. Copyright (C) 2006-2014 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 Lesser 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 Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser 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. /* Mac OS 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. /* When also using extern inline, suppress the use of static inline in
  163. standard headers of problematic Apple configurations, as Libc at
  164. least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
  165. <http://lists.gnu.org/archive/html/bug-gnulib/2012-12/msg00023.html>.
  166. Perhaps Apple will fix this some day. */
  167. #if (defined _GL_EXTERN_INLINE_IN_USE && defined __APPLE__ \
  168. && (defined __i386__ || defined __x86_64__))
  169. # undef sigaddset
  170. # undef sigdelset
  171. # undef sigemptyset
  172. # undef sigfillset
  173. # undef sigismember
  174. #endif
  175. /* Test whether a given signal is contained in a signal set. */
  176. # if @HAVE_POSIX_SIGNALBLOCKING@
  177. /* This function is defined as a macro on Mac OS X. */
  178. # if defined __cplusplus && defined GNULIB_NAMESPACE
  179. # undef sigismember
  180. # endif
  181. # else
  182. _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
  183. _GL_ARG_NONNULL ((1)));
  184. # endif
  185. _GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
  186. _GL_CXXALIASWARN (sigismember);
  187. /* Initialize a signal set to the empty set. */
  188. # if @HAVE_POSIX_SIGNALBLOCKING@
  189. /* This function is defined as a macro on Mac OS X. */
  190. # if defined __cplusplus && defined GNULIB_NAMESPACE
  191. # undef sigemptyset
  192. # endif
  193. # else
  194. _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
  195. # endif
  196. _GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
  197. _GL_CXXALIASWARN (sigemptyset);
  198. /* Add a signal to a signal set. */
  199. # if @HAVE_POSIX_SIGNALBLOCKING@
  200. /* This function is defined as a macro on Mac OS X. */
  201. # if defined __cplusplus && defined GNULIB_NAMESPACE
  202. # undef sigaddset
  203. # endif
  204. # else
  205. _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
  206. _GL_ARG_NONNULL ((1)));
  207. # endif
  208. _GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
  209. _GL_CXXALIASWARN (sigaddset);
  210. /* Remove a signal from a signal set. */
  211. # if @HAVE_POSIX_SIGNALBLOCKING@
  212. /* This function is defined as a macro on Mac OS X. */
  213. # if defined __cplusplus && defined GNULIB_NAMESPACE
  214. # undef sigdelset
  215. # endif
  216. # else
  217. _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
  218. _GL_ARG_NONNULL ((1)));
  219. # endif
  220. _GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
  221. _GL_CXXALIASWARN (sigdelset);
  222. /* Fill a signal set with all possible signals. */
  223. # if @HAVE_POSIX_SIGNALBLOCKING@
  224. /* This function is defined as a macro on Mac OS X. */
  225. # if defined __cplusplus && defined GNULIB_NAMESPACE
  226. # undef sigfillset
  227. # endif
  228. # else
  229. _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
  230. # endif
  231. _GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
  232. _GL_CXXALIASWARN (sigfillset);
  233. /* Return the set of those blocked signals that are pending. */
  234. # if !@HAVE_POSIX_SIGNALBLOCKING@
  235. _GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
  236. # endif
  237. _GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
  238. _GL_CXXALIASWARN (sigpending);
  239. /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
  240. Then, if SET is not NULL, affect the current set of blocked signals by
  241. combining it with *SET as indicated in OPERATION.
  242. In this implementation, you are not allowed to change a signal handler
  243. while the signal is blocked. */
  244. # if !@HAVE_POSIX_SIGNALBLOCKING@
  245. # define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
  246. # define SIG_SETMASK 1 /* blocked_set = *set; */
  247. # define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
  248. _GL_FUNCDECL_SYS (sigprocmask, int,
  249. (int operation, const sigset_t *set, sigset_t *old_set));
  250. # endif
  251. _GL_CXXALIAS_SYS (sigprocmask, int,
  252. (int operation, const sigset_t *set, sigset_t *old_set));
  253. _GL_CXXALIASWARN (sigprocmask);
  254. /* Install the handler FUNC for signal SIG, and return the previous
  255. handler. */
  256. # ifdef __cplusplus
  257. extern "C" {
  258. # endif
  259. # if !GNULIB_defined_function_taking_int_returning_void_t
  260. typedef void (*_gl_function_taking_int_returning_void_t) (int);
  261. # define GNULIB_defined_function_taking_int_returning_void_t 1
  262. # endif
  263. # ifdef __cplusplus
  264. }
  265. # endif
  266. # if !@HAVE_POSIX_SIGNALBLOCKING@
  267. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  268. # define signal rpl_signal
  269. # endif
  270. _GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
  271. (int sig, _gl_function_taking_int_returning_void_t func));
  272. _GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
  273. (int sig, _gl_function_taking_int_returning_void_t func));
  274. # else
  275. _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
  276. (int sig, _gl_function_taking_int_returning_void_t func));
  277. # endif
  278. _GL_CXXALIASWARN (signal);
  279. # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE
  280. /* Raise signal SIGPIPE. */
  281. _GL_EXTERN_C int _gl_raise_SIGPIPE (void);
  282. # endif
  283. #elif defined GNULIB_POSIXCHECK
  284. # undef sigaddset
  285. # if HAVE_RAW_DECL_SIGADDSET
  286. _GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
  287. "use the gnulib module sigprocmask for portability");
  288. # endif
  289. # undef sigdelset
  290. # if HAVE_RAW_DECL_SIGDELSET
  291. _GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
  292. "use the gnulib module sigprocmask for portability");
  293. # endif
  294. # undef sigemptyset
  295. # if HAVE_RAW_DECL_SIGEMPTYSET
  296. _GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
  297. "use the gnulib module sigprocmask for portability");
  298. # endif
  299. # undef sigfillset
  300. # if HAVE_RAW_DECL_SIGFILLSET
  301. _GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
  302. "use the gnulib module sigprocmask for portability");
  303. # endif
  304. # undef sigismember
  305. # if HAVE_RAW_DECL_SIGISMEMBER
  306. _GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
  307. "use the gnulib module sigprocmask for portability");
  308. # endif
  309. # undef sigpending
  310. # if HAVE_RAW_DECL_SIGPENDING
  311. _GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
  312. "use the gnulib module sigprocmask for portability");
  313. # endif
  314. # undef sigprocmask
  315. # if HAVE_RAW_DECL_SIGPROCMASK
  316. _GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
  317. "use the gnulib module sigprocmask for portability");
  318. # endif
  319. #endif /* @GNULIB_SIGPROCMASK@ */
  320. #if @GNULIB_SIGACTION@
  321. # if !@HAVE_SIGACTION@
  322. # if !@HAVE_SIGINFO_T@
  323. # if !GNULIB_defined_siginfo_types
  324. /* Present to allow compilation, but unsupported by gnulib. */
  325. union sigval
  326. {
  327. int sival_int;
  328. void *sival_ptr;
  329. };
  330. /* Present to allow compilation, but unsupported by gnulib. */
  331. struct siginfo_t
  332. {
  333. int si_signo;
  334. int si_code;
  335. int si_errno;
  336. pid_t si_pid;
  337. uid_t si_uid;
  338. void *si_addr;
  339. int si_status;
  340. long si_band;
  341. union sigval si_value;
  342. };
  343. typedef struct siginfo_t siginfo_t;
  344. # define GNULIB_defined_siginfo_types 1
  345. # endif
  346. # endif /* !@HAVE_SIGINFO_T@ */
  347. /* We assume that platforms which lack the sigaction() function also lack
  348. the 'struct sigaction' type, and vice versa. */
  349. # if !GNULIB_defined_struct_sigaction
  350. struct sigaction
  351. {
  352. union
  353. {
  354. void (*_sa_handler) (int);
  355. /* Present to allow compilation, but unsupported by gnulib. POSIX
  356. says that implementations may, but not must, make sa_sigaction
  357. overlap with sa_handler, but we know of no implementation where
  358. they do not overlap. */
  359. void (*_sa_sigaction) (int, siginfo_t *, void *);
  360. } _sa_func;
  361. sigset_t sa_mask;
  362. /* Not all POSIX flags are supported. */
  363. int sa_flags;
  364. };
  365. # define sa_handler _sa_func._sa_handler
  366. # define sa_sigaction _sa_func._sa_sigaction
  367. /* Unsupported flags are not present. */
  368. # define SA_RESETHAND 1
  369. # define SA_NODEFER 2
  370. # define SA_RESTART 4
  371. # define GNULIB_defined_struct_sigaction 1
  372. # endif
  373. _GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
  374. struct sigaction *restrict));
  375. # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
  376. # define sa_sigaction sa_handler
  377. # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
  378. _GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
  379. struct sigaction *restrict));
  380. _GL_CXXALIASWARN (sigaction);
  381. #elif defined GNULIB_POSIXCHECK
  382. # undef sigaction
  383. # if HAVE_RAW_DECL_SIGACTION
  384. _GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
  385. "use the gnulib module sigaction for portability");
  386. # endif
  387. #endif
  388. /* Some systems don't have SA_NODEFER. */
  389. #ifndef SA_NODEFER
  390. # define SA_NODEFER 0
  391. #endif
  392. #endif /* _@GUARD_PREFIX@_SIGNAL_H */
  393. #endif /* _@GUARD_PREFIX@_SIGNAL_H */
  394. #endif