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
|
|
110 #ifndef NeXT
|
872
|
111 typedef RETSIGTYPE (XCDECL * signal_handler_t) (int);
|
428
|
112 #endif
|
|
113
|
|
114 #if defined (HAVE_SIGPROCMASK)
|
|
115
|
|
116 /* The POSIX way (sigaction, sigprocmask, sigpending, sigsuspend) */
|
|
117
|
613
|
118 signal_handler_t qxe_reliable_signal (int signal_number,
|
|
119 signal_handler_t action);
|
|
120
|
|
121 #define EMACS_SIGNAL qxe_reliable_signal
|
428
|
122
|
|
123 #define EMACS_BLOCK_SIGNAL(sig) do \
|
|
124 { \
|
|
125 sigset_t ES_mask; \
|
|
126 sigemptyset (&ES_mask); \
|
|
127 sigaddset (&ES_mask, sig); \
|
|
128 sigprocmask (SIG_BLOCK, &ES_mask, NULL); \
|
|
129 } while (0)
|
|
130 #define EMACS_UNBLOCK_SIGNAL(sig) do \
|
|
131 { \
|
|
132 sigset_t ES_mask; \
|
|
133 sigemptyset (&ES_mask); \
|
|
134 sigaddset (&ES_mask, sig); \
|
|
135 sigprocmask (SIG_UNBLOCK, &ES_mask, NULL); \
|
|
136 } while (0)
|
|
137 #define EMACS_UNBLOCK_ALL_SIGNALS() do \
|
|
138 { \
|
|
139 sigset_t ES_mask; \
|
|
140 sigemptyset (&ES_mask); \
|
|
141 sigprocmask (SIG_SETMASK, &ES_mask, NULL); \
|
|
142 } while (0)
|
|
143 #define EMACS_WAIT_FOR_SIGNAL(sig) do \
|
|
144 { \
|
|
145 sigset_t ES_mask; \
|
|
146 sigprocmask (0, NULL, &ES_mask); \
|
|
147 sigdelset (&ES_mask, sig); \
|
|
148 sigsuspend (&ES_mask); \
|
|
149 } while (0)
|
|
150 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
|
2286
|
151 #define SIG_ARG_MAYBE_UNUSED(decl) UNUSED (decl)
|
428
|
152
|
|
153 #elif defined (HAVE_SIGBLOCK)
|
|
154
|
|
155 /* The older BSD way (signal/sigvec, sigblock, sigsetmask, sigpause) */
|
|
156
|
|
157 /* It's OK to use signal() here directly. No unreliable signal
|
|
158 problems. However, we use sigvec() because it allows us to
|
|
159 request interruptible I/O. */
|
|
160
|
613
|
161 #define EMACS_SIGNAL qxe_reliable_signal
|
428
|
162
|
|
163 /* Is it necessary to define sigmask like this? */
|
|
164 #ifndef sigmask
|
|
165 # define sigmask(no) (1L << ((no) - 1))
|
|
166 #endif
|
|
167
|
|
168 #define EMACS_BLOCK_SIGNAL(sig) sigblock (sigmask (sig))
|
|
169 #define EMACS_UNBLOCK_SIGNAL(sig) sigsetmask (sigblock (0) & ~sigmask (sig))
|
|
170 #define EMACS_UNBLOCK_ALL_SIGNALS() sigsetmask (0)
|
|
171 #define EMACS_WAIT_FOR_SIGNAL(sig) do \
|
|
172 { \
|
|
173 int ES_mask = sigblock (0); \
|
|
174 sigpause (ES_mask & ~sigmask (sig)); \
|
|
175 } while (0)
|
|
176 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
|
2286
|
177 #define SIG_ARG_MAYBE_UNUSED(decl) UNUSED (decl)
|
428
|
178
|
|
179 #elif defined (HAVE_SIGHOLD)
|
|
180
|
|
181 /* The older SYSV way (signal/sigset, sighold, sigrelse, sigignore,
|
|
182 sigpause) */
|
|
183
|
613
|
184 #define EMACS_SIGNAL sigset
|
428
|
185 #define EMACS_BLOCK_SIGNAL(sig) sighold (sig)
|
|
186 #define EMACS_UNBLOCK_SIGNAL(sig) sigrelse (sig)
|
|
187 /* #### There's not really any simple way to implement this.
|
|
188 Since EMACS_UNBLOCK_ALL_SIGNALS() is only called once (at startup),
|
|
189 it's probably OK to just ignore it. */
|
|
190 #define EMACS_UNBLOCK_ALL_SIGNALS() 0
|
|
191 #define EMACS_WAIT_FOR_SIGNAL(sig) sigpause (sig)
|
|
192 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
|
2286
|
193 #define SIG_ARG_MAYBE_UNUSED(decl) UNUSED (decl)
|
428
|
194
|
613
|
195 #elif defined (WIN32_NATIVE)
|
|
196
|
|
197 /* MS Windows signal emulation (in turns emulates the sigset/sighold
|
|
198 paradigm) */
|
|
199
|
|
200 #define EMACS_SIGNAL mswindows_sigset
|
|
201 #define EMACS_BLOCK_SIGNAL(sig) mswindows_sighold (sig)
|
|
202 #define EMACS_UNBLOCK_SIGNAL(sig) mswindows_sigrelse (sig)
|
|
203 /* #### There's not really any simple way to implement this.
|
|
204 Since EMACS_UNBLOCK_ALL_SIGNALS() is only called once (at startup),
|
|
205 it's probably OK to just ignore it. */
|
|
206 #define EMACS_UNBLOCK_ALL_SIGNALS() 0
|
|
207 #define EMACS_WAIT_FOR_SIGNAL(sig) mswindows_sigpause (sig)
|
|
208 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
|
2286
|
209 #define SIG_ARG_MAYBE_UNUSED(decl) UNUSED (decl)
|
613
|
210
|
|
211 /* Defines that we need that aren't in the standard signal.h */
|
|
212 #define SIGHUP 1 /* Hang up */
|
|
213 #define SIGQUIT 3 /* Quit process */
|
|
214 #define SIGKILL 9 /* Die, die die */
|
|
215 #define SIGALRM 14 /* Alarm */
|
|
216 #define SIGPROF 29 /* Profiling timer exp */
|
|
217
|
428
|
218 #else
|
|
219
|
|
220 /* The oldest SYSV way (signal only; unreliable signals) */
|
|
221
|
|
222 /* Old USG systems don't really have signal blocking.
|
|
223 We indicate this by not defining EMACS_BLOCK_SIGNAL or
|
|
224 EMACS_WAIT_FOR_SIGNAL. */
|
613
|
225 #define EMACS_SIGNAL signal
|
428
|
226 #define EMACS_UNBLOCK_SIGNAL(sig) 0
|
|
227 #define EMACS_UNBLOCK_ALL_SIGNALS() 0
|
|
228 #define EMACS_REESTABLISH_SIGNAL(sig, handler) do \
|
|
229 { \
|
|
230 int old_errno = errno; \
|
|
231 signal (sig, handler); \
|
|
232 errno = old_errno; \
|
|
233 } while (0)
|
2286
|
234 #define SIG_ARG_MAYBE_UNUSED(decl) decl
|
428
|
235
|
|
236 /* Under SYSV, setting a signal handler for SIGCLD causes
|
|
237 SIGCLD to immediately be sent if there any unwaited processes
|
|
238 out there. This means that the SIGCLD handler *must* call
|
|
239 wait() to reap the status of all processes -- it cannot
|
|
240 simply set a flag and then reestablish the handler, because
|
|
241 it will get called again, infinitely. We only need to
|
|
242 worry about this on systems where signals need to be
|
|
243 reestablished (SYSV Release 2 and earlier). */
|
|
244 #define OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
|
|
245
|
613
|
246 #endif /* different signalling methods */
|
428
|
247
|
|
248 /* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
|
|
249 Must do that using the killpg call. */
|
442
|
250 #ifdef HAVE_KILLPG
|
|
251 #define EMACS_KILLPG(pid, signo) killpg (pid, signo)
|
814
|
252 #elif defined (WIN32_NATIVE)
|
|
253 #define EMACS_KILLPG(pid, signo) should never be called
|
428
|
254 #else
|
442
|
255 #define EMACS_KILLPG(pid, signo) kill (-(pid), signo)
|
428
|
256 #endif
|
|
257
|
|
258 #ifndef NSIG
|
978
|
259 # ifdef USG5_4
|
|
260 /* Some SVr4s don't define NSIG in sys/signal.h for ANSI environments;
|
|
261 * instead, there's a system variable _sys_nsig. Unfortunately, we need the
|
|
262 * constant to dimension an array. So wire in the appropriate value here.
|
|
263 */
|
|
264 # define NSIG 32
|
|
265 # else
|
|
266 # define NSIG (SIGUSR2+1) /* guess how many elements are in sys_siglist... */
|
|
267 # endif
|
428
|
268 #endif
|
|
269
|
2651
|
270 /* HAVE_DECL_SYS_SIGLIST is determined by configure. On Linux, it seems,
|
428
|
271 configure incorrectly fails to find it, so s/linux.h defines
|
|
272 HAVE_SYS_SIGLIST. */
|
2651
|
273 #if !defined (HAVE_DECL_SYS_SIGLIST) && !defined (HAVE_SYS_SIGLIST)
|
442
|
274 extern const char *sys_siglist[];
|
428
|
275 #endif
|
|
276
|
|
277 #ifdef SIGDANGER
|
|
278 SIGTYPE memory_warning_signal (int sig);
|
|
279 #endif
|
|
280
|
613
|
281 #if defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS)
|
442
|
282 typedef void (__cdecl *mswindows_sighandler) (int);
|
613
|
283
|
|
284 /* Prototypes for signal functions, see win32.c */
|
442
|
285 int mswindows_sighold (int nsig);
|
|
286 int mswindows_sigrelse (int nsig);
|
|
287 int mswindows_sigpause (int nsig);
|
|
288 int mswindows_raise (int nsig);
|
613
|
289 mswindows_sighandler mswindows_sigset (int sig, mswindows_sighandler handler);
|
|
290
|
|
291 #endif /* defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS) */
|
|
292
|
|
293 signal_handler_t set_timeout_signal (int signal_number,
|
|
294 signal_handler_t action);
|
|
295
|
428
|
296
|
440
|
297 #endif /* INCLUDED_syssignal_h_ */
|