signal.h 12 KB

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