* atimer.c (sigmask_atimers): Remove.
Remaining use rewritten to use body of this function.
* atimer.c (block_atimers, unblock_atimers):
* callproc.c (block_child_signal, unblock_child_signal):
* sysdep.c (block_tty_out_signal, unblock_tty_out_signal):
New arg OLDSET. All callers changed.
* atimer.c (block_atimers, unblock_atimers):
* callproc.c (block_child_signal, unblock_child_signal):
* keyboard.c (handle_interrupt):
* sound.c (vox_configure, vox_close):
Restore the old signal mask rather than unilaterally clearing bits
from the mask, in case a handler is running within another
handler. All callers changed.
* lisp.h, process.c, process.h, term.c:
Adjust decls and callers to match new API.
* sysdep.c (emacs_sigaction_init): Don't worry about masking SIGFPE;
signal handlers aren't supposed to use floating point anyway.
(handle_arith_signal): Unblock just SIGFPE rather than clearing mask.
Fixes: debbugs:15561
+2014-03-25 Paul Eggert <eggert@cs.ucla.edu>
+
+ Handle sigmask better with nested signal handlers (Bug#15561).
+ * atimer.c (sigmask_atimers): Remove.
+ Remaining use rewritten to use body of this function.
+ * atimer.c (block_atimers, unblock_atimers):
+ * callproc.c (block_child_signal, unblock_child_signal):
+ * sysdep.c (block_tty_out_signal, unblock_tty_out_signal):
+ New arg OLDSET. All callers changed.
+ * atimer.c (block_atimers, unblock_atimers):
+ * callproc.c (block_child_signal, unblock_child_signal):
+ * keyboard.c (handle_interrupt):
+ * sound.c (vox_configure, vox_close):
+ Restore the old signal mask rather than unilaterally clearing bits
+ from the mask, in case a handler is running within another
+ handler. All callers changed.
+ * lisp.h, process.c, process.h, term.c:
+ Adjust decls and callers to match new API.
+ * sysdep.c (emacs_sigaction_init): Don't worry about masking SIGFPE;
+ signal handlers aren't supposed to use floating point anyway.
+ (handle_arith_signal): Unblock just SIGFPE rather than clearing mask.
+
2014-03-23 Daniel Colascione <dancol@dancol.org>
Split gc_sweep into discrete functions for legibility and better
/* Block/unblock SIGALRM. */
static void
-sigmask_atimers (int how)
+block_atimers (sigset_t *oldset)
{
sigset_t blocked;
sigemptyset (&blocked);
sigaddset (&blocked, SIGALRM);
- pthread_sigmask (how, &blocked, 0);
+ pthread_sigmask (SIG_BLOCK, &blocked, oldset);
}
static void
-block_atimers (void)
+unblock_atimers (sigset_t const *oldset)
{
- sigmask_atimers (SIG_BLOCK);
-}
-static void
-unblock_atimers (void)
-{
- sigmask_atimers (SIG_UNBLOCK);
+ pthread_sigmask (SIG_SETMASK, oldset, 0);
}
/* Function prototypes. */
atimer_callback fn, void *client_data)
{
struct atimer *t;
+ sigset_t oldset;
/* Round TIME up to the next full second if we don't have
itimers. */
t->fn = fn;
t->client_data = client_data;
- block_atimers ();
+ block_atimers (&oldset);
/* Compute the timer's expiration time. */
switch (type)
/* Insert the timer in the list of active atimers. */
schedule_atimer (t);
- unblock_atimers ();
+ unblock_atimers (&oldset);
/* Arrange for a SIGALRM at the time the next atimer is ripe. */
set_alarm ();
cancel_atimer (struct atimer *timer)
{
int i;
+ sigset_t oldset;
- block_atimers ();
+ block_atimers (&oldset);
for (i = 0; i < 2; ++i)
{
}
}
- unblock_atimers ();
+ unblock_atimers (&oldset);
}
void
stop_other_atimers (struct atimer *t)
{
- block_atimers ();
+ sigset_t oldset;
+ block_atimers (&oldset);
if (t)
{
stopped_atimers = append_atimer_lists (atimers, stopped_atimers);
atimers = t;
- unblock_atimers ();
+ unblock_atimers (&oldset);
}
{
struct atimer *t = atimers;
struct atimer *next;
+ sigset_t oldset;
- block_atimers ();
+ block_atimers (&oldset);
atimers = stopped_atimers;
stopped_atimers = NULL;
t = next;
}
- unblock_atimers ();
+ unblock_atimers (&oldset);
}
}
{
if (atimers)
{
- block_atimers ();
+ sigset_t oldset;
+ block_atimers (&oldset);
run_timers ();
- unblock_atimers ();
+ unblock_atimers (&oldset);
}
}
/* Block SIGCHLD. */
void
-block_child_signal (void)
+block_child_signal (sigset_t *oldset)
{
sigset_t blocked;
sigemptyset (&blocked);
sigaddset (&blocked, SIGCHLD);
- pthread_sigmask (SIG_BLOCK, &blocked, 0);
+ pthread_sigmask (SIG_BLOCK, &blocked, oldset);
}
/* Unblock SIGCHLD. */
void
-unblock_child_signal (void)
+unblock_child_signal (sigset_t const *oldset)
{
- pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
+ pthread_sigmask (SIG_SETMASK, oldset, 0);
}
/* Return the current buffer's working directory, or the home
void
record_kill_process (struct Lisp_Process *p, Lisp_Object tempfile)
{
- block_child_signal ();
+ sigset_t oldset;
+ block_child_signal (&oldset);
if (p->alive)
{
kill (- p->pid, SIGKILL);
}
- unblock_child_signal ();
+ unblock_child_signal (&oldset);
}
/* Clean up files, file descriptors and processes created by Fcall_process. */
char *tempfile = NULL;
int pid;
#else
+ sigset_t oldset;
pid_t pid;
#endif
int child_errno;
#ifndef MSDOS
block_input ();
- block_child_signal ();
+ block_child_signal (&oldset);
#ifdef WINDOWSNT
pid = child_setup (filefd, fd_output, fd_error, new_argv, 0, current_dir);
if (pid == 0)
{
- unblock_child_signal ();
+ unblock_child_signal (&oldset);
setsid ();
}
}
- unblock_child_signal ();
+ unblock_child_signal (&oldset);
unblock_input ();
#endif /* not MSDOS */
handle_interrupt (bool in_signal_handler)
{
char c;
+ sigset_t blocked;
+ sigemptyset (&blocked);
+ sigaddset (&blocked, SIGINT);
cancel_echoing ();
/* If SIGINT isn't blocked, don't let us be interrupted by
a SIGINT. It might be harmful due to non-reentrancy
in I/O functions. */
- sigset_t blocked;
- sigemptyset (&blocked);
- sigaddset (&blocked, SIGINT);
pthread_sigmask (SIG_BLOCK, &blocked, 0);
}
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
immediate_quit = 0;
- pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
+ pthread_sigmask (SIG_UNBLOCK, &blocked, 0);
saved = gl_state;
GCPRO4 (saved.object, saved.global_code,
saved.current_syntax_table, saved.old_prop);
}
}
- pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
+ pthread_sigmask (SIG_UNBLOCK, &blocked, 0);
/* TODO: The longjmp in this call throws the NS event loop integration off,
and it seems to do fine without this. Probably some attention
extern void sys_subshell (void);
extern void sys_suspend (void);
extern void discard_tty_input (void);
-extern void block_tty_out_signal (void);
-extern void unblock_tty_out_signal (void);
+extern void block_tty_out_signal (sigset_t *);
+extern void unblock_tty_out_signal (sigset_t const *);
extern void init_sys_modes (struct tty_display_info *);
extern void reset_sys_modes (struct tty_display_info *);
extern void init_all_sys_modes (void);
bool pty_flag = 0;
char pty_name[PTY_NAME_SIZE];
Lisp_Object lisp_pty_name = Qnil;
+ sigset_t oldset;
inchannel = outchannel = -1;
setup_process_coding_systems (process);
block_input ();
- block_child_signal ();
+ block_child_signal (&oldset);
#ifndef WINDOWSNT
/* vfork, and prevent local vars from being clobbered by the vfork. */
signal (SIGPIPE, SIG_DFL);
/* Stop blocking SIGCHLD in the child. */
- unblock_child_signal ();
+ unblock_child_signal (&oldset);
if (pty_flag)
child_setup_tty (xforkout);
p->alive = 1;
/* Stop blocking in the parent. */
- unblock_child_signal ();
+ unblock_child_signal (&oldset);
unblock_input ();
if (pid < 0)
catch_child_signal (void)
{
struct sigaction action, old_action;
+ sigset_t oldset;
emacs_sigaction_init (&action, deliver_child_signal);
- block_child_signal ();
+ block_child_signal (&oldset);
sigaction (SIGCHLD, &action, &old_action);
eassert (! (old_action.sa_flags & SA_SIGINFO));
= (old_action.sa_handler == SIG_DFL || old_action.sa_handler == SIG_IGN
? dummy_handler
: old_action.sa_handler);
- unblock_child_signal ();
+ unblock_child_signal (&oldset);
}
\f
/* Defined in callproc.c. */
-extern void block_child_signal (void);
-extern void unblock_child_signal (void);
+extern void block_child_signal (sigset_t *);
+extern void unblock_child_signal (sigset_t const *);
extern Lisp_Object encode_current_directory (void);
extern void record_kill_process (struct Lisp_Process *, Lisp_Object);
{
int val;
#ifdef USABLE_SIGIO
- sigset_t blocked;
+ sigset_t oldset, blocked;
#endif
eassert (sd->fd >= 0);
#ifdef USABLE_SIGIO
sigemptyset (&blocked);
sigaddset (&blocked, SIGIO);
- pthread_sigmask (SIG_BLOCK, &blocked, 0);
+ pthread_sigmask (SIG_BLOCK, &blocked, &oldset);
#endif
val = sd->format;
turn_on_atimers (1);
#ifdef USABLE_SIGIO
- pthread_sigmask (SIG_UNBLOCK, &blocked, 0);
+ pthread_sigmask (SIG_SETMASK, &oldset, 0);
#endif
}
be interrupted by a signal. Block the ones we know to cause
troubles. */
#ifdef USABLE_SIGIO
- sigset_t blocked;
+ sigset_t blocked, oldset;
sigemptyset (&blocked);
sigaddset (&blocked, SIGIO);
- pthread_sigmask (SIG_BLOCK, &blocked, 0);
+ pthread_sigmask (SIG_BLOCK, &blocked, &oldset);
#endif
turn_on_atimers (0);
turn_on_atimers (1);
#ifdef USABLE_SIGIO
- pthread_sigmask (SIG_UNBLOCK, &blocked, 0);
+ pthread_sigmask (SIG_SETMASK, &oldset, 0);
#endif
/* Close the device. */
/* Block and unblock SIGTTOU. */
void
-block_tty_out_signal (void)
+block_tty_out_signal (sigset_t *oldset)
{
#ifdef SIGTTOU
sigset_t blocked;
sigemptyset (&blocked);
sigaddset (&blocked, SIGTTOU);
- pthread_sigmask (SIG_BLOCK, &blocked, 0);
+ pthread_sigmask (SIG_BLOCK, &blocked, oldset);
#endif
}
void
-unblock_tty_out_signal (void)
+unblock_tty_out_signal (sigset_t const *oldset)
{
#ifdef SIGTTOU
- pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
+ pthread_sigmask (SIG_SETMASK, oldset, 0);
#endif
}
tcsetpgrp_without_stopping (int fd, pid_t pgid)
{
#ifdef SIGTTOU
+ sigset_t oldset;
block_input ();
- block_tty_out_signal ();
+ block_tty_out_signal (&oldset);
tcsetpgrp (fd, pgid);
- unblock_tty_out_signal ();
+ unblock_tty_out_signal (&oldset);
unblock_input ();
#endif
}
#endif
}
- if (! IEEE_FLOATING_POINT)
- sigaddset (&action->sa_mask, SIGFPE);
-
action->sa_handler = handler;
action->sa_flags = emacs_sigaction_flags ();
}
static _Noreturn void
handle_arith_signal (int sig)
{
- pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
+ sigset_t blocked;
+ sigemptyset (&blocked);
+ sigaddset (&blocked, sig);
+ pthread_sigmask (SIG_UNBLOCK, &blocked, 0);
xsignal0 (Qarith_error);
}
/* setsid failed, presumably because Emacs is already a process
group leader. Fall back on the obsolescent way to dissociate
a controlling tty. */
- block_tty_out_signal ();
+ sigset_t oldset;
+ block_tty_out_signal (&oldset);
ioctl (fd, TIOCNOTTY, 0);
- unblock_tty_out_signal ();
+ unblock_tty_out_signal (&oldset);
#endif
}
}
int status;
struct tty_display_info *tty = NULL;
struct terminal *terminal = NULL;
+ sigset_t oldset;
bool ctty = false; /* True if asked to open controlling tty. */
if (!terminal_type)
/* On some systems, tgetent tries to access the controlling
terminal. */
- block_tty_out_signal ();
+ block_tty_out_signal (&oldset);
status = tgetent (tty->termcap_term_buffer, terminal_type);
if (tty->termcap_term_buffer[TERMCAP_BUFFER_SIZE - 1])
emacs_abort ();
- unblock_tty_out_signal ();
+ unblock_tty_out_signal (&oldset);
if (status < 0)
{