signal.h 12 KB

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