Back to index

glibc  2.9
signal.h
Go to the documentation of this file.
00001 /* Copyright (C) 1991-2003, 2004, 2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 /*
00020  *     ISO C99 Standard: 7.14 Signal handling <signal.h>
00021  */
00022 
00023 #ifndef       _SIGNAL_H
00024 
00025 #if !defined __need_sig_atomic_t && !defined __need_sigset_t
00026 # define _SIGNAL_H
00027 #endif
00028 
00029 #include <features.h>
00030 
00031 __BEGIN_DECLS
00032 
00033 #include <bits/sigset.h>           /* __sigset_t, __sig_atomic_t.  */
00034 
00035 /* An integral type that can be modified atomically, without the
00036    possibility of a signal arriving in the middle of the operation.  */
00037 #if defined __need_sig_atomic_t || defined _SIGNAL_H
00038 # ifndef __sig_atomic_t_defined
00039 #  define __sig_atomic_t_defined
00040 __BEGIN_NAMESPACE_STD
00041 typedef __sig_atomic_t sig_atomic_t;
00042 __END_NAMESPACE_STD
00043 # endif
00044 # undef __need_sig_atomic_t
00045 #endif
00046 
00047 #if defined __need_sigset_t || (defined _SIGNAL_H && defined __USE_POSIX)
00048 # ifndef __sigset_t_defined
00049 #  define __sigset_t_defined
00050 typedef __sigset_t sigset_t;
00051 # endif
00052 # undef __need_sigset_t
00053 #endif
00054 
00055 #ifdef _SIGNAL_H
00056 
00057 #include <bits/types.h>
00058 #include <bits/signum.h>
00059 
00060 #if defined __USE_XOPEN || defined __USE_XOPEN2K
00061 # ifndef __pid_t_defined
00062 typedef __pid_t pid_t;
00063 #  define __pid_t_defined
00064 #endif
00065 #ifdef __USE_XOPEN
00066 # endif
00067 # ifndef __uid_t_defined
00068 typedef __uid_t uid_t;
00069 #  define __uid_t_defined
00070 # endif
00071 #endif /* Unix98 */
00072 
00073 
00074 /* Type of a signal handler.  */
00075 typedef void (*__sighandler_t) (int);
00076 
00077 /* The X/Open definition of `signal' specifies the SVID semantic.  Use
00078    the additional function `sysv_signal' when X/Open compatibility is
00079    requested.  */
00080 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
00081      __THROW;
00082 #ifdef __USE_GNU
00083 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
00084      __THROW;
00085 #endif
00086 
00087 /* Set the handler for the signal SIG to HANDLER, returning the old
00088    handler, or SIG_ERR on error.
00089    By default `signal' has the BSD semantic.  */
00090 __BEGIN_NAMESPACE_STD
00091 #ifdef __USE_BSD
00092 extern __sighandler_t signal (int __sig, __sighandler_t __handler)
00093      __THROW;
00094 #else
00095 /* Make sure the used `signal' implementation is the SVID version. */
00096 # ifdef __REDIRECT_NTH
00097 extern __sighandler_t __REDIRECT_NTH (signal,
00098                                   (int __sig, __sighandler_t __handler),
00099                                   __sysv_signal);
00100 # else
00101 #  define signal __sysv_signal
00102 # endif
00103 #endif
00104 __END_NAMESPACE_STD
00105 
00106 #ifdef __USE_XOPEN
00107 /* The X/Open definition of `signal' conflicts with the BSD version.
00108    So they defined another function `bsd_signal'.  */
00109 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler)
00110      __THROW;
00111 #endif
00112 
00113 /* Send signal SIG to process number PID.  If PID is zero,
00114    send SIG to all processes in the current process's process group.
00115    If PID is < -1, send SIG to all processes in process group - PID.  */
00116 #ifdef __USE_POSIX
00117 extern int kill (__pid_t __pid, int __sig) __THROW;
00118 #endif /* Use POSIX.  */
00119 
00120 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
00121 /* Send SIG to all processes in process group PGRP.
00122    If PGRP is zero, send SIG to all processes in
00123    the current process's process group.  */
00124 extern int killpg (__pid_t __pgrp, int __sig) __THROW;
00125 #endif /* Use BSD || X/Open Unix.  */
00126 
00127 __BEGIN_NAMESPACE_STD
00128 /* Raise signal SIG, i.e., send SIG to yourself.  */
00129 extern int raise (int __sig) __THROW;
00130 __END_NAMESPACE_STD
00131 
00132 #ifdef __USE_SVID
00133 /* SVID names for the same things.  */
00134 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
00135      __THROW;
00136 extern int gsignal (int __sig) __THROW;
00137 #endif /* Use SVID.  */
00138 
00139 #ifdef __USE_MISC
00140 /* Print a message describing the meaning of the given signal number.  */
00141 extern void psignal (int __sig, __const char *__s);
00142 #endif /* Use misc.  */
00143 
00144 
00145 /* The `sigpause' function has two different interfaces.  The original
00146    BSD definition defines the argument as a mask of the signal, while
00147    the more modern interface in X/Open defines it as the signal
00148    number.  We go with the BSD version unless the user explicitly
00149    selects the X/Open version.
00150 
00151    This function is a cancellation point and therefore not marked with
00152    __THROW.  */
00153 extern int __sigpause (int __sig_or_mask, int __is_sig);
00154 
00155 #ifdef __FAVOR_BSD
00156 /* Set the mask of blocked signals to MASK,
00157    wait for a signal to arrive, and then restore the mask.  */
00158 extern int sigpause (int __mask) __THROW __attribute_deprecated__;
00159 #else
00160 # ifdef __USE_XOPEN
00161 #  ifdef __GNUC__
00162 extern int sigpause (int __sig) __asm__ ("__xpg_sigpause");
00163 #  else
00164 /* Remove a signal from the signal mask and suspend the process.  */
00165 #   define sigpause(sig) __sigpause ((sig), 1)
00166 #  endif
00167 # endif
00168 #endif
00169 
00170 
00171 #ifdef __USE_BSD
00172 /* None of the following functions should be used anymore.  They are here
00173    only for compatibility.  A single word (`int') is not guaranteed to be
00174    enough to hold a complete signal mask and therefore these functions
00175    simply do not work in many situations.  Use `sigprocmask' instead.  */
00176 
00177 /* Compute mask for signal SIG.  */
00178 # define sigmask(sig)       __sigmask(sig)
00179 
00180 /* Block signals in MASK, returning the old mask.  */
00181 extern int sigblock (int __mask) __THROW __attribute_deprecated__;
00182 
00183 /* Set the mask of blocked signals to MASK, returning the old mask.  */
00184 extern int sigsetmask (int __mask) __THROW __attribute_deprecated__;
00185 
00186 /* Return currently selected signal mask.  */
00187 extern int siggetmask (void) __THROW __attribute_deprecated__;
00188 #endif /* Use BSD.  */
00189 
00190 
00191 #ifdef __USE_MISC
00192 # define NSIG _NSIG
00193 #endif
00194 
00195 #ifdef __USE_GNU
00196 typedef __sighandler_t sighandler_t;
00197 #endif
00198 
00199 /* 4.4 BSD uses the name `sig_t' for this.  */
00200 #ifdef __USE_BSD
00201 typedef __sighandler_t sig_t;
00202 #endif
00203 
00204 #ifdef __USE_POSIX
00205 
00206 # ifdef __USE_POSIX199309
00207 /* We need `struct timespec' later on.  */
00208 #  define __need_timespec
00209 #  include <time.h>
00210 
00211 /* Get the `siginfo_t' type plus the needed symbols.  */
00212 #  include <bits/siginfo.h>
00213 # endif
00214 
00215 /* Clear all signals from SET.  */
00216 extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1));
00217 
00218 /* Set all signals in SET.  */
00219 extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1));
00220 
00221 /* Add SIGNO to SET.  */
00222 extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
00223 
00224 /* Remove SIGNO from SET.  */
00225 extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
00226 
00227 /* Return 1 if SIGNO is in SET, 0 if not.  */
00228 extern int sigismember (__const sigset_t *__set, int __signo)
00229      __THROW __nonnull ((1));
00230 
00231 # ifdef __USE_GNU
00232 /* Return non-empty value is SET is not empty.  */
00233 extern int sigisemptyset (__const sigset_t *__set) __THROW __nonnull ((1));
00234 
00235 /* Build new signal set by combining the two inputs set using logical AND.  */
00236 extern int sigandset (sigset_t *__set, __const sigset_t *__left,
00237                     __const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
00238 
00239 /* Build new signal set by combining the two inputs set using logical OR.  */
00240 extern int sigorset (sigset_t *__set, __const sigset_t *__left,
00241                    __const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
00242 # endif /* GNU */
00243 
00244 /* Get the system-specific definitions of `struct sigaction'
00245    and the `SA_*' and `SIG_*'. constants.  */
00246 # include <bits/sigaction.h>
00247 
00248 /* Get and/or change the set of blocked signals.  */
00249 extern int sigprocmask (int __how, __const sigset_t *__restrict __set,
00250                      sigset_t *__restrict __oset) __THROW;
00251 
00252 /* Change the set of blocked signals to SET,
00253    wait until a signal arrives, and restore the set of blocked signals.
00254 
00255    This function is a cancellation point and therefore not marked with
00256    __THROW.  */
00257 extern int sigsuspend (__const sigset_t *__set) __nonnull ((1));
00258 
00259 /* Get and/or set the action for signal SIG.  */
00260 extern int sigaction (int __sig, __const struct sigaction *__restrict __act,
00261                     struct sigaction *__restrict __oact) __THROW;
00262 
00263 /* Put in SET all signals that are blocked and waiting to be delivered.  */
00264 extern int sigpending (sigset_t *__set) __THROW __nonnull ((1));
00265 
00266 
00267 /* Select any of pending signals from SET or wait for any to arrive.
00268 
00269    This function is a cancellation point and therefore not marked with
00270    __THROW.  */
00271 extern int sigwait (__const sigset_t *__restrict __set, int *__restrict __sig)
00272      __nonnull ((1, 2));
00273 
00274 # ifdef __USE_POSIX199309
00275 /* Select any of pending signals from SET and place information in INFO.
00276 
00277    This function is a cancellation point and therefore not marked with
00278    __THROW.  */
00279 extern int sigwaitinfo (__const sigset_t *__restrict __set,
00280                      siginfo_t *__restrict __info) __nonnull ((1));
00281 
00282 /* Select any of pending signals from SET and place information in INFO.
00283    Wait the time specified by TIMEOUT if no signal is pending.
00284 
00285    This function is a cancellation point and therefore not marked with
00286    __THROW.  */
00287 extern int sigtimedwait (__const sigset_t *__restrict __set,
00288                       siginfo_t *__restrict __info,
00289                       __const struct timespec *__restrict __timeout)
00290      __nonnull ((1));
00291 
00292 /* Send signal SIG to the process PID.  Associate data in VAL with the
00293    signal.  */
00294 extern int sigqueue (__pid_t __pid, int __sig, __const union sigval __val)
00295      __THROW;
00296 # endif       /* Use POSIX 199306.  */
00297 
00298 #endif /* Use POSIX.  */
00299 
00300 #ifdef __USE_BSD
00301 
00302 /* Names of the signals.  This variable exists only for compatibility.
00303    Use `strsignal' instead (see <string.h>).  */
00304 extern __const char *__const _sys_siglist[_NSIG];
00305 extern __const char *__const sys_siglist[_NSIG];
00306 
00307 /* Structure passed to `sigvec'.  */
00308 struct sigvec
00309   {
00310     __sighandler_t sv_handler;     /* Signal handler.  */
00311     int sv_mask;            /* Mask of signals to be blocked.  */
00312 
00313     int sv_flags;           /* Flags (see below).  */
00314 # define sv_onstack  sv_flags /* 4.2 BSD compatibility.  */
00315   };
00316 
00317 /* Bits in `sv_flags'.  */
00318 # define SV_ONSTACK  (1 << 0)/* Take the signal on the signal stack.  */
00319 # define SV_INTERRUPT       (1 << 1)/* Do not restart system calls.  */
00320 # define SV_RESETHAND       (1 << 2)/* Reset handler to SIG_DFL on receipt.  */
00321 
00322 
00323 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
00324    of VEC.  The signals in `sv_mask' will be blocked while the handler runs.
00325    If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
00326    reset to SIG_DFL before `sv_handler' is entered.  If OVEC is non-NULL,
00327    it is filled in with the old information for SIG.  */
00328 extern int sigvec (int __sig, __const struct sigvec *__vec,
00329                  struct sigvec *__ovec) __THROW;
00330 
00331 
00332 /* Get machine-dependent `struct sigcontext' and signal subcodes.  */
00333 # include <bits/sigcontext.h>
00334 
00335 /* Restore the state saved in SCP.  */
00336 extern int sigreturn (struct sigcontext *__scp) __THROW;
00337 
00338 #endif /*  use BSD.  */
00339 
00340 
00341 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
00342 # define __need_size_t
00343 # include <stddef.h>
00344 
00345 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
00346    (causing them to fail with EINTR); if INTERRUPT is zero, make system
00347    calls be restarted after signal SIG.  */
00348 extern int siginterrupt (int __sig, int __interrupt) __THROW;
00349 
00350 # include <bits/sigstack.h>
00351 # ifdef __USE_XOPEN
00352 /* This will define `ucontext_t' and `mcontext_t'.  */
00353 #  include <sys/ucontext.h>
00354 # endif
00355 
00356 /* Run signals handlers on the stack specified by SS (if not NULL).
00357    If OSS is not NULL, it is filled in with the old signal stack status.
00358    This interface is obsolete and on many platform not implemented.  */
00359 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
00360      __THROW __attribute_deprecated__;
00361 
00362 /* Alternate signal handler stack interface.
00363    This interface should always be preferred over `sigstack'.  */
00364 extern int sigaltstack (__const struct sigaltstack *__restrict __ss,
00365                      struct sigaltstack *__restrict __oss) __THROW;
00366 
00367 #endif /* use BSD or X/Open Unix.  */
00368 
00369 #ifdef __USE_XOPEN_EXTENDED
00370 /* Simplified interface for signal management.  */
00371 
00372 /* Add SIG to the calling process' signal mask.  */
00373 extern int sighold (int __sig) __THROW;
00374 
00375 /* Remove SIG from the calling process' signal mask.  */
00376 extern int sigrelse (int __sig) __THROW;
00377 
00378 /* Set the disposition of SIG to SIG_IGN.  */
00379 extern int sigignore (int __sig) __THROW;
00380 
00381 /* Set the disposition of SIG.  */
00382 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
00383 #endif
00384 
00385 #if defined __USE_POSIX199506 || defined __USE_UNIX98
00386 /* Some of the functions for handling signals in threaded programs must
00387    be defined here.  */
00388 # include <bits/pthreadtypes.h>
00389 # include <bits/sigthread.h>
00390 #endif /* use Unix98 */
00391 
00392 /* The following functions are used internally in the C library and in
00393    other code which need deep insights.  */
00394 
00395 /* Return number of available real-time signal with highest priority.  */
00396 extern int __libc_current_sigrtmin (void) __THROW;
00397 /* Return number of available real-time signal with lowest priority.  */
00398 extern int __libc_current_sigrtmax (void) __THROW;
00399 
00400 #endif /* signal.h  */
00401 
00402 __END_DECLS
00403 
00404 #endif /* not signal.h */