diff --git a/usr.bin/su/su.c b/usr.bin/su/su.c index 6348099c92c5..33905a983c29 100644 --- a/usr.bin/su/su.c +++ b/usr.bin/su/su.c @@ -329,10 +329,13 @@ main(int argc, char *argv[]) default: while ((ret_pid = waitpid(child_pid, &statusp, WUNTRACED)) != -1) { if (WIFSTOPPED(statusp)) { - child_pgrp = tcgetpgrp(1); kill(getpid(), SIGSTOP); - tcsetpgrp(1, child_pgrp); - kill(child_pid, SIGCONT); + child_pgrp = getpgid(child_pid); + if (tcgetpgrp(1) == getpgrp()) + { + tcsetpgrp(1, child_pgrp); + kill(child_pid, SIGCONT); + } statusp = 1; continue; }