1 /* syssignal.h - System-dependent definitions for signals.
2 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
4 This file is part of SXEmacs
6 SXEmacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 SXEmacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Synched up with: FSF 19.30. */
22 #ifndef INCLUDED_syssignal_h_
23 #define INCLUDED_syssignal_h_
25 /* In the old world, one could not #include <signal.h> here. The party line
26 was that that header should always be #included before <config.h>, because
27 some configuration files (like s/hpux.h) indicate that SIGIO doesn't work
28 by #undef-ing SIGIO, and if this file #includes <signal.h>, then that will
29 re-#define SIGIO and confuse things.
31 This was, however, a completely fucked up state of affairs, because on some
32 systems it's necessary for the s/m files to #define things in order to get
33 <signal.h> to provide the right typedefs, etc. And it's generally a broken
34 concept for <config.h> to not be the very very first file included.
36 So instead of #undef'ing SIGIO in the various s/m files, I've changed them
37 to define BROKEN_SIGIO instead, then we (syssignal.h) do an #undef SIGIO
38 at the end, after including signal.h. Therefore, it's important that
39 <signal.h> not be included after "syssignal.h", but that's the normal state:
40 nothing should be directly including <signal.h> these days.
47 /* SIGPOLL is the SVR4 signal. Those systems generally define
48 SIGIO as an alias for SIGPOLL, but just in case ... */
50 #if defined (BROKEN_SIGIO)
51 # if defined (SIGIO) && defined (SIGPOLL)
59 #else /* Not BROKEN_SIGIO */
60 # if !defined (SIGIO) && defined (SIGPOLL)
61 # define SIGIO SIGPOLL
65 /* Define SIGCHLD as an alias for SIGCLD. There are many conditionals
67 #if defined (SIGCLD) && !defined (SIGCHLD)
68 # define SIGCHLD SIGCLD
76 #define EMACS_BLOCK_SIGCHLD EMACS_BLOCK_SIGNAL (SIGCHLD)
77 #define EMACS_UNBLOCK_SIGCHLD EMACS_UNBLOCK_SIGNAL (SIGCHLD)
79 #define EMACS_BLOCK_SIGCHLD
80 #define EMACS_UNBLOCK_SIGCHLD
83 /* According to W.R. Stevens __Advanced Programming in the Unix
84 Environment__, there are four different paradigms for handling
85 signals. We use autoconf to tell us which one applies.
87 Note that on some systems, more than one paradigm is implemented
88 (typically, the POSIX sigaction/sigprocmask and either the older
89 SYSV or BSD way). In such a case, we prefer the POSIX way.
91 NOTE: We use EMACS_* macros for most signal operations, but
92 just signal() for the standard signal-setting operation.
93 Perhaps we should change this to EMACS_SIGNAL(), but that runs
94 the risk of someone forgetting this convention and calling
98 typedef SIGTYPE(*signal_handler_t) (int);
101 #if defined (HAVE_SIGPROCMASK)
103 /* The POSIX way (sigaction, sigprocmask, sigpending, sigsuspend) */
105 signal_handler_t sys_do_signal(int signal_number, signal_handler_t action);
106 /* Provide our own version of signal(), that calls sigaction(). The
107 name is not sys_signal() because a function of that name exists in
110 #define signal sys_do_signal
112 #define EMACS_BLOCK_SIGNAL(sig) do \
115 sigemptyset (&ES_mask); \
116 sigaddset (&ES_mask, sig); \
117 sigprocmask (SIG_BLOCK, &ES_mask, NULL); \
119 #define EMACS_UNBLOCK_SIGNAL(sig) do \
122 sigemptyset (&ES_mask); \
123 sigaddset (&ES_mask, sig); \
124 sigprocmask (SIG_UNBLOCK, &ES_mask, NULL); \
126 #define EMACS_UNBLOCK_ALL_SIGNALS() do \
129 sigemptyset (&ES_mask); \
130 sigprocmask (SIG_SETMASK, &ES_mask, NULL); \
132 #define EMACS_WAIT_FOR_SIGNAL(sig) do \
135 sigprocmask (0, NULL, &ES_mask); \
136 sigdelset (&ES_mask, sig); \
137 sigsuspend (&ES_mask); \
139 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
141 #elif defined (HAVE_SIGBLOCK)
143 /* The older BSD way (signal/sigvec, sigblock, sigsetmask, sigpause) */
145 /* It's OK to use signal() here directly. No unreliable signal
146 problems. However, we use sigvec() because it allows us to
147 request interruptible I/O. */
149 #define signal sys_do_signal
151 /* Is it necessary to define sigmask like this? */
153 # define sigmask(no) (1L << ((no) - 1))
156 #define EMACS_BLOCK_SIGNAL(sig) sigblock (sigmask (sig))
157 #define EMACS_UNBLOCK_SIGNAL(sig) sigsetmask (sigblock (0) & ~sigmask (sig))
158 #define EMACS_UNBLOCK_ALL_SIGNALS() sigsetmask (0)
159 #define EMACS_WAIT_FOR_SIGNAL(sig) do \
161 int ES_mask = sigblock (0); \
162 sigpause (ES_mask & ~sigmask (sig)); \
164 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
166 #elif defined (HAVE_SIGHOLD)
168 /* The older SYSV way (signal/sigset, sighold, sigrelse, sigignore,
171 #define signal sigset
172 #define EMACS_BLOCK_SIGNAL(sig) sighold (sig)
173 #define EMACS_UNBLOCK_SIGNAL(sig) sigrelse (sig)
174 /* #### There's not really any simple way to implement this.
175 Since EMACS_UNBLOCK_ALL_SIGNALS() is only called once (at startup),
176 it's probably OK to just ignore it. */
177 #define EMACS_UNBLOCK_ALL_SIGNALS() 0
178 #define EMACS_WAIT_FOR_SIGNAL(sig) sigpause (sig)
179 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
183 /* The oldest SYSV way (signal only; unreliable signals) */
185 /* Old USG systems don't really have signal blocking.
186 We indicate this by not defining EMACS_BLOCK_SIGNAL or
187 EMACS_WAIT_FOR_SIGNAL. */
188 #define EMACS_UNBLOCK_SIGNAL(sig) 0
189 #define EMACS_UNBLOCK_ALL_SIGNALS() 0
190 #define EMACS_REESTABLISH_SIGNAL(sig, handler) do \
192 int old_errno = errno; \
193 signal (sig, handler); \
197 /* Under SYSV, setting a signal handler for SIGCLD causes
198 SIGCLD to immediately be sent if there any unwaited processes
199 out there. This means that the SIGCLD handler *must* call
200 wait() to reap the status of all processes -- it cannot
201 simply set a flag and then reestablish the handler, because
202 it will get called again, infinitely. We only need to
203 worry about this on systems where signals need to be
204 reestablished (SYSV Release 2 and earlier). */
205 #define OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
209 /* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
210 Must do that using the killpg call. */
212 #define EMACS_KILLPG(pid, signo) killpg (pid, signo)
214 #define EMACS_KILLPG(pid, signo) kill (-(pid), signo)
218 # define NSIG (SIGUSR2+1) /* guess how many elements are in sys_siglist... */
221 /* HAVE_DECL_SYS_SIGLIST is determined by configure. On Linux, it seems,
222 configure incorrectly fails to find it, so s/linux.h defines
224 #if (!defined(HAVE_DECL_SYS_SIGLIST) || !HAVE_DECL_SYS_SIGLIST ) && !defined (HAVE_SYS_SIGLIST)
225 extern const char *sys_siglist[];
229 SIGTYPE memory_warning_signal(int sig);
233 #endif /* INCLUDED_syssignal_h_ */