signal.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /* Copyright (C) 1991-2003, 2004 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, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. /*
  16. * ISO C99 Standard: 7.14 Signal handling <signal.h>
  17. */
  18. #ifndef _SIGNAL_H
  19. #if !defined __need_sig_atomic_t && !defined __need_sigset_t
  20. # define _SIGNAL_H
  21. #endif
  22. #include <features.h>
  23. __BEGIN_DECLS
  24. #include <bits/sigset.h> /* __sigset_t, __sig_atomic_t. */
  25. /* An integral type that can be modified atomically, without the
  26. possibility of a signal arriving in the middle of the operation. */
  27. #if defined __need_sig_atomic_t || defined _SIGNAL_H
  28. # ifndef __sig_atomic_t_defined
  29. # define __sig_atomic_t_defined
  30. __BEGIN_NAMESPACE_STD
  31. typedef __sig_atomic_t sig_atomic_t;
  32. __END_NAMESPACE_STD
  33. # endif
  34. # undef __need_sig_atomic_t
  35. #endif
  36. #if defined __need_sigset_t || (defined _SIGNAL_H && defined __USE_POSIX)
  37. # ifndef __sigset_t_defined
  38. # define __sigset_t_defined
  39. typedef __sigset_t sigset_t;
  40. # endif
  41. # undef __need_sigset_t
  42. #endif
  43. #ifdef _SIGNAL_H
  44. #include <bits/types.h>
  45. #include <bits/signum.h>
  46. /* Fake signal functions. */
  47. #define SIG_ERR ((__sighandler_t) -1) /* Error return. */
  48. #define SIG_DFL ((__sighandler_t) 0) /* Default action. */
  49. #define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */
  50. #ifdef __USE_UNIX98
  51. # define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */
  52. #endif
  53. /* Biggest signal number + 1 (including real-time signals). */
  54. #ifndef _NSIG /* if arch has not defined it in bits/signum.h... */
  55. # define _NSIG 65
  56. #endif
  57. #ifdef __USE_MISC
  58. # define NSIG _NSIG
  59. #endif
  60. /* Real-time signal range */
  61. #define SIGRTMIN (__libc_current_sigrtmin())
  62. #define SIGRTMAX (__libc_current_sigrtmax())
  63. /* These are the hard limits of the kernel. These values should not be
  64. used directly at user level. */
  65. #ifndef __SIGRTMIN /* if arch has not defined it in bits/signum.h... */
  66. # define __SIGRTMIN 32
  67. #endif
  68. #define __SIGRTMAX (_NSIG - 1)
  69. #if defined __USE_XOPEN || defined __USE_XOPEN2K
  70. # ifndef __pid_t_defined
  71. typedef __pid_t pid_t;
  72. # define __pid_t_defined
  73. # endif
  74. # ifndef __uid_t_defined
  75. typedef __uid_t uid_t;
  76. # define __uid_t_defined
  77. # endif
  78. #endif /* Unix98 */
  79. /* Type of a signal handler. */
  80. typedef void (*__sighandler_t) (int);
  81. #if defined __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__
  82. /* The X/Open definition of `signal' specifies the SVID semantic. Use
  83. the additional function `sysv_signal' when X/Open compatibility is
  84. requested. */
  85. extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
  86. __THROW;
  87. # ifdef __USE_GNU
  88. extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
  89. __THROW;
  90. # endif
  91. #endif /* __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__ */
  92. /* Set the handler for the signal SIG to HANDLER, returning the old
  93. handler, or SIG_ERR on error.
  94. By default `signal' has the BSD semantic. */
  95. __BEGIN_NAMESPACE_STD
  96. #if defined __USE_BSD || !defined __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__
  97. extern __sighandler_t signal (int __sig, __sighandler_t __handler)
  98. __THROW;
  99. libc_hidden_proto(signal)
  100. #else
  101. /* Make sure the used `signal' implementation is the SVID version. */
  102. # ifdef __REDIRECT_NTH
  103. extern __sighandler_t __REDIRECT_NTH (signal,
  104. (int __sig, __sighandler_t __handler),
  105. __sysv_signal);
  106. # else
  107. # define signal __sysv_signal
  108. # endif
  109. #endif
  110. __END_NAMESPACE_STD
  111. #if defined __USE_XOPEN && defined __UCLIBC_SUSV3_LEGACY__
  112. /* The X/Open definition of `signal' conflicts with the BSD version.
  113. So they defined another function `bsd_signal'. */
  114. extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler)
  115. __THROW;
  116. #endif
  117. /* Send signal SIG to process number PID. If PID is zero,
  118. send SIG to all processes in the current process's process group.
  119. If PID is < -1, send SIG to all processes in process group - PID. */
  120. #ifdef __USE_POSIX
  121. extern int kill (__pid_t __pid, int __sig) __THROW;
  122. libc_hidden_proto(kill)
  123. #endif
  124. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  125. /* Send SIG to all processes in process group PGRP.
  126. If PGRP is zero, send SIG to all processes in
  127. the current process's process group. */
  128. extern int killpg (__pid_t __pgrp, int __sig) __THROW;
  129. #endif
  130. __BEGIN_NAMESPACE_STD
  131. /* Raise signal SIG, i.e., send SIG to yourself. */
  132. extern int raise (int __sig) __THROW;
  133. libc_hidden_proto(raise)
  134. __END_NAMESPACE_STD
  135. #ifdef __USE_SVID
  136. /* SVID names for the same things. */
  137. extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
  138. __THROW;
  139. extern int gsignal (int __sig) __THROW;
  140. #endif /* Use SVID. */
  141. #ifdef __USE_MISC
  142. /* Print a message describing the meaning of the given signal number. */
  143. extern void psignal (int __sig, __const char *__s);
  144. #endif /* Use misc. */
  145. /* The `sigpause' function has two different interfaces. The original
  146. BSD definition defines the argument as a mask of the signal, while
  147. the more modern interface in X/Open defines it as the signal
  148. number. We go with the BSD version unless the user explicitly
  149. selects the X/Open version.
  150. This function is a cancellation point and therefore not marked with
  151. __THROW. */
  152. extern int __sigpause (int __sig_or_mask, int __is_sig);
  153. libc_hidden_proto(__sigpause)
  154. #ifdef __FAVOR_BSD
  155. /* Set the mask of blocked signals to MASK,
  156. wait for a signal to arrive, and then restore the mask. */
  157. extern int sigpause (int __mask) __THROW __attribute_deprecated__;
  158. libc_hidden_proto(sigpause)
  159. # define sigpause(mask) __sigpause ((mask), 0)
  160. #else
  161. # ifdef __USE_XOPEN
  162. /* Remove a signal from the signal mask and suspend the process. */
  163. # define sigpause(sig) __sigpause ((sig), 1)
  164. # endif
  165. #endif
  166. #ifdef __USE_BSD
  167. /* None of the following functions should be used anymore. They are here
  168. only for compatibility. A single word (`int') is not guaranteed to be
  169. enough to hold a complete signal mask and therefore these functions
  170. simply do not work in many situations. Use `sigprocmask' instead. */
  171. /* Compute mask for signal SIG. */
  172. # define sigmask(sig) __sigmask(sig)
  173. /* Block signals in MASK, returning the old mask. */
  174. extern int sigblock (int __mask) __THROW;
  175. /* collides with libc_hidden_proto: __attribute_deprecated__; */
  176. libc_hidden_proto(sigblock)
  177. /* Set the mask of blocked signals to MASK, returning the old mask. */
  178. extern int sigsetmask (int __mask) __THROW;
  179. /* collides with libc_hidden_proto: __attribute_deprecated__; */
  180. libc_hidden_proto(sigsetmask)
  181. /* Return currently selected signal mask. */
  182. extern int siggetmask (void) __THROW __attribute_deprecated__;
  183. #endif /* Use BSD. */
  184. #ifdef __USE_GNU
  185. typedef __sighandler_t sighandler_t;
  186. #endif
  187. /* 4.4 BSD uses the name `sig_t' for this. */
  188. #ifdef __USE_BSD
  189. typedef __sighandler_t sig_t;
  190. #endif
  191. #ifdef __USE_POSIX
  192. # ifdef __USE_POSIX199309
  193. /* We need `struct timespec' later on. */
  194. # define __need_timespec
  195. # include <time.h>
  196. /* Get the `siginfo_t' type plus the needed symbols. */
  197. # include <bits/siginfo.h>
  198. # endif
  199. /* Clear all signals from SET. */
  200. extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1));
  201. libc_hidden_proto(sigemptyset)
  202. /* Set all signals in SET. */
  203. extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1));
  204. libc_hidden_proto(sigfillset)
  205. /* Add SIGNO to SET. */
  206. extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
  207. libc_hidden_proto(sigaddset)
  208. /* Remove SIGNO from SET. */
  209. extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
  210. libc_hidden_proto(sigdelset)
  211. /* Return 1 if SIGNO is in SET, 0 if not. */
  212. extern int sigismember (__const sigset_t *__set, int __signo)
  213. __THROW __nonnull ((1));
  214. # ifdef __USE_GNU
  215. /* Return non-empty value is SET is not empty. */
  216. extern int sigisemptyset (__const sigset_t *__set) __THROW __nonnull ((1));
  217. /* Build new signal set by combining the two inputs set using logical AND. */
  218. extern int sigandset (sigset_t *__set, __const sigset_t *__left,
  219. __const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
  220. /* Build new signal set by combining the two inputs set using logical OR. */
  221. extern int sigorset (sigset_t *__set, __const sigset_t *__left,
  222. __const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
  223. # endif /* GNU */
  224. /* Get the system-specific definitions of `struct sigaction'
  225. and the `SA_*' and `SIG_*'. constants. */
  226. # include <bits/sigaction.h>
  227. /* Get and/or change the set of blocked signals. */
  228. extern int sigprocmask (int __how, __const sigset_t *__restrict __set,
  229. sigset_t *__restrict __oset) __THROW;
  230. libc_hidden_proto(sigprocmask)
  231. /* Change the set of blocked signals to SET,
  232. wait until a signal arrives, and restore the set of blocked signals.
  233. This function is a cancellation point and therefore not marked with
  234. __THROW. */
  235. extern int sigsuspend (__const sigset_t *__set) __nonnull ((1));
  236. libc_hidden_proto(sigsuspend)
  237. /* Get and/or set the action for signal SIG. */
  238. extern int sigaction (int __sig, __const struct sigaction *__restrict __act,
  239. struct sigaction *__restrict __oact) __THROW;
  240. libc_hidden_proto(sigaction)
  241. /* Put in SET all signals that are blocked and waiting to be delivered. */
  242. extern int sigpending (sigset_t *__set) __THROW __nonnull ((1));
  243. /* Select any of pending signals from SET or wait for any to arrive.
  244. This function is a cancellation point and therefore not marked with
  245. __THROW. */
  246. extern int sigwait (__const sigset_t *__restrict __set, int *__restrict __sig)
  247. __nonnull ((1, 2));
  248. libc_hidden_proto(sigwait)
  249. # if defined __USE_POSIX199309 && defined __UCLIBC_HAS_REALTIME__
  250. /* Select any of pending signals from SET and place information in INFO.
  251. This function is a cancellation point and therefore not marked with
  252. __THROW. */
  253. extern int sigwaitinfo (__const sigset_t *__restrict __set,
  254. siginfo_t *__restrict __info) __nonnull ((1));
  255. libc_hidden_proto(sigwaitinfo)
  256. /* Select any of pending signals from SET and place information in INFO.
  257. Wait the time specified by TIMEOUT if no signal is pending.
  258. This function is a cancellation point and therefore not marked with
  259. __THROW. */
  260. extern int sigtimedwait (__const sigset_t *__restrict __set,
  261. siginfo_t *__restrict __info,
  262. __const struct timespec *__restrict __timeout)
  263. __nonnull ((1));
  264. libc_hidden_proto(sigtimedwait)
  265. /* Send signal SIG to the process PID. Associate data in VAL with the
  266. signal. */
  267. extern int sigqueue (__pid_t __pid, int __sig, __const union sigval __val)
  268. __THROW;
  269. # endif /* Use POSIX 199306. */
  270. #endif /* Use POSIX. */
  271. #ifdef __USE_BSD
  272. # ifdef __UCLIBC_HAS_SYS_SIGLIST__
  273. /* Names of the signals. This variable exists only for compatibility.
  274. Use `strsignal' instead (see <string.h>). */
  275. # define _sys_siglist sys_siglist
  276. extern __const char *__const sys_siglist[_NSIG];
  277. # endif
  278. /* Structure passed to `sigvec'. */
  279. struct sigvec
  280. {
  281. __sighandler_t sv_handler; /* Signal handler. */
  282. int sv_mask; /* Mask of signals to be blocked. */
  283. int sv_flags; /* Flags (see below). */
  284. # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
  285. };
  286. /* Bits in `sv_flags'. */
  287. # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
  288. # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
  289. # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
  290. /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
  291. of VEC. The signals in `sv_mask' will be blocked while the handler runs.
  292. If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
  293. reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
  294. it is filled in with the old information for SIG. */
  295. extern int sigvec (int __sig, __const struct sigvec *__vec,
  296. struct sigvec *__ovec) __THROW;
  297. /* Get machine-dependent `struct sigcontext' and signal subcodes. */
  298. # include <bits/sigcontext.h>
  299. /* Restore the state saved in SCP. */
  300. extern int sigreturn (struct sigcontext *__scp) __THROW;
  301. #endif /* use BSD. */
  302. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  303. /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
  304. (causing them to fail with EINTR); if INTERRUPT is zero, make system
  305. calls be restarted after signal SIG. */
  306. extern int siginterrupt (int __sig, int __interrupt) __THROW;
  307. # include <bits/sigstack.h>
  308. # ifdef __USE_XOPEN
  309. /* This will define `ucontext_t' and `mcontext_t'. */
  310. # include <ucontext.h>
  311. # endif
  312. /* Run signals handlers on the stack specified by SS (if not NULL).
  313. If OSS is not NULL, it is filled in with the old signal stack status.
  314. This interface is obsolete and on many platform not implemented. */
  315. extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
  316. __THROW __attribute_deprecated__;
  317. /* Alternate signal handler stack interface.
  318. This interface should always be preferred over `sigstack'. */
  319. extern int sigaltstack (__const struct sigaltstack *__restrict __ss,
  320. struct sigaltstack *__restrict __oss) __THROW;
  321. #endif /* use BSD or X/Open Unix. */
  322. #if defined __USE_XOPEN_EXTENDED && defined __UCLIBC_HAS_OBSOLETE_BSD_SIGNAL__
  323. /* Simplified interface for signal management. */
  324. /* Add SIG to the calling process' signal mask. */
  325. extern int sighold (int __sig) __THROW;
  326. /* Remove SIG from the calling process' signal mask. */
  327. extern int sigrelse (int __sig) __THROW;
  328. /* Set the disposition of SIG to SIG_IGN. */
  329. extern int sigignore (int __sig) __THROW;
  330. /* Set the disposition of SIG. */
  331. extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
  332. #endif
  333. #if defined __UCLIBC_HAS_THREADS__ && (defined __USE_POSIX199506 || defined __USE_UNIX98)
  334. /* Some of the functions for handling signals in threaded programs must
  335. be defined here. */
  336. # include <bits/pthreadtypes.h>
  337. # include <bits/sigthread.h>
  338. #endif
  339. /* The following functions are used internally in the C library and in
  340. other code which need deep insights. */
  341. /* Return number of available real-time signal with highest priority. */
  342. extern int __libc_current_sigrtmin (void) __THROW;
  343. /* Return number of available real-time signal with lowest priority. */
  344. extern int __libc_current_sigrtmax (void) __THROW;
  345. #endif /* signal.h */
  346. __END_DECLS
  347. #endif /* not signal.h */