Mercurial > hg > xemacs-beta
comparison src/syssignal.h @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | 4b173ad71786 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
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 | |
23 #ifndef _XEMACS_SYSSIGNAL_H_ | |
24 #define _XEMACS_SYSSIGNAL_H_ | |
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 (SIGIO) && defined (SIGPOLL) | |
52 # define SIGIO SIGPOLL | |
53 #endif | |
54 | |
55 #if defined (BROKEN_SIGIO) | |
56 # undef SIGIO | |
57 #endif | |
58 | |
59 /* Define SIGCHLD as an alias for SIGCLD. There are many conditionals | |
60 testing SIGCHLD. */ | |
61 #if !defined (VMS) && defined (SIGCLD) && !defined (SIGCHLD) | |
62 # define SIGCHLD SIGCLD | |
63 #endif /* SIGCHLD */ | |
64 | |
65 #ifdef BROKEN_SIGCHLD | |
66 #undef SIGCHLD | |
67 #endif | |
68 | |
69 #ifdef SIGCHLD | |
70 #define EMACS_BLOCK_SIGCHLD EMACS_BLOCK_SIGNAL (SIGCHLD) | |
71 #define EMACS_UNBLOCK_SIGCHLD EMACS_UNBLOCK_SIGNAL (SIGCHLD) | |
72 #else | |
73 #define EMACS_BLOCK_SIGCHLD | |
74 #define EMACS_UNBLOCK_SIGCHLD | |
75 #endif | |
76 | |
77 /* According to W.R. Stevens __Advanced Programming in the Unix | |
78 Environment__, there are four different paradigms for handling | |
79 signals. We use autoconf to tell us which one applies. | |
80 | |
81 Note that on some systems, more than one paradigm is implemented | |
82 (typically, the POSIX sigaction/sigprocmask and either the older | |
83 SYSV or BSD way). In such a case, we prefer the POSIX way. | |
84 | |
85 NOTE: We use EMACS_* macros for most signal operations, but | |
86 just signal() for the standard signal-setting operation. | |
87 Perhaps we should change this to EMACS_SIGNAL(), but that runs | |
88 the risk of someone forgetting this convention and calling | |
89 signal() directly. */ | |
90 | |
91 #if defined (HAVE_SIGPROCMASK) | |
92 | |
93 /* The POSIX way (sigaction, sigprocmask, sigpending, sigsuspend) */ | |
94 | |
95 typedef SIGTYPE (*signal_handler_t) (int); | |
96 extern signal_handler_t sys_do_signal (int signal_number, | |
97 signal_handler_t action); | |
98 /* Provide our own version of signal(), that calls sigaction(). The | |
99 name is not sys_signal() because a function of that name exists in | |
100 libenergize.a */ | |
101 #undef signal | |
102 #define signal sys_do_signal | |
103 | |
104 #define EMACS_BLOCK_SIGNAL(sig) do \ | |
105 { \ | |
106 sigset_t _mask; \ | |
107 sigemptyset (&_mask); \ | |
108 sigaddset (&_mask, sig); \ | |
109 sigprocmask (SIG_BLOCK, &_mask, NULL); \ | |
110 } while (0) | |
111 #define EMACS_UNBLOCK_SIGNAL(sig) do \ | |
112 { \ | |
113 sigset_t _mask; \ | |
114 sigemptyset (&_mask); \ | |
115 sigaddset (&_mask, sig); \ | |
116 sigprocmask (SIG_UNBLOCK, &_mask, NULL); \ | |
117 } while (0) | |
118 #define EMACS_UNBLOCK_ALL_SIGNALS() do \ | |
119 { \ | |
120 sigset_t _mask; \ | |
121 sigemptyset (&_mask); \ | |
122 sigprocmask (SIG_SETMASK, &_mask, NULL); \ | |
123 } while (0) | |
124 #define EMACS_WAIT_FOR_SIGNAL(sig) do \ | |
125 { \ | |
126 sigset_t _mask; \ | |
127 sigprocmask (0, NULL, &_mask); \ | |
128 sigdelset (&_mask, sig); \ | |
129 sigsuspend (&_mask); \ | |
130 } while (0) | |
131 #define EMACS_REESTABLISH_SIGNAL(sig, handler) | |
132 | |
133 #elif defined (HAVE_SIGBLOCK) | |
134 | |
135 /* The older BSD way (signal/sigvec, sigblock, sigsetmask, sigpause) */ | |
136 | |
137 /* It's OK to use signal() here directly. No unreliable signal | |
138 problems. However, we use sigvec() because it allows us to | |
139 request interruptible I/O. */ | |
140 | |
141 #define signal sys_do_signal | |
142 | |
143 /* Is it necessary to define sigmask like this? */ | |
144 #ifndef sigmask | |
145 # define sigmask(no) (1L << ((no) - 1)) | |
146 #endif | |
147 | |
148 #define EMACS_BLOCK_SIGNAL(sig) sigblock (sigmask (sig)) | |
149 #define EMACS_UNBLOCK_SIGNAL(sig) sigsetmask (sigblock (0) & ~sigmask (sig)) | |
150 #define EMACS_UNBLOCK_ALL_SIGNALS() sigsetmask (0) | |
151 #define EMACS_WAIT_FOR_SIGNAL(sig) do \ | |
152 { \ | |
153 int _mask = sigblock (0); \ | |
154 sigpause (_mask & ~sigmask (sig)); \ | |
155 } while (0) | |
156 #define EMACS_REESTABLISH_SIGNAL(sig, handler) | |
157 | |
158 #elif defined (HAVE_SIGHOLD) | |
159 | |
160 /* The older SYSV way (signal/sigset, sighold, sigrelse, sigignore, | |
161 sigpause) */ | |
162 | |
163 #define signal sigset | |
164 #define EMACS_BLOCK_SIGNAL(sig) sighold (sig) | |
165 #define EMACS_UNBLOCK_SIGNAL(sig) sigrelse (sig) | |
166 /* #### There's not really any simple way to implement this. | |
167 Since EMACS_UNBLOCK_ALL_SIGNALS() is only called once (at startup), | |
168 it's probably OK to just ignore it. */ | |
169 #define EMACS_UNBLOCK_ALL_SIGNALS() 0 | |
170 #define EMACS_WAIT_FOR_SIGNAL(sig) sigpause (sig) | |
171 #define EMACS_REESTABLISH_SIGNAL(sig, handler) | |
172 | |
173 #else | |
174 | |
175 /* The oldest SYSV way (signal only; unreliable signals) */ | |
176 | |
177 /* Old USG systems don't really have signal blocking. | |
178 We indicate this by not defining EMACS_BLOCK_SIGNAL or | |
179 EMACS_WAIT_FOR_SIGNAL. */ | |
180 #define EMACS_UNBLOCK_SIGNAL(sig) 0 | |
181 #define EMACS_UNBLOCK_ALL_SIGNALS() 0 | |
182 #define EMACS_REESTABLISH_SIGNAL(sig, handler) do \ | |
183 { \ | |
184 int old_errno = errno; \ | |
185 signal (sig, handler); \ | |
186 errno = old_errno; \ | |
187 } while (0) | |
188 | |
189 /* Under SYSV, setting a signal handler for SIGCLD causes | |
190 SIGCLD to immediately be sent if there any unwaited processes | |
191 out there. This means that the SIGCLD handler *must* call | |
192 wait() to reap the status of all processes -- it cannot | |
193 simply set a flag and then reestablish the handler, because | |
194 it will get called again, infinitely. We only need to | |
195 worry about this on systems where signals need to be | |
196 reestablished (SYSV Release 2 and earlier). */ | |
197 #define OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR | |
198 | |
199 #endif | |
200 | |
201 /* On bsd, [man says] kill does not accept a negative number to kill a pgrp. | |
202 Must do that using the killpg call. */ | |
203 #ifdef BSD | |
204 #define EMACS_KILLPG(gid, signo) killpg (gid, signo) | |
205 #else | |
206 #ifdef WINDOWSNT | |
207 #define EMACS_KILLPG(gid, signo) (win32_kill_process (gid, signo)) | |
208 #else | |
209 #define EMACS_KILLPG(gid, signo) kill (-(gid), signo) | |
210 #endif | |
211 #endif | |
212 | |
213 #ifdef VMS | |
214 # define sys_siglist sys_errlist | |
215 # define NSIG sys_nerr | |
216 #endif /* VMS */ | |
217 | |
218 #ifndef NSIG | |
219 # define NSIG (SIGUSR2+1) /* guess how many elements are in sys_siglist... */ | |
220 #endif | |
221 | |
222 /* SYS_SIGLIST_DECLARED is determined by configure. On Linux, it seems, | |
223 configure incorrectly fails to find it, so s/linux.h defines | |
224 HAVE_SYS_SIGLIST. */ | |
225 #if !defined (SYS_SIGLIST_DECLARED) && !defined (HAVE_SYS_SIGLIST) | |
226 extern CONST char *sys_siglist[]; | |
227 #endif | |
228 | |
229 #ifdef SIGDANGER | |
230 extern SIGTYPE memory_warning_signal (int sig); | |
231 #endif | |
232 | |
233 #endif /* _XEMACS_SYSSIGNAL_H_ */ |