unshare: Propagate inherited signal handling to forked child
In #1086, signal(3) is used along with SIG_IGN,
and SIG_DFL, to prevent premature termination of
the parent. The present approach causes the
forked child to have different inherited
signal handling behaviour than original
behaviour inherited by the parent.
$ /usr/bin/unshare cat /proc/self/status | grep Sig
SigQ: 0/15523
SigPnd:
0000000000000000
SigBlk:
0000000000000000
SigIgn:
0000000000000000
SigCgt:
0000000000000000
$ /usr/bin/unshare --fork cat /proc/self/status | grep Sig
SigQ: 0/15523
SigPnd:
0000000000000000
SigBlk:
0000000000000000
SigIgn:
0000000000004002
SigCgt:
0000000000000000
As a consequence, if the command is killed, the
outcome is different if --fork is used:
$ /usr/bin/unshare sh -c 'kill $$' ; echo $?
Terminated
143
$ /usr/bin/unshare --fork sh -c 'kill $$' ; echo $?
0
Instead use sigprocmask(2) to ensure that signal
handling behaviour is propagated from the grandparent
to the forked child.
Signed-off-by: Earl Chew <earl_chew@yahoo.com>