Update FSF's address.
[bpt/emacs.git] / src / syssignal.h
CommitLineData
9ab9afa9 1/* syssignal.h - System-dependent definitions for signals.
68c45bf0 2 Copyright (C) 1993, 1999 Free Software Foundation, Inc.
9ab9afa9
JB
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
7c938215 8the Free Software Foundation; either version 2, or (at your option)
9ab9afa9
JB
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
4fc5845f
LK
18the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19Boston, MA 02110-1301, USA. */
9ab9afa9 20
2b98b088
TTN
21extern void init_signals P_ ((void));
22
333f1b6f
JD
23#ifdef HAVE_GTK_AND_PTHREAD
24#include <pthread.h>
25extern pthread_t main_thread;
26#endif
27
9ab9afa9 28#ifdef POSIX_SIGNALS
00eaaa32 29
c3aa5fec 30/* Don't #include <signal.h>. That header should always be #included
cf026b25
JB
31 before "config.h", because some configuration files (like s/hpux.h)
32 indicate that SIGIO doesn't work by #undef-ing SIGIO. If this file
33 #includes <signal.h>, then that will re-#define SIGIO and confuse
34 things. */
00eaaa32 35
9ab9afa9
JB
36#define SIGMASKTYPE sigset_t
37
38#define SIGEMPTYMASK (empty_mask)
39#define SIGFULLMASK (full_mask)
47b682b7 40extern sigset_t empty_mask, full_mask;
9ab9afa9 41
1b1f8f85 42/* POSIX pretty much destroys any possibility of writing sigmask as a
47b682b7
AS
43 macro in standard C. We always define our own version because the
44 predefined macro in Glibc 2.1 is only provided for compatility for old
45 programs that use int as signal mask type. */
46#undef sigmask
1b1f8f85
JB
47#ifdef __GNUC__
48#define sigmask(SIG) \
49 ({ \
50 sigset_t _mask; \
51 sigemptyset (&_mask); \
52 sigaddset (&_mask, SIG); \
53 _mask; \
54 })
985a35a3 55#else /* ! defined (__GNUC__) */
9bd67a37 56extern sigset_t sys_sigmask ();
1b1f8f85 57#define sigmask(SIG) (sys_sigmask (SIG))
985a35a3 58#endif /* ! defined (__GNUC__) */
1b1f8f85 59
47b682b7
AS
60#undef sigpause
61#define sigpause(MASK) sigsuspend (&(MASK))
9f910b50 62
69037d5a
RS
63#define sigblock(SIG) sys_sigblock (SIG)
64#define sigunblock(SIG) sys_sigunblock (SIG)
cc210d67 65#ifndef sigsetmask
69037d5a 66#define sigsetmask(SIG) sys_sigsetmask (SIG)
cc210d67 67#endif
9ab9afa9
JB
68#define sighold(SIG) ONLY_USED_IN_BSD_4_1
69#define sigrelse(SIG) ONLY_USED_IN_BSD_4_1
6c8a1e24 70#undef signal
9c063f29 71#define signal(SIG,ACT) sys_signal(SIG,ACT)
9ab9afa9 72
00eaaa32 73/* Whether this is what all systems want or not, this is what
69037d5a 74 appears to be assumed in the source, for example data.c:arith_error. */
667da7f5 75typedef RETSIGTYPE (*signal_handler_t) (/*int*/);
00eaaa32 76
030f4475
AS
77signal_handler_t sys_signal P_ ((int signal_number, signal_handler_t action));
78sigset_t sys_sigblock P_ ((sigset_t new_mask));
79sigset_t sys_sigunblock P_ ((sigset_t new_mask));
80sigset_t sys_sigsetmask P_ ((sigset_t new_mask));
9ab9afa9 81
69037d5a 82#define sys_sigdel(MASK,SIG) sigdelset (&MASK,SIG)
9ab9afa9 83
985a35a3
JB
84#else /* ! defined (POSIX_SIGNALS) */
85#ifdef USG5_4
86
094d2b0e
GM
87extern SIGMASKTYPE sigprocmask_set;
88
69037d5a 89#ifndef sigblock
094d2b0e
GM
90#define sigblock(sig) \
91 (sigprocmask_set = SIGEMPTYMASK | (sig), \
92 sigprocmask (SIG_BLOCK, &sigprocmask_set, NULL))
69037d5a
RS
93#endif
94
fe54008f 95#ifndef sigunblock
094d2b0e
GM
96#define sigunblock(sig) \
97 (sigprocmask_set = SIGFULLMASK & ~(sig), \
98 sigprocmask (SIG_SETMASK, &sigprocmask_set, NULL))
fe54008f 99#endif
985a35a3
JB
100
101#else
102#ifdef USG
103
fe54008f 104#ifndef sigunblock
177c0ea7 105#define sigunblock(sig)
fe54008f 106#endif
985a35a3
JB
107
108#else
9ab9afa9 109
fe54008f 110#ifndef sigunblock
9ab9afa9
JB
111#define sigunblock(SIG) \
112{ SIGMASKTYPE omask = sigblock (SIGEMPTYMASK); sigsetmask (omask & ~SIG); }
fe54008f 113#endif
9ab9afa9 114
985a35a3
JB
115#endif /* ! defined (USG) */
116#endif /* ! defined (USG5_4) */
117#endif /* ! defined (POSIX_SIGNALS) */
9ab9afa9
JB
118
119#ifndef SIGMASKTYPE
120#define SIGMASKTYPE int
121#endif
122
123#ifndef SIGEMPTYMASK
1b1f8f85
JB
124#define SIGEMPTYMASK (0)
125#endif
126
127#ifndef SIGFULLMASK
128#define SIGFULLMASK (0xffffffff)
9ab9afa9
JB
129#endif
130
131#ifndef sigmask
132#define sigmask(no) (1L << ((no) - 1))
133#endif
134
1b1f8f85
JB
135#ifndef sigunblock
136#define sigunblock(SIG) \
137{ SIGMASKTYPE omask = sigblock (SIGFULLMASK); sigsetmask (omask & ~SIG); }
138#endif
139
1b1f8f85
JB
140#ifndef BSD4_1
141#define sigfree() sigsetmask (SIGEMPTYMASK)
ea973b10 142#endif /* not BSD4_1 */
1b1f8f85 143
68c45bf0
PE
144#if defined (SIGINFO) && defined (BROKEN_SIGINFO)
145#undef SIGINFO
146#endif
147#if defined (SIGIO) && defined (BROKEN_SIGIO)
148#undef SIGIO
149#endif
150#if defined (SIGPOLL) && defined (BROKEN_SIGPOLL)
151#undef SIGPOLL
152#endif
153#if defined (SIGTSTP) && defined (BROKEN_SIGTSTP)
154#undef SIGTSTP
155#endif
156#if defined (SIGURG) && defined (BROKEN_SIGURG)
157#undef SIGURG
158#endif
4e677396
KH
159#if defined (SIGAIO) && defined (BROKEN_SIGAIO)
160#undef SIGAIO
161#endif
162#if defined (SIGPTY) && defined (BROKEN_SIGPTY)
163#undef SIGPTY
164#endif
165
68c45bf0
PE
166
167#if NSIG < NSIG_MINIMUM
168# ifdef NSIG
169# undef NSIG
170# endif
171# define NSIG NSIG_MINIMUM
172#endif
173
9ab9afa9
JB
174#ifdef BSD4_1
175#define SIGIO SIGTINT
645280b7 176/* sigfree is in sysdep.c */
ea973b10 177#endif /* BSD4_1 */
9ab9afa9
JB
178
179/* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
180 Must do that using the killpg call. */
6df54671 181#ifdef BSD_SYSTEM
9ab9afa9
JB
182#define EMACS_KILLPG(gid, signo) (killpg ( (gid), (signo)))
183#else
57d65592 184#ifdef WINDOWSNT
f405affb 185#define EMACS_KILLPG(gid, signo) (kill (gid, signo))
57d65592 186#else
9ab9afa9
JB
187#define EMACS_KILLPG(gid, signo) (kill (-(gid), (signo)))
188#endif
57d65592 189#endif
9ab9afa9
JB
190
191/* Define SIGCHLD as an alias for SIGCLD. There are many conditionals
192 testing SIGCHLD. */
9ab9afa9
JB
193#ifndef VMS
194#ifdef SIGCLD
195#ifndef SIGCHLD
196#define SIGCHLD SIGCLD
985a35a3
JB
197#endif /* SIGCHLD */
198#endif /* ! defined (SIGCLD) */
199#endif /* VMS */
68c45bf0
PE
200
201#ifndef HAVE_STRSIGNAL
202/* strsignal is in sysdep.c */
203char *strsignal ();
204#endif
ab5796a9 205
333f1b6f
JD
206#ifdef HAVE_GTK_AND_PTHREAD
207#define SIGNAL_THREAD_CHECK(signo) \
208 do { \
209 if (pthread_self () != main_thread) \
210 { \
211 /* POSIX says any thread can receive the signal. On GNU/Linux \
212 that is not true, but for other systems (FreeBSD at least) \
213 it is. So direct the signal to the correct thread and block \
214 it from this thread. */ \
215 sigset_t new_mask; \
216 \
217 sigemptyset (&new_mask); \
218 sigaddset (&new_mask, signo); \
219 pthread_sigmask (SIG_BLOCK, &new_mask, 0); \
220 pthread_kill (main_thread, signo); \
221 return; \
222 } \
223 } while (0)
224
225#else /* not HAVE_GTK_AND_PTHREAD */
226#define SIGNAL_THREAD_CHECK(signo)
227#endif /* not HAVE_GTK_AND_PTHREAD */
ab5796a9
MB
228/* arch-tag: 4580e86a-340d-4574-9e11-a742b6e1a152
229 (do not change this comment) */