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)
+ − 151
+ − 152 #elif defined (HAVE_SIGBLOCK)
+ − 153
+ − 154 /* The older BSD way (signal/sigvec, sigblock, sigsetmask, sigpause) */
+ − 155
+ − 156 /* It's OK to use signal() here directly. No unreliable signal
+ − 157 problems. However, we use sigvec() because it allows us to
+ − 158 request interruptible I/O. */
+ − 159
613
+ − 160 #define EMACS_SIGNAL qxe_reliable_signal
428
+ − 161
+ − 162 /* Is it necessary to define sigmask like this? */
+ − 163 #ifndef sigmask
+ − 164 # define sigmask(no) (1L << ((no) - 1))
+ − 165 #endif
+ − 166
+ − 167 #define EMACS_BLOCK_SIGNAL(sig) sigblock (sigmask (sig))
+ − 168 #define EMACS_UNBLOCK_SIGNAL(sig) sigsetmask (sigblock (0) & ~sigmask (sig))
+ − 169 #define EMACS_UNBLOCK_ALL_SIGNALS() sigsetmask (0)
+ − 170 #define EMACS_WAIT_FOR_SIGNAL(sig) do \
+ − 171 { \
+ − 172 int ES_mask = sigblock (0); \
+ − 173 sigpause (ES_mask & ~sigmask (sig)); \
+ − 174 } while (0)
+ − 175 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
+ − 176
+ − 177 #elif defined (HAVE_SIGHOLD)
+ − 178
+ − 179 /* The older SYSV way (signal/sigset, sighold, sigrelse, sigignore,
+ − 180 sigpause) */
+ − 181
613
+ − 182 #define EMACS_SIGNAL sigset
428
+ − 183 #define EMACS_BLOCK_SIGNAL(sig) sighold (sig)
+ − 184 #define EMACS_UNBLOCK_SIGNAL(sig) sigrelse (sig)
+ − 185 /* #### There's not really any simple way to implement this.
+ − 186 Since EMACS_UNBLOCK_ALL_SIGNALS() is only called once (at startup),
+ − 187 it's probably OK to just ignore it. */
+ − 188 #define EMACS_UNBLOCK_ALL_SIGNALS() 0
+ − 189 #define EMACS_WAIT_FOR_SIGNAL(sig) sigpause (sig)
+ − 190 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
+ − 191
613
+ − 192 #elif defined (WIN32_NATIVE)
+ − 193
+ − 194 /* MS Windows signal emulation (in turns emulates the sigset/sighold
+ − 195 paradigm) */
+ − 196
+ − 197 #define EMACS_SIGNAL mswindows_sigset
+ − 198 #define EMACS_BLOCK_SIGNAL(sig) mswindows_sighold (sig)
+ − 199 #define EMACS_UNBLOCK_SIGNAL(sig) mswindows_sigrelse (sig)
+ − 200 /* #### There's not really any simple way to implement this.
+ − 201 Since EMACS_UNBLOCK_ALL_SIGNALS() is only called once (at startup),
+ − 202 it's probably OK to just ignore it. */
+ − 203 #define EMACS_UNBLOCK_ALL_SIGNALS() 0
+ − 204 #define EMACS_WAIT_FOR_SIGNAL(sig) mswindows_sigpause (sig)
+ − 205 #define EMACS_REESTABLISH_SIGNAL(sig, handler)
+ − 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)
+ − 230
+ − 231 /* Under SYSV, setting a signal handler for SIGCLD causes
+ − 232 SIGCLD to immediately be sent if there any unwaited processes
+ − 233 out there. This means that the SIGCLD handler *must* call
+ − 234 wait() to reap the status of all processes -- it cannot
+ − 235 simply set a flag and then reestablish the handler, because
+ − 236 it will get called again, infinitely. We only need to
+ − 237 worry about this on systems where signals need to be
+ − 238 reestablished (SYSV Release 2 and earlier). */
+ − 239 #define OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
+ − 240
613
+ − 241 #endif /* different signalling methods */
428
+ − 242
+ − 243 /* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
+ − 244 Must do that using the killpg call. */
442
+ − 245 #ifdef HAVE_KILLPG
+ − 246 #define EMACS_KILLPG(pid, signo) killpg (pid, signo)
814
+ − 247 #elif defined (WIN32_NATIVE)
+ − 248 #define EMACS_KILLPG(pid, signo) should never be called
428
+ − 249 #else
442
+ − 250 #define EMACS_KILLPG(pid, signo) kill (-(pid), signo)
428
+ − 251 #endif
+ − 252
+ − 253 #ifndef NSIG
978
+ − 254 # ifdef USG5_4
+ − 255 /* Some SVr4s don't define NSIG in sys/signal.h for ANSI environments;
+ − 256 * instead, there's a system variable _sys_nsig. Unfortunately, we need the
+ − 257 * constant to dimension an array. So wire in the appropriate value here.
+ − 258 */
+ − 259 # define NSIG 32
+ − 260 # else
+ − 261 # define NSIG (SIGUSR2+1) /* guess how many elements are in sys_siglist... */
+ − 262 # endif
428
+ − 263 #endif
+ − 264
+ − 265 /* SYS_SIGLIST_DECLARED is determined by configure. On Linux, it seems,
+ − 266 configure incorrectly fails to find it, so s/linux.h defines
+ − 267 HAVE_SYS_SIGLIST. */
+ − 268 #if !defined (SYS_SIGLIST_DECLARED) && !defined (HAVE_SYS_SIGLIST)
442
+ − 269 extern const char *sys_siglist[];
428
+ − 270 #endif
+ − 271
+ − 272 #ifdef SIGDANGER
+ − 273 SIGTYPE memory_warning_signal (int sig);
+ − 274 #endif
+ − 275
613
+ − 276 #if defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS)
442
+ − 277 typedef void (__cdecl *mswindows_sighandler) (int);
613
+ − 278
+ − 279 /* Prototypes for signal functions, see win32.c */
442
+ − 280 int mswindows_sighold (int nsig);
+ − 281 int mswindows_sigrelse (int nsig);
+ − 282 int mswindows_sigpause (int nsig);
+ − 283 int mswindows_raise (int nsig);
613
+ − 284 mswindows_sighandler mswindows_sigset (int sig, mswindows_sighandler handler);
+ − 285
+ − 286 #endif /* defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS) */
+ − 287
+ − 288 signal_handler_t set_timeout_signal (int signal_number,
+ − 289 signal_handler_t action);
+ − 290
428
+ − 291
440
+ − 292 #endif /* INCLUDED_syssignal_h_ */