summaryrefslogtreecommitdiffstats
path: root/login-utils
diff options
context:
space:
mode:
authorKarel Zak2017-02-01 11:58:09 +0100
committerKarel Zak2017-09-18 11:48:56 +0200
commit6b28328255aa1248931947a4d1521288bde01837 (patch)
tree663adde03dcf54ba841c6d2b3020273ca0fb2e92 /login-utils
parentsu: improve some debug messages (diff)
downloadkernel-qcow2-util-linux-6b28328255aa1248931947a4d1521288bde01837.tar.gz
kernel-qcow2-util-linux-6b28328255aa1248931947a4d1521288bde01837.tar.xz
kernel-qcow2-util-linux-6b28328255aa1248931947a4d1521288bde01837.zip
su: properly clear child PID
The patch from master branch, somehow lost during su refactoring rebase. Reported-by: Tobias Stöckmann <tobias@stoeckmann.org> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils')
-rw-r--r--login-utils/su-common.c15
1 files changed, 9 insertions, 6 deletions
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.
*