[SV 51400] Only unblock fatal signals after child invocation

* job.c (unblock_sigs): Only unblock fatal signals not all signals.
(unblock_all_sigs): Unblock all signals not just fatal signals.
(child_execute_job): Call unblock_all_sigs() in child process.
* job.h: Remove unused function definitions.
* remote-cstms.c (start_remote_job): Call unblock_all_sigs() in
child process.
Reported by Koen Van Hoof <koen.van_hoof@nokia.com>
This commit is contained in:
Paul Smith 2017-07-09 18:44:17 -04:00
parent 75b5268faf
commit 78b5fec689
4 changed files with 62 additions and 45 deletions

84
job.c
View File

@ -464,6 +464,62 @@ is_bourne_compatible_shell (const char *path)
return 0; return 0;
} }
#ifdef POSIX
extern sigset_t fatal_signal_set;
static void
block_sigs ()
{
sigprocmask (SIG_BLOCK, &fatal_signal_set, (sigset_t *) 0);
}
static void
unblock_sigs ()
{
sigprocmask (SIG_UNBLOCK, &fatal_signal_set, (sigset_t *) 0);
}
void
unblock_all_sigs ()
{
sigset_t empty;
sigemptyset (&empty);
sigprocmask (SIG_SETMASK, &empty, (sigset_t *) 0);
}
#elif defined(HAVE_SIGSETMASK)
extern int fatal_signal_mask;
static void
block_sigs ()
{
sigblock (fatal_signal_mask);
}
static void
unblock_sigs ()
{
sigsetmask (siggetmask (0) & ~fatal_signal_mask)
}
void
unblock_all_sigs ()
{
sigsetmask (0);
}
#else
#define block_sigs()
#define unblock_sigs()
void
unblock_all_sigs ()
{
}
#endif
/* Write an error message describing the exit status given in /* Write an error message describing the exit status given in
EXIT_CODE, EXIT_SIG, and COREDUMP, for the target TARGET_NAME. EXIT_CODE, EXIT_SIG, and COREDUMP, for the target TARGET_NAME.
@ -1037,32 +1093,6 @@ free_child (struct child *child)
free (child); free (child);
} }
#ifdef POSIX
extern sigset_t fatal_signal_set;
#endif
void
block_sigs (void)
{
#ifdef POSIX
(void) sigprocmask (SIG_BLOCK, &fatal_signal_set, (sigset_t *) 0);
#else
# ifdef HAVE_SIGSETMASK
(void) sigblock (fatal_signal_mask);
# endif
#endif
}
#ifdef POSIX
void
unblock_sigs (void)
{
sigset_t empty;
sigemptyset (&empty);
sigprocmask (SIG_SETMASK, &empty, (sigset_t *) 0);
}
#endif
/* Start a job to run the commands specified in CHILD. /* Start a job to run the commands specified in CHILD.
CHILD is updated to reflect the commands and ID of the child process. CHILD is updated to reflect the commands and ID of the child process.
@ -2144,7 +2174,7 @@ child_execute_job (struct output *out, int good_stdin, char **argv, char **envp)
return pid; return pid;
/* We are the child. */ /* We are the child. */
unblock_sigs (); unblock_all_sigs ();
#ifdef SET_STACK_SIZE #ifdef SET_STACK_SIZE
/* Reset limits, if necessary. */ /* Reset limits, if necessary. */

15
job.h
View File

@ -73,18 +73,7 @@ int exec_command (char **argv, char **envp);
void exec_command (char **argv, char **envp) __attribute__ ((noreturn)); void exec_command (char **argv, char **envp) __attribute__ ((noreturn));
#endif #endif
void unblock_all_sigs (void);
extern unsigned int job_slots_used; extern unsigned int job_slots_used;
void block_sigs (void);
#ifdef POSIX
void unblock_sigs (void);
#else
#ifdef HAVE_SIGSETMASK
extern int fatal_signal_mask;
#define unblock_sigs() sigsetmask (0)
#else
#define unblock_sigs()
#endif
#endif
extern unsigned int jobserver_tokens; extern unsigned int jobserver_tokens;

6
main.c
View File

@ -582,12 +582,10 @@ struct output make_sync;
/* Mask of signals that are being caught with fatal_error_signal. */ /* Mask of signals that are being caught with fatal_error_signal. */
#ifdef POSIX #if defined(POSIX)
sigset_t fatal_signal_set; sigset_t fatal_signal_set;
#else #elif defined(HAVE_SIGSETMASK)
# ifdef HAVE_SIGSETMASK
int fatal_signal_mask; int fatal_signal_mask;
# endif
#endif #endif
#if !HAVE_DECL_BSD_SIGNAL && !defined bsd_signal #if !HAVE_DECL_BSD_SIGNAL && !defined bsd_signal

View File

@ -246,7 +246,7 @@ start_remote_job (char **argv, char **envp, int stdin_fd,
(void) dup2 (stdin_fd, 0); (void) dup2 (stdin_fd, 0);
/* Unblock signals in the child. */ /* Unblock signals in the child. */
unblock_sigs (); unblock_all_sigs ();
/* Run the command. */ /* Run the command. */
exec_command (new_argv, envp); exec_command (new_argv, envp);