Back to index

tetex-bin  3.0
signals.h
Go to the documentation of this file.
00001 /* signals.h -- header to include system dependent signal definitions.
00002    $Id: signals.h,v 1.2 2004/04/11 17:56:46 karl Exp $
00003 
00004    Copyright (C) 1993, 1994, 1995, 1997, 2002, 2004 Free Software Foundation, Inc.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2, or (at your option)
00009    any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019 
00020    Originally written by Brian Fox (bfox@ai.mit.edu). */
00021 
00022 #ifndef INFO_SIGNALS_H
00023 #define INFO_SIGNALS_H
00024 
00025 #include <sys/types.h>
00026 #include <signal.h>
00027 
00028 /* For sysV68 --phdm@info.ucl.ac.be.  */
00029 #if !defined (SIGCHLD) && defined (SIGCLD)
00030 #define SIGCHLD SIGCLD
00031 #endif
00032 
00033 #if !defined (HAVE_SIGPROCMASK) && !defined (sigmask)
00034 #  define sigmask(x) (1 << ((x)-1))
00035 #endif /* !HAVE_SIGPROCMASK && !sigmask */
00036 
00037 /* Without SA_NOCLDSTOP, sigset_t might end up being undefined even
00038    though we have sigprocmask, on older systems, according to Nelson
00039    Beebe.  The test is from coreutils/sort.c, via Paul Eggert.  */
00040 #if !defined (HAVE_SIGPROCMASK) || !defined (SA_NOCLDSTOP)
00041 #  if !defined (SIG_BLOCK)
00042 #    define SIG_UNBLOCK 1
00043 #    define SIG_BLOCK   2
00044 #    define SIG_SETMASK 3
00045 #  endif /* SIG_BLOCK */
00046 
00047 /* Type of a signal set. */
00048 #  define sigset_t int
00049 
00050 /* Make SET have no signals in it. */
00051 #  define sigemptyset(set) (*(set) = (sigset_t)0x0)
00052 
00053 /* Make SET have the full range of signal specifications possible. */
00054 #  define sigfillset(set) (*(set) = (sigset_t)0xffffffffff)
00055 
00056 /* Add SIG to the contents of SET. */
00057 #  define sigaddset(set, sig) *(set) |= sigmask (sig)
00058 
00059 /* Delete SIG from the contents of SET. */
00060 #  define sigdelset(set, sig) *(set) &= ~(sigmask (sig))
00061 
00062 /* Tell if SET contains SIG. */
00063 #  define sigismember(set, sig) (*(set) & (sigmask (sig)))
00064 
00065 /* Suspend the process until the reception of one of the signals
00066    not present in SET. */
00067 #  define sigsuspend(set) sigpause (*(set))
00068 #endif /* !HAVE_SIGPROCMASK */
00069 
00070 #if defined (HAVE_SIGPROCMASK) || defined (HAVE_SIGSETMASK)
00071 /* These definitions are used both in POSIX and non-POSIX implementations. */
00072 
00073 #define BLOCK_SIGNAL(sig) \
00074   do { \
00075     sigset_t nvar, ovar; \
00076     sigemptyset (&nvar); \
00077     sigemptyset (&ovar); \
00078     sigaddset (&nvar, sig); \
00079     sigprocmask (SIG_BLOCK, &nvar, &ovar); \
00080   } while (0)
00081 
00082 #define UNBLOCK_SIGNAL(sig) \
00083   do { \
00084     sigset_t nvar, ovar; \
00085     sigemptyset (&ovar); \
00086     sigemptyset (&nvar); \
00087     sigaddset (&nvar, sig); \
00088     sigprocmask (SIG_UNBLOCK, &nvar, &ovar); \
00089   } while (0)
00090 
00091 #else /* !HAVE_SIGPROCMASK && !HAVE_SIGSETMASK */
00092 #  define BLOCK_SIGNAL(sig)
00093 #  define UNBLOCK_SIGNAL(sig)
00094 #endif /* !HAVE_SIGPROCMASK && !HAVE_SIGSETMASK */
00095 
00096 #endif /* not INFO_SIGNALS_H */