From: Karel Zak Date: Wed, 1 Feb 2017 10:58:09 +0000 (+0100) Subject: su: properly clear child PID X-Git-Tag: v2.29.2~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b018571132cb8c9fece3d75ed240cc74cdb5f0f7;p=thirdparty%2Futil-linux.git su: properly clear child PID Reported-by: Tobias Stöckmann Signed-off-by: Karel Zak --- diff --git a/login-utils/su-common.c b/login-utils/su-common.c index 0ea4e40bd0..b1720f037f 100644 --- a/login-utils/su-common.c +++ b/login-utils/su-common.c @@ -376,6 +376,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; @@ -385,7 +388,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); @@ -395,9 +398,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. *