]> 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>
Wed, 1 Feb 2017 10:58:09 +0000 (11:58 +0100)
Reported-by: Tobias Stöckmann <tobias@stoeckmann.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/su-common.c

index 5aefd3fff0a1d489f479b41b8881dd2b15686dba..696adc8888ad901efbb98f7878c31e4a21c4cf27 100644 (file)
@@ -368,6 +368,9 @@ create_watching_parent (void)
             }
           else
             status = WEXITSTATUS (status);
+
+         /* child is gone, don't use the PID anymore */
+         child = (pid_t) -1;
         }
       else if (caught_signal)
         status = caught_signal + 128;
@@ -377,7 +380,7 @@ create_watching_parent (void)
   else
     status = 1;
 
-  if (caught_signal)
+  if (caught_signal && child != (pid_t)-1)
     {
       fprintf (stderr, _("\nSession terminated, killing shell..."));
       kill (child, SIGTERM);
@@ -387,9 +390,12 @@ create_watching_parent (void)
 
   if (caught_signal)
     {
-      sleep (2);
-      kill (child, SIGKILL);
-      fprintf (stderr, _(" ...killed.\n"));
+      if (child != (pid_t)-1)
+       {
+         sleep (2);
+         kill (child, SIGKILL);
+         fprintf (stderr, _(" ...killed.\n"));
+       }
 
       /* Let's terminate itself with the received signal.
        *