dcavalca / rpms / util-linux

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