Add 2012 to FSF copyright years for Emacs files
[bpt/emacs.git] / src / syssignal.h
CommitLineData
9ab9afa9 1/* syssignal.h - System-dependent definitions for signals.
acaf905b 2 Copyright (C) 1993, 1999, 2001-2012 Free Software Foundation, Inc.
9ab9afa9
JB
3
4This file is part of GNU Emacs.
5
b9b1cc14 6GNU Emacs is free software: you can redistribute it and/or modify
9ab9afa9 7it under the terms of the GNU General Public License as published by
b9b1cc14
GM
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
9ab9afa9
JB
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
b9b1cc14 17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
9ab9afa9 18
383e0970 19extern void init_signals (void);
2b98b088 20
ae9e757a 21#ifdef HAVE_PTHREAD
333f1b6f 22#include <pthread.h>
f8240abd
YM
23/* If defined, asynchronous signals delivered to a non-main thread are
24 forwarded to the main thread. */
25#define FORWARD_SIGNAL_TO_MAIN_THREAD
26#endif
27
c3aa5fec 28/* Don't #include <signal.h>. That header should always be #included
cf026b25
JB
29 before "config.h", because some configuration files (like s/hpux.h)
30 indicate that SIGIO doesn't work by #undef-ing SIGIO. If this file
31 #includes <signal.h>, then that will re-#define SIGIO and confuse
32 things. */
4d553a13 33/* XXX This is not correct anymore, there is a BROKEN_SIGIO macro. */
00eaaa32 34
9ab9afa9
JB
35#define SIGMASKTYPE sigset_t
36
37#define SIGEMPTYMASK (empty_mask)
1fa53021 38extern sigset_t empty_mask;
9ab9afa9 39
1b1f8f85 40/* POSIX pretty much destroys any possibility of writing sigmask as a
47b682b7 41 macro in standard C. We always define our own version because the
da6062e6 42 predefined macro in Glibc 2.1 is only provided for compatibility for old
47b682b7
AS
43 programs that use int as signal mask type. */
44#undef sigmask
1b1f8f85
JB
45#ifdef __GNUC__
46#define sigmask(SIG) \
47 ({ \
48 sigset_t _mask; \
49 sigemptyset (&_mask); \
50 sigaddset (&_mask, SIG); \
51 _mask; \
52 })
985a35a3 53#else /* ! defined (__GNUC__) */
9bd67a37 54extern sigset_t sys_sigmask ();
1b1f8f85 55#define sigmask(SIG) (sys_sigmask (SIG))
985a35a3 56#endif /* ! defined (__GNUC__) */
1b1f8f85 57
47b682b7
AS
58#undef sigpause
59#define sigpause(MASK) sigsuspend (&(MASK))
9f910b50 60
69037d5a
RS
61#define sigblock(SIG) sys_sigblock (SIG)
62#define sigunblock(SIG) sys_sigunblock (SIG)
cc210d67 63#ifndef sigsetmask
69037d5a 64#define sigsetmask(SIG) sys_sigsetmask (SIG)
cc210d67 65#endif
6c8a1e24 66#undef signal
9c063f29 67#define signal(SIG,ACT) sys_signal(SIG,ACT)
9ab9afa9 68
ae877222
DN
69/* Whether this is what all systems want or not, this is what
70 appears to be assumed in the source, for example data.c:arith_error. */
9af30bdf 71typedef void (*signal_handler_t) (int);
ae877222 72
383e0970
J
73signal_handler_t sys_signal (int signal_number, signal_handler_t action);
74sigset_t sys_sigblock (sigset_t new_mask);
75sigset_t sys_sigunblock (sigset_t new_mask);
76sigset_t sys_sigsetmask (sigset_t new_mask);
5d4cb038 77#if ! (defined TIOCNOTTY || defined USG5 || defined CYGWIN)
adddb265 78void croak (char *) NO_RETURN;
5d4cb038 79#endif
9ab9afa9 80
69037d5a 81#define sys_sigdel(MASK,SIG) sigdelset (&MASK,SIG)
9ab9afa9 82
1b1f8f85 83#define sigfree() sigsetmask (SIGEMPTYMASK)
1b1f8f85 84
68c45bf0
PE
85#if defined (SIGINFO) && defined (BROKEN_SIGINFO)
86#undef SIGINFO
87#endif
88#if defined (SIGIO) && defined (BROKEN_SIGIO)
098767d9 89# undef SIGIO
68c45bf0
PE
90#endif
91#if defined (SIGPOLL) && defined (BROKEN_SIGPOLL)
92#undef SIGPOLL
93#endif
94#if defined (SIGTSTP) && defined (BROKEN_SIGTSTP)
95#undef SIGTSTP
96#endif
97#if defined (SIGURG) && defined (BROKEN_SIGURG)
98#undef SIGURG
99#endif
4e677396
KH
100#if defined (SIGAIO) && defined (BROKEN_SIGAIO)
101#undef SIGAIO
102#endif
103#if defined (SIGPTY) && defined (BROKEN_SIGPTY)
104#undef SIGPTY
105#endif
106
68c45bf0
PE
107
108#if NSIG < NSIG_MINIMUM
109# ifdef NSIG
110# undef NSIG
111# endif
112# define NSIG NSIG_MINIMUM
113#endif
114
9ab9afa9
JB
115/* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
116 Must do that using the killpg call. */
6df54671 117#ifdef BSD_SYSTEM
9ab9afa9
JB
118#define EMACS_KILLPG(gid, signo) (killpg ( (gid), (signo)))
119#else
57d65592 120#ifdef WINDOWSNT
f405affb 121#define EMACS_KILLPG(gid, signo) (kill (gid, signo))
57d65592 122#else
9ab9afa9
JB
123#define EMACS_KILLPG(gid, signo) (kill (-(gid), (signo)))
124#endif
57d65592 125#endif
9ab9afa9
JB
126
127/* Define SIGCHLD as an alias for SIGCLD. There are many conditionals
128 testing SIGCHLD. */
9ab9afa9
JB
129#ifdef SIGCLD
130#ifndef SIGCHLD
131#define SIGCHLD SIGCLD
985a35a3
JB
132#endif /* SIGCHLD */
133#endif /* ! defined (SIGCLD) */
68c45bf0
PE
134
135#ifndef HAVE_STRSIGNAL
136/* strsignal is in sysdep.c */
361358ea 137char *strsignal (int);
68c45bf0 138#endif
ab5796a9 139
f8240abd 140#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
dff94ed5 141extern pthread_t main_thread;
333f1b6f
JD
142#define SIGNAL_THREAD_CHECK(signo) \
143 do { \
3fb8b536 144 if (!pthread_equal (pthread_self (), main_thread)) \
333f1b6f
JD
145 { \
146 /* POSIX says any thread can receive the signal. On GNU/Linux \
147 that is not true, but for other systems (FreeBSD at least) \
148 it is. So direct the signal to the correct thread and block \
149 it from this thread. */ \
150 sigset_t new_mask; \
151 \
152 sigemptyset (&new_mask); \
153 sigaddset (&new_mask, signo); \
154 pthread_sigmask (SIG_BLOCK, &new_mask, 0); \
155 pthread_kill (main_thread, signo); \
156 return; \
157 } \
158 } while (0)
159
f8240abd 160#else /* not FORWARD_SIGNAL_TO_MAIN_THREAD */
333f1b6f 161#define SIGNAL_THREAD_CHECK(signo)
f8240abd 162#endif /* not FORWARD_SIGNAL_TO_MAIN_THREAD */