]> git.ipfire.org Git - thirdparty/util-linux.git/commit
unshare: Propagate inherited signal handling to forked child
authorEarl Chew <earl_chew@yahoo.com>
Sun, 9 Jan 2022 22:01:21 +0000 (14:01 -0800)
committerEarl Chew <earl_chew@yahoo.com>
Sun, 9 Jan 2022 22:08:03 +0000 (14:08 -0800)
commitf2f9801779e1664b7fa2d31c58fdb499191902ba
tree6a78067002f97aa345ab439366504ba90239d753
parent312b64d9d1cedeac8d926cc503ffb4fbe023ade0
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>
sys-utils/unshare.c