su: properly clear child PID

Reported-by: Tobias Stöckmann <tobias@stoeckmann.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2017-02-01 11:58:09 +01:00
parent 904ffe1fd2
commit dffab154d2
1 changed files with 10 additions and 4 deletions

View File

@ -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.
*