]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
Revert "unshare: Fix PDEATHSIG race for --kill-child"
authorKarel Zak <kzak@redhat.com>
Mon, 28 Feb 2022 10:02:04 +0000 (11:02 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 28 Feb 2022 10:02:04 +0000 (11:02 +0100)
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 <kzak@redhat.com>
sys-utils/unshare.c

index 19357d478e1e58f46f99d4d84dfd925abbd5b68e..5effff6b187d34fd2c1683185dc4e4443de3124c 100644 (file)
@@ -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);