signal.h 12 KB

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