Skip to content

Commit dffab15

Browse files
committed
su: properly clear child PID
Reported-by: Tobias Stöckmann <tobias@stoeckmann.org> Signed-off-by: Karel Zak <kzak@redhat.com>
1 parent 904ffe1 commit dffab15

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Diff for: login-utils/su-common.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ create_watching_parent (void)
368368
}
369369
else
370370
status = WEXITSTATUS (status);
371+
372+
/* child is gone, don't use the PID anymore */
373+
child = (pid_t) -1;
371374
}
372375
else if (caught_signal)
373376
status = caught_signal + 128;
@@ -377,7 +380,7 @@ create_watching_parent (void)
377380
else
378381
status = 1;
379382

380-
if (caught_signal)
383+
if (caught_signal && child != (pid_t)-1)
381384
{
382385
fprintf (stderr, _("\nSession terminated, killing shell..."));
383386
kill (child, SIGTERM);
@@ -387,9 +390,12 @@ create_watching_parent (void)
387390

388391
if (caught_signal)
389392
{
390-
sleep (2);
391-
kill (child, SIGKILL);
392-
fprintf (stderr, _(" ...killed.\n"));
393+
if (child != (pid_t)-1)
394+
{
395+
sleep (2);
396+
kill (child, SIGKILL);
397+
fprintf (stderr, _(" ...killed.\n"));
398+
}
393399

394400
/* Let's terminate itself with the received signal.
395401
*

0 commit comments

Comments
 (0)