531551
From 756f8301d5f7959312bea3fa8865bb543d43fd50 Mon Sep 17 00:00:00 2001
531551
From: Karel Zak <kzak@redhat.com>
531551
Date: Wed, 8 Feb 2017 10:19:56 +0100
531551
Subject: [PATCH] su: properly clear child PID
531551
531551
Upstream: http://github.com/karelzak/util-linux/commit/dffab154d29a288aa171ff50263ecc8f2e14a891
531551
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1419474
531551
Signed-off-by: Karel Zak <kzak@redhat.com>
531551
---
531551
 login-utils/su-common.c | 25 +++++++++++++++----------
531551
 1 file changed, 15 insertions(+), 10 deletions(-)
531551
531551
diff --git a/login-utils/su-common.c b/login-utils/su-common.c
531551
index d53d690..9b3cad5 100644
531551
--- a/login-utils/su-common.c
531551
+++ b/login-utils/su-common.c
531551
@@ -357,21 +357,26 @@ create_watching_parent (void)
531551
 	    break;
531551
 	}
531551
       if (pid != (pid_t)-1)
531551
-	if (WIFSIGNALED (status))
531551
-	  {
531551
-            fprintf (stderr, "%s%s\n", strsignal (WTERMSIG (status)),
531551
-                     WCOREDUMP (status) ? _(" (core dumped)") : "");
531551
-            status = WTERMSIG (status) + 128;
531551
-	  }
531551
-	else
531551
-	  status = WEXITSTATUS (status);
531551
+	{
531551
+	  if (WIFSIGNALED (status))
531551
+	    {
531551
+	      fprintf (stderr, "%s%s\n", strsignal (WTERMSIG (status)),
531551
+                       WCOREDUMP (status) ? _(" (core dumped)") : "");
531551
+	      status = WTERMSIG (status) + 128;
531551
+	    }
531551
+	  else
531551
+	    status = WEXITSTATUS (status);
531551
+
531551
+          /* child is gone, don't use the PID anymore */
531551
+          child = (pid_t) -1;
531551
+	}
531551
       else
531551
 	status = 1;
531551
     }
531551
   else
531551
     status = 1;
531551
 
531551
-  if (caught_signal)
531551
+  if (caught_signal && child != (pid_t)-1)
531551
     {
531551
       fprintf (stderr, _("\nSession terminated, killing shell..."));
531551
       kill (child, SIGTERM);
531551
@@ -379,7 +384,7 @@ create_watching_parent (void)
531551
 
531551
   cleanup_pam (PAM_SUCCESS);
531551
 
531551
-  if (caught_signal)
531551
+  if (caught_signal && (child != (pid_t)-1))
531551
     {
531551
       sleep (2);
531551
       kill (child, SIGKILL);
531551
-- 
531551
2.7.4
531551