]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
su: properly clear child PID
authorKarel Zak <kzak@redhat.com>
Wed, 1 Feb 2017 10:58:09 +0000 (11:58 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 18 Sep 2017 09:48:56 +0000 (11:48 +0200)
The patch from master branch, somehow lost during su refactoring
rebase.

Reported-by: Tobias Stöckmann <tobias@stoeckmann.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/su-common.c

index 9a32a7dc7b3f373279cab86ef4457969f2916ad0..61227f5b0df0a900e17e7d0fc74a5c567f784b3f 100644 (file)
@@ -418,11 +418,12 @@ static void create_watching_parent(struct su_context *su)
                else
                        status = 1;
 
-               DBG(SIG, ul_debug("child is dead [status=%d]", status));
+               DBG(SIG, ul_debug("child %d is dead [status=%d]", child, status));
+               child = (pid_t) -1;     /* Don't use the PID anymore! */
        } else
                status = 1;
 
-       if (caught_signal) {
+       if (caught_signal && child != (pid_t)-1) {
                fprintf(stderr, _("\nSession terminated, killing shell..."));
                kill(child, SIGTERM);
        }
@@ -430,10 +431,12 @@ static void create_watching_parent(struct su_context *su)
        supam_cleanup(su, PAM_SUCCESS);
 
        if (caught_signal) {
-               DBG(SIG, ul_debug("killing child"));
-               sleep(2);
-               kill(child, SIGKILL);
-               fprintf(stderr, _(" ...killed.\n"));
+               if (child != (pid_t)-1) {
+                       DBG(SIG, ul_debug("killing child"));
+                       sleep(2);
+                       kill(child, SIGKILL);
+                       fprintf(stderr, _(" ...killed.\n"));
+               }
 
                /* Let's terminate itself with the received signal.
                 *