diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2012-09-06 18:27:44 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2012-09-06 18:27:44 -0700 |
commit | 2fe282993cf9c84f5be424dc93d03f9705a7edd8 (patch) | |
tree | 229edb6fe29e66984b2992f3f9fa081cd7fe8920 /src/syssignal.h | |
parent | 845ce106c0ab157e25416964330875ad6c24b699 (diff) | |
download | emacs-2fe282993cf9c84f5be424dc93d03f9705a7edd8.tar.gz |
Signal-handler cleanup.
Emacs's signal handlers were written in the old 4.2BSD style with
sigblock and sigmask and so forth, and this led to some
inefficiencies and confusion. Rewrite these to use
pthread_sigmask etc. without copying signal sets around. Also,
get rid of the confusing macros 'SIGNAL_THREAD_CHECK' and
'signal', and instead use functions that do not attempt to take
over the system name space. This patch causes Emacs's text
segment to shrink by 0.7% on my platform, Fedora 17 x86-64.
* configure.ac (PTY_OPEN, PTY_TTY_NAME_SPRINTF):
Adjust to syssignal.h changes.
(SIGNAL_H_AB): Remove; no longer needed.
* src/alloc.c, src/emacsgtkfixed.c, src/nsfns.m, src/widget.c, src/xmenu.c:
Do not include <signal.h> or "syssignal.h", as these
modules do not use signals.
* src/atimer.c, src/callproc.c, src/data.c, src/dispnew.c, src/emacs.c:
* src/floatfns.c, src/gtkutil.c, src/keyboard.c, src/process.c, src/sound.c:
* src/sysdep.c, src/term.c, src/xterm.c:
Do not include <signal.h>, as "syssignal.h" does that for us now.
* src/atimer.c (sigmask_atimers): New function.
(block_atimers, unblock_atimers): New functions,
replacing the old macros BLOCK_ATIMERS and UNBLOCK_ATIMERS.
All uses replaced.
* src/conf_post.h [SIGNAL_H_AHB]: Do not include <signal.h>;
no longer needed here.
* src/emacs.c (main): Inspect existing signal handler with sigaction,
so that there's no need to block and unblock SIGHUP.
* src/sysdep.c (struct save_signal): New member 'action', replacing
old member 'handler'.
(save_signal_handlers, restore_signal_handlers):
Use sigaction instead of 'signal' to save and restore.
(get_set_sighandler, set_sighandler) [!WINDOWSNT]:
New function. All users of 'signal' modified to use set_sighandler
if they're writeonly, and to use sys_signal if they're read+write.
(emacs_sigaction_init, forwarded_signal): New functions.
(sys_signal): Remove. All uses replaced by calls to sigaction
and emacs_sigaction_init, or by direct calls to 'signal'.
(sys_sigmask) [!__GNUC__]: Remove; no longer needed.
(sys_sigblock, sys_sigunblock, sys_sigsetmask): Remove;
all uses replaced by pthread_sigmask etc. calls.
* src/syssignal.h: Include <signal.h>.
(emacs_sigaction_init, forwarded_signal): New decls.
(SIGMASKTYPE): Remove. All uses replaced by its definiens, sigset_t.
(SIGEMPTYMASK): Remove; all uses replaced by its definiens, empty_mask.
(sigmask, sys_sigmask): Remove; no longer needed.
(sigpause): Remove. All uses replaced by its definiens, sigsuspend.
(sigblock, sigunblock, sigfree):
(sigsetmask) [!defined sigsetmask]:
Remove. All uses replaced by pthread_sigmask.
(signal): Remove. Its remaining uses (with SIG_DFL and SIG_IGN)
no longer need to be replaced, and its typical old uses
are now done via emacs_sigaction_init and sigaction.
(sys_sigblock, sys_sigunblock, sys_sigsetmask): Remove decls.
(sys_sigdel): Remove; unused.
(NSIG): Remove a FIXME; the code's fine. Remove an unnecessary ifdef.
Fixes: debbugs:12327
Diffstat (limited to 'src/syssignal.h')
-rw-r--r-- | src/syssignal.h | 59 |
1 files changed, 5 insertions, 54 deletions
diff --git a/src/syssignal.h b/src/syssignal.h index 504aff43083..58290ee3fc7 100644 --- a/src/syssignal.h +++ b/src/syssignal.h @@ -17,6 +17,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ +#include <signal.h> + extern void init_signals (void); #ifdef HAVE_PTHREAD @@ -26,63 +28,16 @@ extern void init_signals (void); #define FORWARD_SIGNAL_TO_MAIN_THREAD #endif -/* Don't #include <signal.h>. That header should always be #included - before "config.h", because some configuration files (like s/hpux.h) - indicate that SIGIO doesn't work by #undef-ing SIGIO. If this file - #includes <signal.h>, then that will re-#define SIGIO and confuse - things. */ -/* XXX This is not correct anymore, there is a BROKEN_SIGIO macro. */ - -#define SIGMASKTYPE sigset_t - -#define SIGEMPTYMASK (empty_mask) extern sigset_t empty_mask; -/* POSIX pretty much destroys any possibility of writing sigmask as a - macro in standard C. We always define our own version because the - predefined macro in Glibc 2.1 is only provided for compatibility for old - programs that use int as signal mask type. */ -#undef sigmask -#ifdef __GNUC__ -#define sigmask(SIG) \ - ({ \ - sigset_t _mask; \ - sigemptyset (&_mask); \ - sigaddset (&_mask, SIG); \ - _mask; \ - }) -#else /* ! defined (__GNUC__) */ -extern sigset_t sys_sigmask (); -#define sigmask(SIG) (sys_sigmask (SIG)) -#endif /* ! defined (__GNUC__) */ - -#undef sigpause -#define sigpause(MASK) sigsuspend (&(MASK)) - -#define sigblock(SIG) sys_sigblock (SIG) -#define sigunblock(SIG) sys_sigunblock (SIG) -#ifndef sigsetmask -#define sigsetmask(SIG) sys_sigsetmask (SIG) -#endif -#undef signal -#define signal(SIG,ACT) sys_signal(SIG,ACT) - -/* Whether this is what all systems want or not, this is what - appears to be assumed in the source, for example data.c:arith_error. */ typedef void (*signal_handler_t) (int); -signal_handler_t sys_signal (int signal_number, signal_handler_t action); -sigset_t sys_sigblock (sigset_t new_mask); -sigset_t sys_sigunblock (sigset_t new_mask); -sigset_t sys_sigsetmask (sigset_t new_mask); +extern void emacs_sigaction_init (struct sigaction *, signal_handler_t); + #if ! (defined TIOCNOTTY || defined USG5 || defined CYGWIN) _Noreturn void croak (char *); #endif -#define sys_sigdel(MASK,SIG) sigdelset (&MASK,SIG) - -#define sigfree() sigsetmask (SIGEMPTYMASK) - #if defined (SIGIO) && defined (BROKEN_SIGIO) # undef SIGIO #endif @@ -97,12 +52,8 @@ _Noreturn void croak (char *); #undef SIGPTY #endif - -/* FIXME? Emacs only defines NSIG_MINIMUM on some platforms? */ #if NSIG < NSIG_MINIMUM -# ifdef NSIG -# undef NSIG -# endif +# undef NSIG # define NSIG NSIG_MINIMUM #endif |