Build Fix -- compatibility issue with newer autoconf
[sxemacs] / src / syssignal.h
1 /* syssignal.h - System-dependent definitions for signals.
2    Copyright (C) 1992, 1993 Free Software Foundation, Inc.
3
4 This file is part of SXEmacs
5
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.
10
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.
15
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/>. */
18
19
20 /* Synched up with: FSF 19.30. */
21
22 #ifndef INCLUDED_syssignal_h_
23 #define INCLUDED_syssignal_h_
24
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.
30
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.
35
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.
41                                                         -- jwz, 29-nov-93
42  */
43
44 #include <signal.h>
45 #include <errno.h>
46
47 /* SIGPOLL is the SVR4 signal.  Those systems generally define
48    SIGIO as an alias for SIGPOLL, but just in case ... */
49
50 #if defined (BROKEN_SIGIO)
51 #  if defined (SIGIO) && defined (SIGPOLL)
52 #    if SIGIO == SIGPOLL
53 #      undef SIGIO
54 #      undef SIGPOLL
55 #    else
56 #      undef SIGIO
57 #    endif
58 #  endif
59 #else                           /* Not BROKEN_SIGIO */
60 #  if !defined (SIGIO) && defined (SIGPOLL)
61 #    define SIGIO SIGPOLL
62 #  endif
63 #endif
64
65 /* Define SIGCHLD as an alias for SIGCLD.  There are many conditionals
66    testing SIGCHLD.  */
67 #if defined (SIGCLD) && !defined (SIGCHLD)
68 # define SIGCHLD SIGCLD
69 #endif                          /* SIGCHLD */
70
71 #ifdef BROKEN_SIGCHLD
72 #undef SIGCHLD
73 #endif
74
75 #ifdef SIGCHLD
76 #define EMACS_BLOCK_SIGCHLD EMACS_BLOCK_SIGNAL (SIGCHLD)
77 #define EMACS_UNBLOCK_SIGCHLD EMACS_UNBLOCK_SIGNAL (SIGCHLD)
78 #else
79 #define EMACS_BLOCK_SIGCHLD
80 #define EMACS_UNBLOCK_SIGCHLD
81 #endif
82
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.
86
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.
90
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
95    signal() directly. */
96
97 #ifndef NeXT
98 typedef SIGTYPE(*signal_handler_t) (int);
99 #endif
100
101 #if defined (HAVE_SIGPROCMASK)
102
103 /* The POSIX way (sigaction, sigprocmask, sigpending, sigsuspend) */
104
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
108    libenergize.a */
109 #undef signal
110 #define signal sys_do_signal
111
112 #define EMACS_BLOCK_SIGNAL(sig) do              \
113 {                                               \
114   sigset_t ES_mask;                             \
115   sigemptyset (&ES_mask);                       \
116   sigaddset (&ES_mask, sig);                    \
117   sigprocmask (SIG_BLOCK, &ES_mask, NULL);      \
118 } while (0)
119 #define EMACS_UNBLOCK_SIGNAL(sig) do            \
120 {                                               \
121   sigset_t ES_mask;                             \
122   sigemptyset (&ES_mask);                       \
123   sigaddset (&ES_mask, sig);                    \
124   sigprocmask (SIG_UNBLOCK, &ES_mask, NULL);    \
125 } while (0)
126 #define EMACS_UNBLOCK_ALL_SIGNALS() do          \
127 {                                               \
128   sigset_t ES_mask;                             \
129   sigemptyset (&ES_mask);                       \
130   sigprocmask (SIG_SETMASK, &ES_mask, NULL);    \
131 } while (0)
132 #define EMACS_WAIT_FOR_SIGNAL(sig) do           \
133 {                                               \
134   sigset_t ES_mask;                             \
135   sigprocmask (0, NULL, &ES_mask);              \
136   sigdelset (&ES_mask, sig);                    \
137   sigsuspend (&ES_mask);                        \
138 } while (0)
139 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
140
141 #elif defined (HAVE_SIGBLOCK)
142
143 /* The older BSD way (signal/sigvec, sigblock, sigsetmask, sigpause) */
144
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. */
148
149 #define signal sys_do_signal
150
151 /* Is it necessary to define sigmask like this? */
152 #ifndef sigmask
153 # define sigmask(no) (1L << ((no) - 1))
154 #endif
155
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           \
160 {                                               \
161   int ES_mask = sigblock (0);                   \
162   sigpause (ES_mask & ~sigmask (sig));          \
163 } while (0)
164 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
165
166 #elif defined (HAVE_SIGHOLD)
167
168 /* The older SYSV way (signal/sigset, sighold, sigrelse, sigignore,
169    sigpause) */
170
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)
180
181 #else
182
183 /* The oldest SYSV way (signal only; unreliable signals) */
184
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       \
191 {                                                       \
192   int old_errno = errno;                                \
193   signal (sig, handler);                                \
194   errno = old_errno;                                    \
195 } while (0)
196
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
206
207 #endif
208
209 /* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
210    Must do that using the killpg call.  */
211 #ifdef HAVE_KILLPG
212 #define EMACS_KILLPG(pid, signo) killpg (pid, signo)
213 #else
214 #define EMACS_KILLPG(pid, signo) kill (-(pid), signo)
215 #endif
216
217 #ifndef NSIG
218 # define NSIG (SIGUSR2+1)       /* guess how many elements are in sys_siglist... */
219 #endif
220
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
223    HAVE_SYS_SIGLIST. */
224 #if (!defined(HAVE_DECL_SYS_SIGLIST) || !HAVE_DECL_SYS_SIGLIST ) && !defined (HAVE_SYS_SIGLIST)
225 extern const char *sys_siglist[];
226 #endif
227
228 #ifdef SIGDANGER
229 SIGTYPE memory_warning_signal(int sig);
230 #endif
231
232
233 #endif                          /* INCLUDED_syssignal_h_ */