Skip to content

Commit

Permalink
Shell: Move the first command in a pipeline to the pipeline pgid too
Browse files Browse the repository at this point in the history
This process is supposed to be the session leader of the pipeline
process group, we can't *not* move it into that group :P
  • Loading branch information
alimpfard authored and awesomekling committed Sep 12, 2020
1 parent d366e99 commit 063fb02
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Shell/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,12 +622,14 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
}

pid_t pgid = is_first ? child : (command.pipeline ? command.pipeline->pgid : child);
if (!m_is_subshell && command.should_wait) {
if ((!m_is_subshell && command.should_wait) || command.pipeline) {
if (setpgid(child, pgid) < 0)
perror("setpgid");

tcsetpgrp(STDOUT_FILENO, pgid);
tcsetpgrp(STDIN_FILENO, pgid);
if (!m_is_subshell) {
tcsetpgrp(STDOUT_FILENO, pgid);
tcsetpgrp(STDIN_FILENO, pgid);
}
}

while (write(sync_pipe[1], "x", 1) < 0) {
Expand Down

0 comments on commit 063fb02

Please sign in to comment.