Mercurial > hg > xemacs-beta
annotate src/syssignal.h @ 5940:c608d4b0b75e cygwin64 tip
rescue lost branch from 64bit.backup
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Thu, 16 Dec 2021 18:48:58 +0000 |
parents | 308d34e9f07d |
children | 574f0cded429 |
rev | line source |
---|---|
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 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4759
diff
changeset
|
7 XEmacs is free software: you can redistribute it and/or modify it |
428 | 8 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4759
diff
changeset
|
9 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4759
diff
changeset
|
10 option) any later version. |
428 | 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 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4759
diff
changeset
|
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 19 |
20 /* Synched up with: FSF 19.30. */ | |
21 | |
440 | 22 #ifndef INCLUDED_syssignal_h_ |
23 #define INCLUDED_syssignal_h_ | |
428 | 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 | |
613 | 91 We used to say this: |
92 | |
93 [[ NOTE: We use EMACS_* macros for most signal operations, but | |
428 | 94 just signal() for the standard signal-setting operation. |
95 Perhaps we should change this to EMACS_SIGNAL(), but that runs | |
96 the risk of someone forgetting this convention and calling | |
613 | 97 signal() directly. ]] |
98 | |
99 But current policy is to avoid playing with macros as much as | |
100 possible, since in the long run it really just ends up creating | |
101 unmaintainable code -- someone newly reading the code is never | |
102 going to realize exactly which calls are redirected, and on | |
103 which systems, and where the redirection occurs. | |
104 | |
105 Possibly we should use the new "qxe" convention. | |
106 */ | |
428 | 107 |
872 | 108 typedef RETSIGTYPE (XCDECL * signal_handler_t) (int); |
428 | 109 |
110 #if defined (HAVE_SIGPROCMASK) | |
111 | |
112 /* The POSIX way (sigaction, sigprocmask, sigpending, sigsuspend) */ | |
113 | |
613 | 114 signal_handler_t qxe_reliable_signal (int signal_number, |
115 signal_handler_t action); | |
116 | |
117 #define EMACS_SIGNAL qxe_reliable_signal | |
428 | 118 |
119 #define EMACS_BLOCK_SIGNAL(sig) do \ | |
120 { \ | |
121 sigset_t ES_mask; \ | |
122 sigemptyset (&ES_mask); \ | |
123 sigaddset (&ES_mask, sig); \ | |
124 sigprocmask (SIG_BLOCK, &ES_mask, NULL); \ | |
125 } while (0) | |
126 #define EMACS_UNBLOCK_SIGNAL(sig) do \ | |
127 { \ | |
128 sigset_t ES_mask; \ | |
129 sigemptyset (&ES_mask); \ | |
130 sigaddset (&ES_mask, sig); \ | |
131 sigprocmask (SIG_UNBLOCK, &ES_mask, NULL); \ | |
132 } while (0) | |
133 #define EMACS_UNBLOCK_ALL_SIGNALS() do \ | |
134 { \ | |
135 sigset_t ES_mask; \ | |
136 sigemptyset (&ES_mask); \ | |
137 sigprocmask (SIG_SETMASK, &ES_mask, NULL); \ | |
138 } while (0) | |
139 #define EMACS_WAIT_FOR_SIGNAL(sig) do \ | |
140 { \ | |
141 sigset_t ES_mask; \ | |
142 sigprocmask (0, NULL, &ES_mask); \ | |
143 sigdelset (&ES_mask, sig); \ | |
144 sigsuspend (&ES_mask); \ | |
145 } while (0) | |
146 #define EMACS_REESTABLISH_SIGNAL(sig, handler) | |
2286 | 147 #define SIG_ARG_MAYBE_UNUSED(decl) UNUSED (decl) |
428 | 148 |
149 #elif defined (HAVE_SIGBLOCK) | |
150 | |
151 /* The older BSD way (signal/sigvec, sigblock, sigsetmask, sigpause) */ | |
152 | |
153 /* It's OK to use signal() here directly. No unreliable signal | |
154 problems. However, we use sigvec() because it allows us to | |
155 request interruptible I/O. */ | |
156 | |
613 | 157 #define EMACS_SIGNAL qxe_reliable_signal |
428 | 158 |
159 /* Is it necessary to define sigmask like this? */ | |
160 #ifndef sigmask | |
161 # define sigmask(no) (1L << ((no) - 1)) | |
162 #endif | |
163 | |
164 #define EMACS_BLOCK_SIGNAL(sig) sigblock (sigmask (sig)) | |
165 #define EMACS_UNBLOCK_SIGNAL(sig) sigsetmask (sigblock (0) & ~sigmask (sig)) | |
166 #define EMACS_UNBLOCK_ALL_SIGNALS() sigsetmask (0) | |
167 #define EMACS_WAIT_FOR_SIGNAL(sig) do \ | |
168 { \ | |
169 int ES_mask = sigblock (0); \ | |
170 sigpause (ES_mask & ~sigmask (sig)); \ | |
171 } while (0) | |
172 #define EMACS_REESTABLISH_SIGNAL(sig, handler) | |
2286 | 173 #define SIG_ARG_MAYBE_UNUSED(decl) UNUSED (decl) |
428 | 174 |
175 #elif defined (HAVE_SIGHOLD) | |
176 | |
177 /* The older SYSV way (signal/sigset, sighold, sigrelse, sigignore, | |
178 sigpause) */ | |
179 | |
613 | 180 #define EMACS_SIGNAL sigset |
428 | 181 #define EMACS_BLOCK_SIGNAL(sig) sighold (sig) |
182 #define EMACS_UNBLOCK_SIGNAL(sig) sigrelse (sig) | |
183 /* #### There's not really any simple way to implement this. | |
184 Since EMACS_UNBLOCK_ALL_SIGNALS() is only called once (at startup), | |
185 it's probably OK to just ignore it. */ | |
186 #define EMACS_UNBLOCK_ALL_SIGNALS() 0 | |
187 #define EMACS_WAIT_FOR_SIGNAL(sig) sigpause (sig) | |
188 #define EMACS_REESTABLISH_SIGNAL(sig, handler) | |
2286 | 189 #define SIG_ARG_MAYBE_UNUSED(decl) UNUSED (decl) |
428 | 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) | |
2286 | 205 #define SIG_ARG_MAYBE_UNUSED(decl) UNUSED (decl) |
613 | 206 |
207 /* Defines that we need that aren't in the standard signal.h */ | |
208 #define SIGHUP 1 /* Hang up */ | |
209 #define SIGQUIT 3 /* Quit process */ | |
210 #define SIGKILL 9 /* Die, die die */ | |
211 #define SIGALRM 14 /* Alarm */ | |
212 #define SIGPROF 29 /* Profiling timer exp */ | |
213 | |
428 | 214 #else |
215 | |
216 /* The oldest SYSV way (signal only; unreliable signals) */ | |
217 | |
218 /* Old USG systems don't really have signal blocking. | |
219 We indicate this by not defining EMACS_BLOCK_SIGNAL or | |
220 EMACS_WAIT_FOR_SIGNAL. */ | |
613 | 221 #define EMACS_SIGNAL signal |
428 | 222 #define EMACS_UNBLOCK_SIGNAL(sig) 0 |
223 #define EMACS_UNBLOCK_ALL_SIGNALS() 0 | |
224 #define EMACS_REESTABLISH_SIGNAL(sig, handler) do \ | |
225 { \ | |
226 int old_errno = errno; \ | |
227 signal (sig, handler); \ | |
228 errno = old_errno; \ | |
229 } while (0) | |
2286 | 230 #define SIG_ARG_MAYBE_UNUSED(decl) decl |
428 | 231 |
232 /* Under SYSV, setting a signal handler for SIGCLD causes | |
233 SIGCLD to immediately be sent if there any unwaited processes | |
234 out there. This means that the SIGCLD handler *must* call | |
235 wait() to reap the status of all processes -- it cannot | |
236 simply set a flag and then reestablish the handler, because | |
237 it will get called again, infinitely. We only need to | |
238 worry about this on systems where signals need to be | |
239 reestablished (SYSV Release 2 and earlier). */ | |
240 #define OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR | |
241 | |
613 | 242 #endif /* different signalling methods */ |
428 | 243 |
244 /* On bsd, [man says] kill does not accept a negative number to kill a pgrp. | |
245 Must do that using the killpg call. */ | |
442 | 246 #ifdef HAVE_KILLPG |
247 #define EMACS_KILLPG(pid, signo) killpg (pid, signo) | |
814 | 248 #elif defined (WIN32_NATIVE) |
249 #define EMACS_KILLPG(pid, signo) should never be called | |
428 | 250 #else |
442 | 251 #define EMACS_KILLPG(pid, signo) kill (-(pid), signo) |
428 | 252 #endif |
253 | |
254 #ifndef NSIG | |
978 | 255 # ifdef USG5_4 |
256 /* Some SVr4s don't define NSIG in sys/signal.h for ANSI environments; | |
257 * instead, there's a system variable _sys_nsig. Unfortunately, we need the | |
258 * constant to dimension an array. So wire in the appropriate value here. | |
259 */ | |
260 # define NSIG 32 | |
261 # else | |
262 # define NSIG (SIGUSR2+1) /* guess how many elements are in sys_siglist... */ | |
263 # endif | |
428 | 264 #endif |
265 | |
2651 | 266 /* HAVE_DECL_SYS_SIGLIST is determined by configure. On Linux, it seems, |
428 | 267 configure incorrectly fails to find it, so s/linux.h defines |
268 HAVE_SYS_SIGLIST. */ | |
2655 | 269 #if (!defined(HAVE_DECL_SYS_SIGLIST) || !HAVE_DECL_SYS_SIGLIST ) && !defined (HAVE_SYS_SIGLIST) |
442 | 270 extern const char *sys_siglist[]; |
428 | 271 #endif |
272 | |
273 #ifdef SIGDANGER | |
274 SIGTYPE memory_warning_signal (int sig); | |
275 #endif | |
276 | |
613 | 277 #if defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS) |
442 | 278 typedef void (__cdecl *mswindows_sighandler) (int); |
613 | 279 |
280 /* Prototypes for signal functions, see win32.c */ | |
442 | 281 int mswindows_sighold (int nsig); |
282 int mswindows_sigrelse (int nsig); | |
283 int mswindows_sigpause (int nsig); | |
284 int mswindows_raise (int nsig); | |
613 | 285 mswindows_sighandler mswindows_sigset (int sig, mswindows_sighandler handler); |
286 | |
287 #endif /* defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS) */ | |
288 | |
289 signal_handler_t set_timeout_signal (int signal_number, | |
290 signal_handler_t action); | |
291 | |
428 | 292 |
440 | 293 #endif /* INCLUDED_syssignal_h_ */ |