428
|
1 /* syssignal.h - System-dependent definitions for signals.
|
|
2 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
|
814
|
3 Copyright (C) 1996 Ben Wing.
|
|
4
|
428
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: FSF 19.30. */
|
|
23
|
440
|
24 #ifndef INCLUDED_syssignal_h_
|
|
25 #define INCLUDED_syssignal_h_
|
428
|
26
|
|
27 /* In the old world, one could not #include <signal.h> here. The party line
|
|
28 was that that header should always be #included before <config.h>, because
|
|
29 some configuration files (like s/hpux.h) indicate that SIGIO doesn't work
|
|
30 by #undef-ing SIGIO, and if this file #includes <signal.h>, then that will
|
|
31 re-#define SIGIO and confuse things.
|
|
32
|
|
33 This was, however, a completely fucked up state of affairs, because on some
|
|
34 systems it's necessary for the s/m files to #define things in order to get
|
|
35 <signal.h> to provide the right typedefs, etc. And it's generally a broken
|
|
36 concept for <config.h> to not be the very very first file included.
|
|
37
|
|
38 So instead of #undef'ing SIGIO in the various s/m files, I've changed them
|
|
39 to define BROKEN_SIGIO instead, then we (syssignal.h) do an #undef SIGIO
|
|
40 at the end, after including signal.h. Therefore, it's important that
|
|
41 <signal.h> not be included after "syssignal.h", but that's the normal state:
|
|
42 nothing should be directly including <signal.h> these days.
|
|
43 -- jwz, 29-nov-93
|
|
44 */
|
|
45
|
|
46 #include <signal.h>
|
|
47 #include <errno.h>
|
|
48
|
|
49 /* SIGPOLL is the SVR4 signal. Those systems generally define
|
|
50 SIGIO as an alias for SIGPOLL, but just in case ... */
|
|
51
|
|
52 #if defined (BROKEN_SIGIO)
|
|
53 # if defined (SIGIO) && defined (SIGPOLL)
|
|
54 # if SIGIO == SIGPOLL
|
|
55 # undef SIGIO
|
|
56 # undef SIGPOLL
|
|
57 # else
|
|
58 # undef SIGIO
|
|
59 # endif
|
|
60 # endif
|
|
61 #else /* Not BROKEN_SIGIO */
|
|
62 # if !defined (SIGIO) && defined (SIGPOLL)
|
|
63 # define SIGIO SIGPOLL
|
|
64 # endif
|
|
65 #endif
|
|
66
|
|
67 /* Define SIGCHLD as an alias for SIGCLD. There are many conditionals
|
|
68 testing SIGCHLD. */
|
|
69 #if defined (SIGCLD) && !defined (SIGCHLD)
|
|
70 # define SIGCHLD SIGCLD
|
|
71 #endif /* SIGCHLD */
|
|
72
|
|
73 #ifdef BROKEN_SIGCHLD
|
|
74 #undef SIGCHLD
|
|
75 #endif
|
|
76
|
|
77 #ifdef SIGCHLD
|
|
78 #define EMACS_BLOCK_SIGCHLD EMACS_BLOCK_SIGNAL (SIGCHLD)
|
|
79 #define EMACS_UNBLOCK_SIGCHLD EMACS_UNBLOCK_SIGNAL (SIGCHLD)
|
|
80 #else
|
|
81 #define EMACS_BLOCK_SIGCHLD
|
|
82 #define EMACS_UNBLOCK_SIGCHLD
|
|
83 #endif
|
|
84
|
|
85 /* According to W.R. Stevens __Advanced Programming in the Unix
|
|
86 Environment__, there are four different paradigms for handling
|
|
87 signals. We use autoconf to tell us which one applies.
|
|
88
|
|
89 Note that on some systems, more than one paradigm is implemented
|
|
90 (typically, the POSIX sigaction/sigprocmask and either the older
|
|
91 SYSV or BSD way). In such a case, we prefer the POSIX way.
|
|
92
|
613
|
93 We used to say this:
|
|
94
|
|
95 [[ NOTE: We use EMACS_* macros for most signal operations, but
|
428
|
96 just signal() for the standard signal-setting operation.
|
|
97 Perhaps we should change this to EMACS_SIGNAL(), but that runs
|
|
98 the risk of someone forgetting this convention and calling
|
613
|
99 signal() directly. ]]
|
|
100
|
|
101 But current policy is to avoid playing with macros as much as
|
|
102 possible, since in the long run it really just ends up creating
|
|
103 unmaintainable code -- someone newly reading the code is never
|
|
104 going to realize exactly which calls are redirected, and on
|
|
105 which systems, and where the redirection occurs.
|
|
106
|
|
107 Possibly we should use the new "qxe" convention.
|
|
108 */
|
428
|
109
|
872
|
110 typedef RETSIGTYPE (XCDECL * signal_handler_t) (int);
|
428
|
111
|
|
112 #if defined (HAVE_SIGPROCMASK)
|
|
113
|
|
114 /* The POSIX way (sigaction, sigprocmask, sigpending, sigsuspend) */
|
|
115
|
613
|
116 signal_handler_t qxe_reliable_signal (int signal_number,
|
|
117 signal_handler_t action);
|
|
118
|
|
119 #define EMACS_SIGNAL qxe_reliable_signal
|
428
|
120
|
|
121 #define EMACS_BLOCK_SIGNAL(sig) do \
|
|
122 { \
|
|
123 sigset_t ES_mask; \
|
|
124 sigemptyset (&ES_mask); \
|
|
125 sigaddset (&ES_mask, sig); \
|
|
126 sigprocmask (SIG_BLOCK, &ES_mask, NULL); \
|
|
127 } while (0)
|
|
128 #define EMACS_UNBLOCK_SIGNAL(sig) do \
|
|
129 { \
|
|
130 sigset_t ES_mask; \
|
|
131 sigemptyset (&ES_mask); \
|
|
132 sigaddset (&ES_mask, sig); \
|
|
133 sigprocmask (SIG_UNBLOCK, &ES_mask, NULL); \
|
|
134 } while (0)
|
|
135 #define EMACS_UNBLOCK_ALL_SIGNALS() do \
|
|
136 { \
|
|
137 sigset_t ES_mask; \
|
|
138 sigemptyset (&ES_mask); \
|
|
139 sigprocmask (SIG_SETMASK, &ES_mask, NULL); \
|
|
140 } while (0)
|
|
141 #define EMACS_WAIT_FOR_SIGNAL(sig) do \
|
|
142 { \
|
|
143 sigset_t ES_mask; \
|
|
144 sigprocmask (0, NULL, &ES_mask); \
|
|
145 sigdelset (&ES_mask, sig); \
|
|
146 sigsuspend (&ES_mask); \
|
|
147 } while (0)
|
|
148 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
|
2286
|
149 #define SIG_ARG_MAYBE_UNUSED(decl) UNUSED (decl)
|
428
|
150
|
|
151 #elif defined (HAVE_SIGBLOCK)
|
|
152
|
|
153 /* The older BSD way (signal/sigvec, sigblock, sigsetmask, sigpause) */
|
|
154
|
|
155 /* It's OK to use signal() here directly. No unreliable signal
|
|
156 problems. However, we use sigvec() because it allows us to
|
|
157 request interruptible I/O. */
|
|
158
|
613
|
159 #define EMACS_SIGNAL qxe_reliable_signal
|
428
|
160
|
|
161 /* Is it necessary to define sigmask like this? */
|
|
162 #ifndef sigmask
|
|
163 # define sigmask(no) (1L << ((no) - 1))
|
|
164 #endif
|
|
165
|
|
166 #define EMACS_BLOCK_SIGNAL(sig) sigblock (sigmask (sig))
|
|
167 #define EMACS_UNBLOCK_SIGNAL(sig) sigsetmask (sigblock (0) & ~sigmask (sig))
|
|
168 #define EMACS_UNBLOCK_ALL_SIGNALS() sigsetmask (0)
|
|
169 #define EMACS_WAIT_FOR_SIGNAL(sig) do \
|
|
170 { \
|
|
171 int ES_mask = sigblock (0); \
|
|
172 sigpause (ES_mask & ~sigmask (sig)); \
|
|
173 } while (0)
|
|
174 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
|
2286
|
175 #define SIG_ARG_MAYBE_UNUSED(decl) UNUSED (decl)
|
428
|
176
|
|
177 #elif defined (HAVE_SIGHOLD)
|
|
178
|
|
179 /* The older SYSV way (signal/sigset, sighold, sigrelse, sigignore,
|
|
180 sigpause) */
|
|
181
|
613
|
182 #define EMACS_SIGNAL sigset
|
428
|
183 #define EMACS_BLOCK_SIGNAL(sig) sighold (sig)
|
|
184 #define EMACS_UNBLOCK_SIGNAL(sig) sigrelse (sig)
|
|
185 /* #### There's not really any simple way to implement this.
|
|
186 Since EMACS_UNBLOCK_ALL_SIGNALS() is only called once (at startup),
|
|
187 it's probably OK to just ignore it. */
|
|
188 #define EMACS_UNBLOCK_ALL_SIGNALS() 0
|
|
189 #define EMACS_WAIT_FOR_SIGNAL(sig) sigpause (sig)
|
|
190 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
|
2286
|
191 #define SIG_ARG_MAYBE_UNUSED(decl) UNUSED (decl)
|
428
|
192
|
613
|
193 #elif defined (WIN32_NATIVE)
|
|
194
|
|
195 /* MS Windows signal emulation (in turns emulates the sigset/sighold
|
|
196 paradigm) */
|
|
197
|
|
198 #define EMACS_SIGNAL mswindows_sigset
|
|
199 #define EMACS_BLOCK_SIGNAL(sig) mswindows_sighold (sig)
|
|
200 #define EMACS_UNBLOCK_SIGNAL(sig) mswindows_sigrelse (sig)
|
|
201 /* #### There's not really any simple way to implement this.
|
|
202 Since EMACS_UNBLOCK_ALL_SIGNALS() is only called once (at startup),
|
|
203 it's probably OK to just ignore it. */
|
|
204 #define EMACS_UNBLOCK_ALL_SIGNALS() 0
|
|
205 #define EMACS_WAIT_FOR_SIGNAL(sig) mswindows_sigpause (sig)
|
|
206 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
|
2286
|
207 #define SIG_ARG_MAYBE_UNUSED(decl) UNUSED (decl)
|
613
|
208
|
|
209 /* Defines that we need that aren't in the standard signal.h */
|
|
210 #define SIGHUP 1 /* Hang up */
|
|
211 #define SIGQUIT 3 /* Quit process */
|
|
212 #define SIGKILL 9 /* Die, die die */
|
|
213 #define SIGALRM 14 /* Alarm */
|
|
214 #define SIGPROF 29 /* Profiling timer exp */
|
|
215
|
428
|
216 #else
|
|
217
|
|
218 /* The oldest SYSV way (signal only; unreliable signals) */
|
|
219
|
|
220 /* Old USG systems don't really have signal blocking.
|
|
221 We indicate this by not defining EMACS_BLOCK_SIGNAL or
|
|
222 EMACS_WAIT_FOR_SIGNAL. */
|
613
|
223 #define EMACS_SIGNAL signal
|
428
|
224 #define EMACS_UNBLOCK_SIGNAL(sig) 0
|
|
225 #define EMACS_UNBLOCK_ALL_SIGNALS() 0
|
|
226 #define EMACS_REESTABLISH_SIGNAL(sig, handler) do \
|
|
227 { \
|
|
228 int old_errno = errno; \
|
|
229 signal (sig, handler); \
|
|
230 errno = old_errno; \
|
|
231 } while (0)
|
2286
|
232 #define SIG_ARG_MAYBE_UNUSED(decl) decl
|
428
|
233
|
|
234 /* Under SYSV, setting a signal handler for SIGCLD causes
|
|
235 SIGCLD to immediately be sent if there any unwaited processes
|
|
236 out there. This means that the SIGCLD handler *must* call
|
|
237 wait() to reap the status of all processes -- it cannot
|
|
238 simply set a flag and then reestablish the handler, because
|
|
239 it will get called again, infinitely. We only need to
|
|
240 worry about this on systems where signals need to be
|
|
241 reestablished (SYSV Release 2 and earlier). */
|
|
242 #define OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
|
|
243
|
613
|
244 #endif /* different signalling methods */
|
428
|
245
|
|
246 /* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
|
|
247 Must do that using the killpg call. */
|
442
|
248 #ifdef HAVE_KILLPG
|
|
249 #define EMACS_KILLPG(pid, signo) killpg (pid, signo)
|
814
|
250 #elif defined (WIN32_NATIVE)
|
|
251 #define EMACS_KILLPG(pid, signo) should never be called
|
428
|
252 #else
|
442
|
253 #define EMACS_KILLPG(pid, signo) kill (-(pid), signo)
|
428
|
254 #endif
|
|
255
|
|
256 #ifndef NSIG
|
978
|
257 # ifdef USG5_4
|
|
258 /* Some SVr4s don't define NSIG in sys/signal.h for ANSI environments;
|
|
259 * instead, there's a system variable _sys_nsig. Unfortunately, we need the
|
|
260 * constant to dimension an array. So wire in the appropriate value here.
|
|
261 */
|
|
262 # define NSIG 32
|
|
263 # else
|
|
264 # define NSIG (SIGUSR2+1) /* guess how many elements are in sys_siglist... */
|
|
265 # endif
|
428
|
266 #endif
|
|
267
|
2651
|
268 /* HAVE_DECL_SYS_SIGLIST is determined by configure. On Linux, it seems,
|
428
|
269 configure incorrectly fails to find it, so s/linux.h defines
|
|
270 HAVE_SYS_SIGLIST. */
|
2655
|
271 #if (!defined(HAVE_DECL_SYS_SIGLIST) || !HAVE_DECL_SYS_SIGLIST ) && !defined (HAVE_SYS_SIGLIST)
|
442
|
272 extern const char *sys_siglist[];
|
428
|
273 #endif
|
|
274
|
|
275 #ifdef SIGDANGER
|
|
276 SIGTYPE memory_warning_signal (int sig);
|
|
277 #endif
|
|
278
|
613
|
279 #if defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS)
|
442
|
280 typedef void (__cdecl *mswindows_sighandler) (int);
|
613
|
281
|
|
282 /* Prototypes for signal functions, see win32.c */
|
442
|
283 int mswindows_sighold (int nsig);
|
|
284 int mswindows_sigrelse (int nsig);
|
|
285 int mswindows_sigpause (int nsig);
|
|
286 int mswindows_raise (int nsig);
|
613
|
287 mswindows_sighandler mswindows_sigset (int sig, mswindows_sighandler handler);
|
|
288
|
|
289 #endif /* defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS) */
|
|
290
|
|
291 signal_handler_t set_timeout_signal (int signal_number,
|
|
292 signal_handler_t action);
|
|
293
|
428
|
294
|
440
|
295 #endif /* INCLUDED_syssignal_h_ */
|