From: Karel Zak Date: Mon, 28 Feb 2022 10:02:04 +0000 (+0100) Subject: Revert "unshare: Fix PDEATHSIG race for --kill-child" X-Git-Tag: v2.38-rc2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f71f0cf2c8e157803ccd2e25bd9f21cae6c5fd3;p=thirdparty%2Futil-linux.git Revert "unshare: Fix PDEATHSIG race for --kill-child" This reverts commit 764bb68af8e6d1b6c10a154c1dace64c450100c0. It seems getppid() is use-less in some cases. For more details see: https://github.com/util-linux/util-linux/pull/1561#issuecomment-1049979795 Signed-off-by: Karel Zak --- diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c index 19357d478e..5effff6b18 100644 --- a/sys-utils/unshare.c +++ b/sys-utils/unshare.c @@ -763,7 +763,7 @@ int main(int argc, char *argv[]) const char *newroot = NULL; const char *newdir = NULL; pid_t pid_bind = 0, pid_idmap = 0; - pid_t pid = 0, pid_parent = 0; + pid_t pid = 0; int fd_idmap, fd_bind = -1; sigset_t sigset, oldsigset; int status; @@ -956,7 +956,6 @@ int main(int argc, char *argv[]) /* force child forking before mountspace binding * so pid_for_children is populated */ - pid_parent = getpid(); pid = fork(); switch(pid) { @@ -1008,17 +1007,8 @@ int main(int argc, char *argv[]) err(EXIT_FAILURE, _("child exit failed")); } - if (kill_child_signo != 0) { - if (prctl(PR_SET_PDEATHSIG, kill_child_signo) < 0) - err(EXIT_FAILURE, "prctl failed"); - - if (getppid() != pid_parent) { - if (kill(getpid(), kill_child_signo) != 0) - err(EXIT_FAILURE, _("child kill failed")); - /* The selected kill_child_signo be blocked, or - * might not cause termination. */ - } - } + if (kill_child_signo != 0 && prctl(PR_SET_PDEATHSIG, kill_child_signo) < 0) + err(EXIT_FAILURE, "prctl failed"); if (mapuser != (uid_t) -1 && !usermap) map_id(_PATH_PROC_UIDMAP, mapuser, real_euid);