signal.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. /* Copyright (C) 1991-2003, 2004, 2007, 2009 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. #endif
  75. #ifdef __USE_XOPEN
  76. # ifndef __uid_t_defined
  77. typedef __uid_t uid_t;
  78. # define __uid_t_defined
  79. # endif
  80. #endif /* Unix98 */
  81. #if defined __USE_POSIX199309 && defined __UCLIBC_HAS_REALTIME__
  82. /* We need `struct timespec' later on. */
  83. # define __need_timespec
  84. # include <time.h>
  85. /* Get the `siginfo_t' type plus the needed symbols. */
  86. # include <bits/siginfo.h>
  87. #endif
  88. /* Type of a signal handler. */
  89. typedef void (*__sighandler_t) (int);
  90. #if defined __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__
  91. /* The X/Open definition of `signal' specifies the SVID semantic. Use
  92. the additional function `sysv_signal' when X/Open compatibility is
  93. requested. */
  94. extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
  95. __THROW;
  96. # ifdef __USE_GNU
  97. extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
  98. __THROW;
  99. # endif
  100. #endif /* __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__ */
  101. /* Set the handler for the signal SIG to HANDLER, returning the old
  102. handler, or SIG_ERR on error.
  103. By default `signal' has the BSD semantic. */
  104. __BEGIN_NAMESPACE_STD
  105. #if defined __USE_BSD || !defined __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__
  106. extern __sighandler_t signal (int __sig, __sighandler_t __handler)
  107. __THROW;
  108. libc_hidden_proto(signal)
  109. #else
  110. /* Make sure the used `signal' implementation is the SVID version. */
  111. # ifdef __REDIRECT_NTH
  112. extern __sighandler_t __REDIRECT_NTH (signal,
  113. (int __sig, __sighandler_t __handler),
  114. __sysv_signal);
  115. # else
  116. # define signal __sysv_signal
  117. # endif
  118. #endif
  119. __END_NAMESPACE_STD
  120. #if defined __USE_XOPEN && defined __UCLIBC_SUSV3_LEGACY__
  121. /* The X/Open definition of `signal' conflicts with the BSD version.
  122. So they defined another function `bsd_signal'. */
  123. extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler)
  124. __THROW;
  125. #endif
  126. /* Send signal SIG to process number PID. If PID is zero,
  127. send SIG to all processes in the current process's process group.
  128. If PID is < -1, send SIG to all processes in process group - PID. */
  129. #ifdef __USE_POSIX
  130. extern int kill (__pid_t __pid, int __sig) __THROW;
  131. libc_hidden_proto(kill)
  132. #endif
  133. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  134. /* Send SIG to all processes in process group PGRP.
  135. If PGRP is zero, send SIG to all processes in
  136. the current process's process group. */
  137. extern int killpg (__pid_t __pgrp, int __sig) __THROW;
  138. #endif
  139. __BEGIN_NAMESPACE_STD
  140. /* Raise signal SIG, i.e., send SIG to yourself. */
  141. extern int raise (int __sig) __THROW;
  142. libc_hidden_proto(raise)
  143. __END_NAMESPACE_STD
  144. #if 0 /*def __USE_SVID*/
  145. /* SVID names for the same things. */
  146. extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
  147. __THROW;
  148. extern int gsignal (int __sig) __THROW;
  149. #endif /* Use SVID. */
  150. /* glibc guards the next two wrong with __USE_XOPEN2K */
  151. #if defined __USE_MISC || defined __USE_XOPEN2K8
  152. /* Print a message describing the meaning of the given signal number. */
  153. extern void psignal (int __sig, __const char *__s);
  154. #endif /* Use misc or POSIX 2008. */
  155. #if 0 /*def __USE_XOPEN2K8*/
  156. /* Print a message describing the meaning of the given signal information. */
  157. extern void psiginfo (__const siginfo_t *__pinfo, __const char *__s);
  158. #endif /* POSIX 2008. */
  159. #ifdef __UCLIBC_SUSV4_LEGACY__
  160. /* The `sigpause' function has two different interfaces. The original
  161. BSD definition defines the argument as a mask of the signal, while
  162. the more modern interface in X/Open defines it as the signal
  163. number. We go with the BSD version unless the user explicitly
  164. selects the X/Open version.
  165. This function is a cancellation point and therefore not marked with
  166. __THROW. */
  167. extern int __sigpause (int __sig_or_mask, int __is_sig);
  168. libc_hidden_proto(__sigpause)
  169. #ifdef __FAVOR_BSD
  170. /* Set the mask of blocked signals to MASK,
  171. wait for a signal to arrive, and then restore the mask. */
  172. extern int sigpause (int __mask) __THROW __attribute_deprecated__;
  173. # define sigpause(mask) __sigpause ((mask), 0)
  174. #else
  175. # ifdef __USE_XOPEN
  176. /* Remove a signal from the signal mask and suspend the process. */
  177. # define sigpause(sig) __sigpause ((sig), 1)
  178. # endif
  179. #endif
  180. #endif /* __UCLIBC_SUSV4_LEGACY__ */
  181. #ifdef __USE_BSD
  182. /* None of the following functions should be used anymore. They are here
  183. only for compatibility. A single word (`int') is not guaranteed to be
  184. enough to hold a complete signal mask and therefore these functions
  185. simply do not work in many situations. Use `sigprocmask' instead. */
  186. /* Compute mask for signal SIG. */
  187. # define sigmask(sig) __sigmask(sig)
  188. /* Block signals in MASK, returning the old mask. */
  189. # ifdef _LIBC
  190. extern int sigblock (int __mask) __THROW;
  191. /* collides with libc_hidden_proto: __attribute_deprecated__; */
  192. libc_hidden_proto(sigblock)
  193. # else
  194. extern int sigblock (int __mask) __THROW __attribute_deprecated__;
  195. # endif
  196. /* Set the mask of blocked signals to MASK, returning the old mask. */
  197. # ifdef _LIBC
  198. extern int sigsetmask (int __mask) __THROW;
  199. /* collides with libc_hidden_proto: __attribute_deprecated__; */
  200. libc_hidden_proto(sigsetmask)
  201. # else
  202. extern int sigsetmask (int __mask) __THROW __attribute_deprecated__;
  203. # endif
  204. /* Return currently selected signal mask. */
  205. extern int siggetmask (void) __THROW __attribute_deprecated__;
  206. #endif /* Use BSD. */
  207. #ifdef __USE_GNU
  208. typedef __sighandler_t sighandler_t;
  209. #endif
  210. /* 4.4 BSD uses the name `sig_t' for this. */
  211. #ifdef __USE_BSD
  212. typedef __sighandler_t sig_t;
  213. #endif
  214. #ifdef __USE_POSIX
  215. /* Clear all signals from SET. */
  216. extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1));
  217. libc_hidden_proto(sigemptyset)
  218. /* Set all signals in SET. */
  219. extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1));
  220. libc_hidden_proto(sigfillset)
  221. /* Add SIGNO to SET. */
  222. extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
  223. libc_hidden_proto(sigaddset)
  224. /* Remove SIGNO from SET. */
  225. extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
  226. libc_hidden_proto(sigdelset)
  227. /* Return 1 if SIGNO is in SET, 0 if not. */
  228. extern int sigismember (__const sigset_t *__set, int __signo)
  229. __THROW __nonnull ((1));
  230. # ifdef __USE_GNU
  231. /* Return non-empty value is SET is not empty. */
  232. extern int sigisemptyset (__const sigset_t *__set) __THROW __nonnull ((1));
  233. /* Build new signal set by combining the two inputs set using logical AND. */
  234. extern int sigandset (sigset_t *__set, __const sigset_t *__left,
  235. __const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
  236. /* Build new signal set by combining the two inputs set using logical OR. */
  237. extern int sigorset (sigset_t *__set, __const sigset_t *__left,
  238. __const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
  239. # endif /* GNU */
  240. /* Get the system-specific definitions of `struct sigaction'
  241. and the `SA_*' and `SIG_*'. constants. */
  242. # include <bits/sigaction.h>
  243. /* Get and/or change the set of blocked signals. */
  244. extern int sigprocmask (int __how, __const sigset_t *__restrict __set,
  245. sigset_t *__restrict __oset) __THROW;
  246. libc_hidden_proto(sigprocmask)
  247. /* Change the set of blocked signals to SET,
  248. wait until a signal arrives, and restore the set of blocked signals.
  249. This function is a cancellation point and therefore not marked with
  250. __THROW. */
  251. extern int sigsuspend (__const sigset_t *__set) __nonnull ((1));
  252. libc_hidden_proto(sigsuspend)
  253. /* Get and/or set the action for signal SIG. */
  254. extern int sigaction (int __sig, __const struct sigaction *__restrict __act,
  255. struct sigaction *__restrict __oact) __THROW;
  256. #ifdef _LIBC
  257. # if 0 /* this is in headers */
  258. /* In uclibc, userspace struct sigaction is identical to
  259. * "new" struct kernel_sigaction (one from the Linux 2.1.68 kernel).
  260. * See sigaction.h
  261. */
  262. struct old_kernel_sigaction;
  263. extern int __syscall_sigaction(int, __const struct old_kernel_sigaction *,
  264. struct old_kernel_sigaction *) attribute_hidden;
  265. # else /* this is how the function is built */
  266. extern __typeof(sigaction) __syscall_sigaction attribute_hidden;
  267. # endif
  268. /* candidate for attribute_hidden, if NPTL would behave */
  269. extern int __syscall_rt_sigaction(int, __const struct sigaction *,
  270. struct sigaction *, size_t)
  271. # ifndef __UCLIBC_HAS_THREADS_NATIVE__
  272. attribute_hidden
  273. # endif
  274. ;
  275. extern __typeof(sigaction) __libc_sigaction;
  276. libc_hidden_proto(sigaction)
  277. #endif
  278. /* Put in SET all signals that are blocked and waiting to be delivered. */
  279. extern int sigpending (sigset_t *__set) __THROW __nonnull ((1));
  280. /* Select any of pending signals from SET or wait for any to arrive.
  281. This function is a cancellation point and therefore not marked with
  282. __THROW. */
  283. extern int sigwait (__const sigset_t *__restrict __set, int *__restrict __sig)
  284. __nonnull ((1, 2));
  285. # if defined __USE_POSIX199309 && defined __UCLIBC_HAS_REALTIME__
  286. /* Select any of pending signals from SET and place information in INFO.
  287. This function is a cancellation point and therefore not marked with
  288. __THROW. */
  289. extern int sigwaitinfo (__const sigset_t *__restrict __set,
  290. siginfo_t *__restrict __info) __nonnull ((1));
  291. #ifdef _LIBC
  292. extern __typeof(sigwaitinfo) __sigwaitinfo attribute_hidden;
  293. #endif
  294. /* Select any of pending signals from SET and place information in INFO.
  295. Wait the time specified by TIMEOUT if no signal is pending.
  296. This function is a cancellation point and therefore not marked with
  297. __THROW. */
  298. extern int sigtimedwait (__const sigset_t *__restrict __set,
  299. siginfo_t *__restrict __info,
  300. __const struct timespec *__restrict __timeout)
  301. __nonnull ((1));
  302. #ifdef _LIBC
  303. extern __typeof(sigtimedwait) __sigtimedwait attribute_hidden;
  304. #endif
  305. /* Send signal SIG to the process PID. Associate data in VAL with the
  306. signal. */
  307. extern int sigqueue (__pid_t __pid, int __sig, __const union sigval __val)
  308. __THROW;
  309. # endif /* Use POSIX 199306. */
  310. #endif /* Use POSIX. */
  311. #ifdef __USE_BSD
  312. # ifdef __UCLIBC_HAS_SYS_SIGLIST__
  313. /* Names of the signals. This variable exists only for compatibility.
  314. Use `strsignal' instead (see <string.h>). */
  315. # define _sys_siglist sys_siglist
  316. extern __const char *__const sys_siglist[_NSIG];
  317. # endif
  318. #ifndef __UCLIBC_STRICT_HEADERS__
  319. /* Structure passed to `sigvec'. */
  320. struct sigvec
  321. {
  322. __sighandler_t sv_handler; /* Signal handler. */
  323. int sv_mask; /* Mask of signals to be blocked. */
  324. int sv_flags; /* Flags (see below). */
  325. # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
  326. };
  327. /* Bits in `sv_flags'. */
  328. # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
  329. # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
  330. # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
  331. #endif
  332. #if 0
  333. /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
  334. of VEC. The signals in `sv_mask' will be blocked while the handler runs.
  335. If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
  336. reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
  337. it is filled in with the old information for SIG. */
  338. extern int sigvec (int __sig, __const struct sigvec *__vec,
  339. struct sigvec *__ovec) __THROW;
  340. #endif
  341. /* Get machine-dependent `struct sigcontext' and signal subcodes. */
  342. # include <bits/sigcontext.h>
  343. #if 0
  344. /* Restore the state saved in SCP. */
  345. extern int sigreturn (struct sigcontext *__scp) __THROW;
  346. #endif
  347. #endif /* use BSD. */
  348. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  349. # ifdef __UCLIBC_SUSV4_LEGACY__
  350. /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
  351. (causing them to fail with EINTR); if INTERRUPT is zero, make system
  352. calls be restarted after signal SIG. */
  353. extern int siginterrupt (int __sig, int __interrupt) __THROW;
  354. # endif
  355. # include <bits/sigstack.h>
  356. # ifdef __USE_XOPEN
  357. /* This will define `ucontext_t' and `mcontext_t'. */
  358. /* SuSv4 obsoleted include/ucontext.h */
  359. # include <sys/ucontext.h>
  360. # endif
  361. # if 0
  362. /* Run signals handlers on the stack specified by SS (if not NULL).
  363. If OSS is not NULL, it is filled in with the old signal stack status.
  364. This interface is obsolete and on many platform not implemented. */
  365. extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
  366. __THROW __attribute_deprecated__;
  367. # endif
  368. /* Alternate signal handler stack interface.
  369. This interface should always be preferred over `sigstack'. */
  370. extern int sigaltstack (__const struct sigaltstack *__restrict __ss,
  371. struct sigaltstack *__restrict __oss) __THROW;
  372. #endif /* use BSD or X/Open Unix. */
  373. #if defined __USE_XOPEN_EXTENDED && defined __UCLIBC_HAS_OBSOLETE_BSD_SIGNAL__
  374. /* Simplified interface for signal management. */
  375. /* Add SIG to the calling process' signal mask. */
  376. extern int sighold (int __sig) __THROW;
  377. /* Remove SIG from the calling process' signal mask. */
  378. extern int sigrelse (int __sig) __THROW;
  379. /* Set the disposition of SIG to SIG_IGN. */
  380. extern int sigignore (int __sig) __THROW;
  381. /* Set the disposition of SIG. */
  382. extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
  383. #endif
  384. #if defined __UCLIBC_HAS_THREADS__ && (defined __USE_POSIX199506 || defined __USE_UNIX98)
  385. /* Some of the functions for handling signals in threaded programs must
  386. be defined here. */
  387. # include <bits/pthreadtypes.h>
  388. # include <bits/sigthread.h>
  389. #endif
  390. /* The following functions are used internally in the C library and in
  391. other code which need deep insights. */
  392. /* Return number of available real-time signal with highest priority. */
  393. extern int __libc_current_sigrtmin (void) __THROW;
  394. /* Return number of available real-time signal with lowest priority. */
  395. extern int __libc_current_sigrtmax (void) __THROW;
  396. #endif /* signal.h */
  397. __END_DECLS
  398. #endif /* not signal.h */