0
|
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
|
74
|
91 typedef SIGTYPE (*signal_handler_t) (int);
|
|
92
|
0
|
93 #if defined (HAVE_SIGPROCMASK)
|
|
94
|
|
95 /* The POSIX way (sigaction, sigprocmask, sigpending, sigsuspend) */
|
|
96
|
|
97 extern signal_handler_t sys_do_signal (int signal_number,
|
|
98 signal_handler_t action);
|
|
99 /* Provide our own version of signal(), that calls sigaction(). The
|
|
100 name is not sys_signal() because a function of that name exists in
|
|
101 libenergize.a */
|
|
102 #undef signal
|
|
103 #define signal sys_do_signal
|
|
104
|
|
105 #define EMACS_BLOCK_SIGNAL(sig) do \
|
|
106 { \
|
|
107 sigset_t _mask; \
|
|
108 sigemptyset (&_mask); \
|
|
109 sigaddset (&_mask, sig); \
|
|
110 sigprocmask (SIG_BLOCK, &_mask, NULL); \
|
|
111 } while (0)
|
|
112 #define EMACS_UNBLOCK_SIGNAL(sig) do \
|
|
113 { \
|
|
114 sigset_t _mask; \
|
|
115 sigemptyset (&_mask); \
|
|
116 sigaddset (&_mask, sig); \
|
|
117 sigprocmask (SIG_UNBLOCK, &_mask, NULL); \
|
|
118 } while (0)
|
|
119 #define EMACS_UNBLOCK_ALL_SIGNALS() do \
|
|
120 { \
|
|
121 sigset_t _mask; \
|
|
122 sigemptyset (&_mask); \
|
|
123 sigprocmask (SIG_SETMASK, &_mask, NULL); \
|
|
124 } while (0)
|
|
125 #define EMACS_WAIT_FOR_SIGNAL(sig) do \
|
|
126 { \
|
|
127 sigset_t _mask; \
|
|
128 sigprocmask (0, NULL, &_mask); \
|
|
129 sigdelset (&_mask, sig); \
|
|
130 sigsuspend (&_mask); \
|
|
131 } while (0)
|
|
132 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
|
|
133
|
|
134 #elif defined (HAVE_SIGBLOCK)
|
|
135
|
|
136 /* The older BSD way (signal/sigvec, sigblock, sigsetmask, sigpause) */
|
|
137
|
|
138 /* It's OK to use signal() here directly. No unreliable signal
|
|
139 problems. However, we use sigvec() because it allows us to
|
|
140 request interruptible I/O. */
|
|
141
|
|
142 #define signal sys_do_signal
|
|
143
|
|
144 /* Is it necessary to define sigmask like this? */
|
|
145 #ifndef sigmask
|
|
146 # define sigmask(no) (1L << ((no) - 1))
|
|
147 #endif
|
|
148
|
|
149 #define EMACS_BLOCK_SIGNAL(sig) sigblock (sigmask (sig))
|
|
150 #define EMACS_UNBLOCK_SIGNAL(sig) sigsetmask (sigblock (0) & ~sigmask (sig))
|
|
151 #define EMACS_UNBLOCK_ALL_SIGNALS() sigsetmask (0)
|
|
152 #define EMACS_WAIT_FOR_SIGNAL(sig) do \
|
|
153 { \
|
|
154 int _mask = sigblock (0); \
|
|
155 sigpause (_mask & ~sigmask (sig)); \
|
|
156 } while (0)
|
|
157 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
|
|
158
|
|
159 #elif defined (HAVE_SIGHOLD)
|
|
160
|
|
161 /* The older SYSV way (signal/sigset, sighold, sigrelse, sigignore,
|
|
162 sigpause) */
|
|
163
|
|
164 #define signal sigset
|
|
165 #define EMACS_BLOCK_SIGNAL(sig) sighold (sig)
|
|
166 #define EMACS_UNBLOCK_SIGNAL(sig) sigrelse (sig)
|
|
167 /* #### There's not really any simple way to implement this.
|
|
168 Since EMACS_UNBLOCK_ALL_SIGNALS() is only called once (at startup),
|
|
169 it's probably OK to just ignore it. */
|
|
170 #define EMACS_UNBLOCK_ALL_SIGNALS() 0
|
|
171 #define EMACS_WAIT_FOR_SIGNAL(sig) sigpause (sig)
|
|
172 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
|
|
173
|
|
174 #else
|
|
175
|
|
176 /* The oldest SYSV way (signal only; unreliable signals) */
|
|
177
|
|
178 /* Old USG systems don't really have signal blocking.
|
|
179 We indicate this by not defining EMACS_BLOCK_SIGNAL or
|
|
180 EMACS_WAIT_FOR_SIGNAL. */
|
|
181 #define EMACS_UNBLOCK_SIGNAL(sig) 0
|
|
182 #define EMACS_UNBLOCK_ALL_SIGNALS() 0
|
|
183 #define EMACS_REESTABLISH_SIGNAL(sig, handler) do \
|
|
184 { \
|
|
185 int old_errno = errno; \
|
|
186 signal (sig, handler); \
|
|
187 errno = old_errno; \
|
|
188 } while (0)
|
|
189
|
|
190 /* Under SYSV, setting a signal handler for SIGCLD causes
|
|
191 SIGCLD to immediately be sent if there any unwaited processes
|
|
192 out there. This means that the SIGCLD handler *must* call
|
|
193 wait() to reap the status of all processes -- it cannot
|
|
194 simply set a flag and then reestablish the handler, because
|
|
195 it will get called again, infinitely. We only need to
|
|
196 worry about this on systems where signals need to be
|
|
197 reestablished (SYSV Release 2 and earlier). */
|
|
198 #define OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
|
|
199
|
|
200 #endif
|
|
201
|
|
202 /* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
|
|
203 Must do that using the killpg call. */
|
|
204 #ifdef BSD
|
|
205 #define EMACS_KILLPG(gid, signo) killpg (gid, signo)
|
|
206 #else
|
|
207 #ifdef WINDOWSNT
|
|
208 #define EMACS_KILLPG(gid, signo) (win32_kill_process (gid, signo))
|
|
209 #else
|
|
210 #define EMACS_KILLPG(gid, signo) kill (-(gid), signo)
|
|
211 #endif
|
|
212 #endif
|
|
213
|
|
214 #ifdef VMS
|
|
215 # define sys_siglist sys_errlist
|
|
216 # define NSIG sys_nerr
|
|
217 #endif /* VMS */
|
|
218
|
|
219 #ifndef NSIG
|
|
220 # define NSIG (SIGUSR2+1) /* guess how many elements are in sys_siglist... */
|
|
221 #endif
|
|
222
|
|
223 /* SYS_SIGLIST_DECLARED is determined by configure. On Linux, it seems,
|
|
224 configure incorrectly fails to find it, so s/linux.h defines
|
|
225 HAVE_SYS_SIGLIST. */
|
|
226 #if !defined (SYS_SIGLIST_DECLARED) && !defined (HAVE_SYS_SIGLIST)
|
|
227 extern CONST char *sys_siglist[];
|
|
228 #endif
|
|
229
|
|
230 #ifdef SIGDANGER
|
|
231 extern SIGTYPE memory_warning_signal (int sig);
|
|
232 #endif
|
|
233
|
|
234 #endif /* _XEMACS_SYSSIGNAL_H_ */
|