From cd17a1f7ba2020eda0e79b5ff0e0e58df3fdd084 Mon Sep 17 00:00:00 2001 From: Brian Somers Date: Tue, 3 Jan 2006 09:17:04 +0000 Subject: [PATCH] Fix the other su bug reintroduced two commits ago, namely $ su % kill -STOP $$ where su is executing (t)csh. csh's job handling is a little more special than that of (a)sh, bash and even zsh and blows up a little more spectacularly. This modification restores the original mucking about with the tty pgrp, but is careful to only do it when su (or su's child) is the foreground process. While I'm here, fix a STDERR_FILENO spelling as suggested by bde. --- usr.bin/su/su.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/usr.bin/su/su.c b/usr.bin/su/su.c index ba592b06279..dd1602db15a 100644 --- a/usr.bin/su/su.c +++ b/usr.bin/su/su.c @@ -156,7 +156,7 @@ main(int argc, char *argv[]) char * const *b; } np; uid_t ruid; - pid_t child_pid, pid; + pid_t child_pid, child_pgrp, pid; int asme, ch, asthem, fastlogin, prio, i, retcode, statusp, setmaclabel; u_int setwhat; @@ -392,17 +392,30 @@ main(int argc, char *argv[]) sa.sa_handler = SIG_IGN; sigaction(SIGTTOU, &sa, NULL); close(fds[0]); + setpgid(child_pid, child_pid); + if (tcgetpgrp(STDERR_FILENO) == getpgrp()) + tcsetpgrp(STDERR_FILENO, child_pid); close(fds[1]); sigaction(SIGPIPE, &sa_pipe, NULL); while ((pid = waitpid(child_pid, &statusp, WUNTRACED)) != -1) { if (WIFSTOPPED(statusp)) { + child_pgrp = getpgid(child_pid); + if (tcgetpgrp(STDERR_FILENO) == child_pgrp) + tcsetpgrp(STDERR_FILENO, getpgrp()); kill(getpid(), SIGSTOP); + if (tcgetpgrp(STDERR_FILENO) == getpgrp()) { + child_pgrp = getpgid(child_pid); + tcsetpgrp(STDERR_FILENO, child_pgrp); + } kill(child_pid, SIGCONT); statusp = 1; continue; } break; } + child_pgrp = getpgid(child_pid); + if (tcgetpgrp(STDERR_FILENO) == child_pgrp) + tcsetpgrp(STDERR_FILENO, getpgrp()); if (pid == -1) err(1, "waitpid"); PAM_END();