signal.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /* Copyright (C) 1991-2021 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library 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 GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. /*
  15. * ISO C99 Standard: 7.14 Signal handling <signal.h>
  16. */
  17. #ifndef _SIGNAL_H
  18. #define _SIGNAL_H
  19. #include <features.h>
  20. __BEGIN_DECLS
  21. #include <bits/types.h>
  22. #include <bits/signum-generic.h>
  23. #include <bits/types/sig_atomic_t.h>
  24. #if defined __USE_POSIX
  25. #include <bits/types/sigset_t.h>
  26. #endif
  27. #if defined __USE_XOPEN || defined __USE_XOPEN2K
  28. # ifndef __pid_t_defined
  29. typedef __pid_t pid_t;
  30. # define __pid_t_defined
  31. #endif
  32. #ifdef __USE_XOPEN
  33. # endif
  34. # ifndef __uid_t_defined
  35. typedef __uid_t uid_t;
  36. # define __uid_t_defined
  37. # endif
  38. #endif /* Unix98 */
  39. #ifdef __USE_POSIX199309
  40. /* We need `struct timespec' later on. */
  41. # include <bits/types/struct_timespec.h>
  42. #endif
  43. #if defined __USE_POSIX199309 || defined __USE_XOPEN_EXTENDED
  44. # include <bits/types/siginfo_t.h>
  45. # include <bits/siginfo-consts.h>
  46. #endif
  47. #ifdef __USE_MISC
  48. # include <bits/types/sigval_t.h>
  49. #endif
  50. #ifdef __USE_POSIX199309
  51. # include <bits/types/sigevent_t.h>
  52. # include <bits/sigevent-consts.h>
  53. #endif
  54. /* Type of a signal handler. */
  55. typedef void (*__sighandler_t) (int);
  56. /* The X/Open definition of `signal' specifies the SVID semantic. Use
  57. the additional function `sysv_signal' when X/Open compatibility is
  58. requested. */
  59. extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
  60. __THROW;
  61. #ifdef __USE_GNU
  62. extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
  63. __THROW;
  64. #endif
  65. /* Set the handler for the signal SIG to HANDLER, returning the old
  66. handler, or SIG_ERR on error.
  67. By default `signal' has the BSD semantic. */
  68. #ifdef __USE_MISC
  69. extern __sighandler_t signal (int __sig, __sighandler_t __handler)
  70. __THROW;
  71. #else
  72. /* Make sure the used `signal' implementation is the SVID version. */
  73. # ifdef __REDIRECT_NTH
  74. extern __sighandler_t __REDIRECT_NTH (signal,
  75. (int __sig, __sighandler_t __handler),
  76. __sysv_signal);
  77. # else
  78. # define signal __sysv_signal
  79. # endif
  80. #endif
  81. #if defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8
  82. /* The X/Open definition of `signal' conflicts with the BSD version.
  83. So they defined another function `bsd_signal'. */
  84. extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler)
  85. __THROW;
  86. #endif
  87. /* Send signal SIG to process number PID. If PID is zero,
  88. send SIG to all processes in the current process's process group.
  89. If PID is < -1, send SIG to all processes in process group - PID. */
  90. #ifdef __USE_POSIX
  91. extern int kill (__pid_t __pid, int __sig) __THROW;
  92. #endif /* Use POSIX. */
  93. #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
  94. /* Send SIG to all processes in process group PGRP.
  95. If PGRP is zero, send SIG to all processes in
  96. the current process's process group. */
  97. extern int killpg (__pid_t __pgrp, int __sig) __THROW;
  98. #endif /* Use misc || X/Open Unix. */
  99. /* Raise signal SIG, i.e., send SIG to yourself. */
  100. extern int raise (int __sig) __THROW;
  101. #ifdef __USE_MISC
  102. /* SVID names for the same things. */
  103. extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
  104. __THROW;
  105. extern int gsignal (int __sig) __THROW;
  106. #endif /* Use misc. */
  107. #ifdef __USE_XOPEN2K8
  108. /* Print a message describing the meaning of the given signal number. */
  109. extern void psignal (int __sig, const char *__s);
  110. /* Print a message describing the meaning of the given signal information. */
  111. extern void psiginfo (const siginfo_t *__pinfo, const char *__s);
  112. #endif /* POSIX 2008. */
  113. /* The `sigpause' function in X/Open defines the argument as the
  114. signal number. This requires redirecting to another function
  115. because the default version in glibc uses an old BSD interface.
  116. This function is a cancellation point and therefore not marked with
  117. __THROW. */
  118. #ifdef __USE_XOPEN_EXTENDED
  119. # ifdef __GNUC__
  120. extern int sigpause (int __sig) __asm__ ("__xpg_sigpause")
  121. __attribute_deprecated_msg__ ("Use the sigsuspend function instead");
  122. # else
  123. extern int __sigpause (int __sig_or_mask, int __is_sig);
  124. /* Remove a signal from the signal mask and suspend the process. */
  125. # define sigpause(sig) __sigpause ((sig), 1)
  126. # endif
  127. #endif
  128. #ifdef __USE_MISC
  129. /* None of the following functions should be used anymore. They are here
  130. only for compatibility. A single word (`int') is not guaranteed to be
  131. enough to hold a complete signal mask and therefore these functions
  132. simply do not work in many situations. Use `sigprocmask' instead. */
  133. /* Compute mask for signal SIG. */
  134. # define sigmask(sig) \
  135. __glibc_macro_warning ("sigmask is deprecated") \
  136. ((int)(1u << ((sig) - 1)))
  137. /* Block signals in MASK, returning the old mask. */
  138. extern int sigblock (int __mask) __THROW __attribute_deprecated__;
  139. /* Set the mask of blocked signals to MASK, returning the old mask. */
  140. extern int sigsetmask (int __mask) __THROW __attribute_deprecated__;
  141. /* Return currently selected signal mask. */
  142. extern int siggetmask (void) __THROW __attribute_deprecated__;
  143. #endif /* Use misc. */
  144. #ifdef __USE_MISC
  145. # define NSIG _NSIG
  146. #endif
  147. #ifdef __USE_GNU
  148. typedef __sighandler_t sighandler_t;
  149. #endif
  150. /* 4.4 BSD uses the name `sig_t' for this. */
  151. #ifdef __USE_MISC
  152. typedef __sighandler_t sig_t;
  153. #endif
  154. #ifdef __USE_POSIX
  155. /* Clear all signals from SET. */
  156. extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1));
  157. /* Set all signals in SET. */
  158. extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1));
  159. /* Add SIGNO to SET. */
  160. extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
  161. /* Remove SIGNO from SET. */
  162. extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
  163. /* Return 1 if SIGNO is in SET, 0 if not. */
  164. extern int sigismember (const sigset_t *__set, int __signo)
  165. __THROW __nonnull ((1));
  166. # ifdef __USE_GNU
  167. /* Return non-empty value is SET is not empty. */
  168. extern int sigisemptyset (const sigset_t *__set) __THROW __nonnull ((1));
  169. /* Build new signal set by combining the two inputs set using logical AND. */
  170. extern int sigandset (sigset_t *__set, const sigset_t *__left,
  171. const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
  172. /* Build new signal set by combining the two inputs set using logical OR. */
  173. extern int sigorset (sigset_t *__set, const sigset_t *__left,
  174. const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
  175. # endif /* GNU */
  176. /* Get the system-specific definitions of `struct sigaction'
  177. and the `SA_*' and `SIG_*'. constants. */
  178. # include <bits/sigaction.h>
  179. /* Get and/or change the set of blocked signals. */
  180. extern int sigprocmask (int __how, const sigset_t *__restrict __set,
  181. sigset_t *__restrict __oset) __THROW;
  182. /* Change the set of blocked signals to SET,
  183. wait until a signal arrives, and restore the set of blocked signals.
  184. This function is a cancellation point and therefore not marked with
  185. __THROW. */
  186. extern int sigsuspend (const sigset_t *__set) __nonnull ((1));
  187. /* Get and/or set the action for signal SIG. */
  188. extern int sigaction (int __sig, const struct sigaction *__restrict __act,
  189. struct sigaction *__restrict __oact) __THROW;
  190. /* Put in SET all signals that are blocked and waiting to be delivered. */
  191. extern int sigpending (sigset_t *__set) __THROW __nonnull ((1));
  192. # ifdef __USE_POSIX199506
  193. /* Select any of pending signals from SET or wait for any to arrive.
  194. This function is a cancellation point and therefore not marked with
  195. __THROW. */
  196. extern int sigwait (const sigset_t *__restrict __set, int *__restrict __sig)
  197. __nonnull ((1, 2));
  198. # endif /* Use POSIX 1995. */
  199. # ifdef __USE_POSIX199309
  200. /* Select any of pending signals from SET and place information in INFO.
  201. This function is a cancellation point and therefore not marked with
  202. __THROW. */
  203. extern int sigwaitinfo (const sigset_t *__restrict __set,
  204. siginfo_t *__restrict __info) __nonnull ((1));
  205. /* Select any of pending signals from SET and place information in INFO.
  206. Wait the time specified by TIMEOUT if no signal is pending.
  207. This function is a cancellation point and therefore not marked with
  208. __THROW. */
  209. extern int sigtimedwait (const sigset_t *__restrict __set,
  210. siginfo_t *__restrict __info,
  211. const struct timespec *__restrict __timeout)
  212. __nonnull ((1));
  213. /* Send signal SIG to the process PID. Associate data in VAL with the
  214. signal. */
  215. extern int sigqueue (__pid_t __pid, int __sig, const union sigval __val)
  216. __THROW;
  217. # endif /* Use POSIX 199306. */
  218. #endif /* Use POSIX. */
  219. #ifdef __USE_MISC
  220. /* Get machine-dependent `struct sigcontext' and signal subcodes. */
  221. # include <bits/sigcontext.h>
  222. /* Restore the state saved in SCP. */
  223. extern int sigreturn (struct sigcontext *__scp) __THROW;
  224. #endif /* Use misc. */
  225. #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
  226. # define __need_size_t
  227. # include <stddef.h>
  228. # include <bits/types/stack_t.h>
  229. # if defined __USE_XOPEN || defined __USE_XOPEN2K8
  230. /* This will define `ucontext_t' and `mcontext_t'. */
  231. # include <sys/ucontext.h>
  232. # endif
  233. #endif /* Use POSIX.1-2008 or X/Open Unix. */
  234. #if defined __USE_XOPEN_EXTENDED || defined __USE_MISC
  235. /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
  236. (causing them to fail with EINTR); if INTERRUPT is zero, make system
  237. calls be restarted after signal SIG. */
  238. extern int siginterrupt (int __sig, int __interrupt) __THROW
  239. __attribute_deprecated_msg__ ("Use sigaction with SA_RESTART instead");
  240. # include <bits/sigstack.h>
  241. # include <bits/ss_flags.h>
  242. /* Alternate signal handler stack interface.
  243. This interface should always be preferred over `sigstack'. */
  244. extern int sigaltstack (const stack_t *__restrict __ss,
  245. stack_t *__restrict __oss) __THROW;
  246. #endif /* __USE_XOPEN_EXTENDED || __USE_MISC */
  247. #if ((defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) \
  248. || defined __USE_MISC)
  249. # include <bits/types/struct_sigstack.h>
  250. #endif
  251. #if ((defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \
  252. || defined __USE_MISC)
  253. /* Run signals handlers on the stack specified by SS (if not NULL).
  254. If OSS is not NULL, it is filled in with the old signal stack status.
  255. This interface is obsolete and on many platform not implemented. */
  256. extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
  257. __THROW __attribute_deprecated__;
  258. #endif
  259. #ifdef __USE_XOPEN_EXTENDED
  260. /* Simplified interface for signal management. */
  261. /* Add SIG to the calling process' signal mask. */
  262. extern int sighold (int __sig) __THROW
  263. __attribute_deprecated_msg__ ("Use the sigprocmask function instead");
  264. /* Remove SIG from the calling process' signal mask. */
  265. extern int sigrelse (int __sig) __THROW
  266. __attribute_deprecated_msg__ ("Use the sigprocmask function instead");
  267. /* Set the disposition of SIG to SIG_IGN. */
  268. extern int sigignore (int __sig) __THROW
  269. __attribute_deprecated_msg__ ("Use the signal function instead");
  270. /* Set the disposition of SIG. */
  271. extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW
  272. __attribute_deprecated_msg__
  273. ("Use the signal and sigprocmask functions instead");
  274. #endif
  275. #if defined __USE_POSIX199506 || defined __USE_UNIX98
  276. /* Some of the functions for handling signals in threaded programs must
  277. be defined here. */
  278. # include <bits/pthreadtypes.h>
  279. # include <bits/sigthread.h>
  280. #endif /* use Unix98 */
  281. /* The following functions are used internally in the C library and in
  282. other code which need deep insights. */
  283. /* Return number of available real-time signal with highest priority. */
  284. extern int __libc_current_sigrtmin (void) __THROW;
  285. /* Return number of available real-time signal with lowest priority. */
  286. extern int __libc_current_sigrtmax (void) __THROW;
  287. #define SIGRTMIN (__libc_current_sigrtmin ())
  288. #define SIGRTMAX (__libc_current_sigrtmax ())
  289. /* System-specific extensions. */
  290. #include <bits/signal_ext.h>
  291. __END_DECLS
  292. #endif /* not signal.h */