signal.in.h 14 KB

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