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