signal.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /* Copyright (C) 1991-1999, 2000, 2001 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. typedef __sig_atomic_t sig_atomic_t;
  31. # endif
  32. # undef __need_sig_atomic_t
  33. #endif
  34. #if defined __need_sigset_t || (defined _SIGNAL_H && defined __USE_POSIX)
  35. # ifndef __sigset_t_defined
  36. # define __sigset_t_defined
  37. typedef __sigset_t sigset_t;
  38. # endif
  39. # undef __need_sigset_t
  40. #endif
  41. #ifdef _SIGNAL_H
  42. #include <bits/types.h>
  43. #include <bits/signum.h>
  44. #ifdef __USE_XOPEN
  45. # ifndef __pid_t_defined
  46. typedef __pid_t pid_t;
  47. # define __pid_t_defined
  48. # endif
  49. # ifndef __uid_t_defined
  50. typedef __uid_t uid_t;
  51. # define __uid_t_defined
  52. # endif
  53. #endif /* Unix98 */
  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_BSD
  69. extern __sighandler_t signal (int __sig, __sighandler_t __handler) __THROW;
  70. #else
  71. /* Make sure the used `signal' implementation is the SVID version. */
  72. # ifdef __REDIRECT
  73. extern __sighandler_t __REDIRECT (signal,
  74. (int __sig,
  75. __sighandler_t __handler) __THROW,
  76. __sysv_signal);
  77. # else
  78. # define signal __sysv_signal
  79. # endif
  80. #endif
  81. #ifdef __USE_XOPEN
  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) __THROW;
  85. #endif
  86. /* Send signal SIG to process number PID. If PID is zero,
  87. send SIG to all processes in the current process's process group.
  88. If PID is < -1, send SIG to all processes in process group - PID. */
  89. #ifdef __USE_POSIX
  90. extern int kill (__pid_t __pid, int __sig) __THROW;
  91. #endif /* Use POSIX. */
  92. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  93. /* Send SIG to all processes in process group PGRP.
  94. If PGRP is zero, send SIG to all processes in
  95. the current process's process group. */
  96. extern int killpg (__pid_t __pgrp, int __sig) __THROW;
  97. #endif /* Use BSD || X/Open Unix. */
  98. /* Raise signal SIG, i.e., send SIG to yourself. */
  99. extern int raise (int __sig) __THROW;
  100. #ifdef __USE_SVID
  101. /* SVID names for the same things. */
  102. extern __sighandler_t ssignal (int __sig, __sighandler_t __handler) __THROW;
  103. extern int gsignal (int __sig) __THROW;
  104. #endif /* Use SVID. */
  105. #ifdef __USE_MISC
  106. /* Print a message describing the meaning of the given signal number. */
  107. extern void psignal (int __sig, __const char *__s) __THROW;
  108. #endif /* Use misc. */
  109. /* The `sigpause' function has two different interfaces. The original
  110. BSD definition defines the argument as a mask of the signal, while
  111. the more modern interface in X/Open defines it as the signal
  112. number. We go with the BSD version unless the user explicitly
  113. selects the X/Open version. */
  114. extern int __sigpause (int __sig_or_mask, int __is_sig) __THROW;
  115. #ifdef __USE_BSD
  116. /* Set the mask of blocked signals to MASK,
  117. wait for a signal to arrive, and then restore the mask. */
  118. extern int sigpause (int __mask) __THROW;
  119. # define sigpause(mask) __sigpause ((mask), 0)
  120. #else
  121. # ifdef __USE_XOPEN
  122. # ifdef __GNUC__
  123. extern int sigpause (int __sig) __THROW __asm__ ("__xpg_sigpause");
  124. # endif
  125. /* Remove a signal from the signal mask and suspend the process. */
  126. # define sigpause(sig) __sigpause ((sig), 1)
  127. # endif
  128. #endif
  129. #ifdef __USE_BSD
  130. /* None of the following functions should be used anymore. They are here
  131. only for compatibility. A single word (`int') is not guaranteed to be
  132. enough to hold a complete signal mask and therefore these functions
  133. simply do not work in many situations. Use `sigprocmask' instead. */
  134. /* Compute mask for signal SIG. */
  135. # define sigmask(sig) __sigmask(sig)
  136. /* Block signals in MASK, returning the old mask. */
  137. extern int sigblock (int __mask) __THROW;
  138. /* Set the mask of blocked signals to MASK, returning the old mask. */
  139. extern int sigsetmask (int __mask) __THROW;
  140. /* Return currently selected signal mask. */
  141. extern int siggetmask (void) __THROW;
  142. #endif /* Use BSD. */
  143. #ifdef __USE_MISC
  144. # define NSIG _NSIG
  145. #endif
  146. #ifdef __USE_GNU
  147. typedef __sighandler_t sighandler_t;
  148. #endif
  149. /* 4.4 BSD uses the name `sig_t' for this. */
  150. #ifdef __USE_BSD
  151. typedef __sighandler_t sig_t;
  152. #endif
  153. #ifdef __USE_POSIX
  154. # ifdef __USE_POSIX199309
  155. /* We need `struct timespec' later on. */
  156. # define __need_timespec
  157. # include <time.h>
  158. /* Get the `siginfo_t' type plus the needed symbols. */
  159. # include <bits/siginfo.h>
  160. # endif
  161. /* Clear all signals from SET. */
  162. extern int sigemptyset (sigset_t *__set) __THROW;
  163. /* Set all signals in SET. */
  164. extern int sigfillset (sigset_t *__set) __THROW;
  165. /* Add SIGNO to SET. */
  166. extern int sigaddset (sigset_t *__set, int __signo) __THROW;
  167. /* Remove SIGNO from SET. */
  168. extern int sigdelset (sigset_t *__set, int __signo) __THROW;
  169. /* Return 1 if SIGNO is in SET, 0 if not. */
  170. extern int sigismember (__const sigset_t *__set, int __signo) __THROW;
  171. # ifdef __USE_GNU
  172. /* Return non-empty value is SET is not empty. */
  173. extern int sigisemptyset (__const sigset_t *__set) __THROW;
  174. /* Build new signal set by combining the two inputs set using logical AND. */
  175. extern int sigandset (sigset_t *__set, __const sigset_t *__left,
  176. __const sigset_t *__right) __THROW;
  177. /* Build new signal set by combining the two inputs set using logical OR. */
  178. extern int sigorset (sigset_t *__set, __const sigset_t *__left,
  179. __const sigset_t *__right) __THROW;
  180. # endif /* GNU */
  181. /* Get the system-specific definitions of `struct sigaction'
  182. and the `SA_*' and `SIG_*'. constants. */
  183. # include <bits/sigaction.h>
  184. /* Get and/or change the set of blocked signals. */
  185. extern int sigprocmask (int __how, __const sigset_t *__restrict __set,
  186. sigset_t *__restrict __oset) __THROW;
  187. /* Change the set of blocked signals to SET,
  188. wait until a signal arrives, and restore the set of blocked signals. */
  189. extern int sigsuspend (__const sigset_t *__set) __THROW;
  190. /* Get and/or set the action for signal SIG. */
  191. extern int sigaction (int __sig, __const struct sigaction *__restrict __act,
  192. struct sigaction *__restrict __oact) __THROW;
  193. /* Put in SET all signals that are blocked and waiting to be delivered. */
  194. extern int sigpending (sigset_t *__set) __THROW;
  195. /* Select any of pending signals from SET or wait for any to arrive. */
  196. extern int sigwait (__const sigset_t *__restrict __set, int *__restrict __sig)
  197. __THROW;
  198. # ifdef __USE_POSIX199309
  199. /* Select any of pending signals from SET and place information in INFO. */
  200. extern int sigwaitinfo (__const sigset_t *__restrict __set,
  201. siginfo_t *__restrict __info) __THROW;
  202. /* Select any of pending signals from SET and place information in INFO.
  203. Wait the imte specified by TIMEOUT if no signal is pending. */
  204. extern int sigtimedwait (__const sigset_t *__restrict __set,
  205. siginfo_t *__restrict __info,
  206. __const struct timespec *__restrict __timeout)
  207. __THROW;
  208. /* Send signal SIG to the process PID. Associate data in VAL with the
  209. signal. */
  210. extern int sigqueue (__pid_t __pid, int __sig, __const union sigval __val)
  211. __THROW;
  212. # endif /* Use POSIX 199306. */
  213. #endif /* Use POSIX. */
  214. #ifdef __USE_BSD
  215. /* Names of the signals. This variable exists only for compatibility.
  216. Use `strsignal' instead (see <string.h>). */
  217. extern __const char *__const _sys_siglist[_NSIG];
  218. extern __const char *__const sys_siglist[_NSIG];
  219. /* Structure passed to `sigvec'. */
  220. struct sigvec
  221. {
  222. __sighandler_t sv_handler; /* Signal handler. */
  223. int sv_mask; /* Mask of signals to be blocked. */
  224. int sv_flags; /* Flags (see below). */
  225. # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
  226. };
  227. /* Bits in `sv_flags'. */
  228. # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
  229. # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
  230. # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
  231. /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
  232. of VEC. The signals in `sv_mask' will be blocked while the handler runs.
  233. If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
  234. reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
  235. it is filled in with the old information for SIG. */
  236. extern int sigvec (int __sig, __const struct sigvec *__vec,
  237. struct sigvec *__ovec) __THROW;
  238. /* Get machine-dependent `struct sigcontext' and signal subcodes. */
  239. # include <bits/sigcontext.h>
  240. /* Restore the state saved in SCP. */
  241. extern int sigreturn (struct sigcontext *__scp) __THROW;
  242. #endif /* use BSD. */
  243. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  244. /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
  245. (causing them to fail with EINTR); if INTERRUPT is zero, make system
  246. calls be restarted after signal SIG. */
  247. extern int siginterrupt (int __sig, int __interrupt) __THROW;
  248. # include <bits/sigstack.h>
  249. # ifdef __USE_XOPEN
  250. # include <ucontext.h>
  251. # endif
  252. /* Run signals handlers on the stack specified by SS (if not NULL).
  253. If OSS is not NULL, it is filled in with the old signal stack status.
  254. This interface is obsolete and on many platform not implemented. */
  255. extern int sigstack (struct sigstack *__ss, struct sigstack *__oss) __THROW;
  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 BSD or X/Open Unix. */
  261. #ifdef __USE_UNIX98
  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 __UCLIBC_HAS_THREADS__ && (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/sigthread.h>
  276. #endif /* use Unix98 */
  277. /* The following functions are used internally in the C library and in
  278. other code which need deep insights. */
  279. /* Return number of available real-time signal with highest priority. */
  280. extern int __libc_current_sigrtmin (void) __THROW;
  281. /* Return number of available real-time signal with lowest priority. */
  282. extern int __libc_current_sigrtmax (void) __THROW;
  283. #endif /* signal.h */
  284. __END_DECLS
  285. #endif /* not signal.h */