Skip to content

Commit

Permalink
su: properly clear child PID
Browse files Browse the repository at this point in the history
Reported-by: Tobias Stöckmann <tobias@stoeckmann.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
  • Loading branch information
karelzak committed Feb 1, 2017
1 parent 904ffe1 commit dffab15
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions login-utils/su-common.c
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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.
*
Expand Down

0 comments on commit dffab15

Please sign in to comment.