Bash – calling sigprocmask from bash

bashsignals

I have a process that spawn a bash command with system() while the signal mask has all the signals blocked. This cannot be fixed easily.

The bash command eventually execs into a process. The all blocked signal mask is inherited from the original process through bash to the final process, so in the end I get a process that is "immune" to all the signals (except of course SIGKILL, SIGSTOP, etc).

The workaround would be resetting sigprocmask from bash, but I cannot find any related command. Is it possible to do?

Best Answer

There doesn't seem to be a pure bash solution.

Ksh (both ksh93 and mksh) unblock all signals (tested on Debian wheezy), so if you can use ksh instead of bash, it will solve your problem.

If you can't change the fact that bash is invoked, you might be able to make bash execute ksh and make ksh execute the child process: replace

bash -c '…; exec child_process'

by

bash -c '…; exec ksh -c "exec child_process"'

Beware of quoting issues!

Ksh is fast and easy to use, but often not part of the default installation. If that is an issue, you can use Perl instead, which is part of the default installation in most non-embedded Linux systems.

perl -e '
    use POSIX;
    $s = POSIX::SigSet->new(); $s->fillset();
    sigprocmask(1, $s, $s) or die $!;    # 1 = SIG_UNBLOCK
    exec "child_process"'
Related Question