summaryrefslogtreecommitdiffstats
path: root/login-utils/su-common.c
diff options
context:
space:
mode:
authorKarel Zak2017-02-01 11:58:09 +0100
committerKarel Zak2017-02-01 11:58:09 +0100
commitdffab154d29a288aa171ff50263ecc8f2e14a891 (patch)
treed635901ad9729c325982dccfc7b2a37ca1bdd4c1 /login-utils/su-common.c
parentlscpu: don't use path_exist() before path_fopen() (diff)
downloadkernel-qcow2-util-linux-dffab154d29a288aa171ff50263ecc8f2e14a891.tar.gz
kernel-qcow2-util-linux-dffab154d29a288aa171ff50263ecc8f2e14a891.tar.xz
kernel-qcow2-util-linux-dffab154d29a288aa171ff50263ecc8f2e14a891.zip
su: properly clear child PID
Reported-by: Tobias Stöckmann <tobias@stoeckmann.org> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils/su-common.c')
-rw-r--r--login-utils/su-common.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/login-utils/su-common.c b/login-utils/su-common.c
index 5aefd3fff..696adc888 100644
--- a/login-utils/su-common.c
+++ b/login-utils/su-common.c
@@ -368,6 +368,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;
@@ -377,7 +380,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);
@@ -387,9 +390,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.
*