From 6b28328255aa1248931947a4d1521288bde01837 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 1 Feb 2017 11:58:09 +0100 Subject: su: properly clear child PID The patch from master branch, somehow lost during su refactoring rebase. Reported-by: Tobias Stöckmann Signed-off-by: Karel Zak --- login-utils/su-common.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'login-utils') diff --git a/login-utils/su-common.c b/login-utils/su-common.c index 9a32a7dc7..61227f5b0 100644 --- a/login-utils/su-common.c +++ b/login-utils/su-common.c @@ -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. * -- cgit v1.2.3-55-g7522