Skip to content

Commit 8b3643e

Browse files
committed
sh: use child pgid instead of pid
1 parent 45ef990 commit 8b3643e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

sh/src/shell/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,15 +768,18 @@ impl Shell {
768768
if is_process_in_foreground() {
769769
// unwrap should never fail as child is a valid process id and in the
770770
// same session as the shell process
771-
while getpgid(Some(child)).unwrap().as_raw() as u32 == getgid().as_raw() {
772-
// loop until child is process group leader
771+
let mut child_pgid = getpgid(Some(child)).unwrap();
772+
// loop until child is in another group
773+
while child_pgid.as_raw() as u32 == getgid().as_raw() {
773774
self.handle_async_events();
774775
std::thread::sleep(Duration::from_millis(16));
776+
// cannot fail, same reason as above
777+
child_pgid = getpgid(Some(child)).unwrap();
775778
}
776779
// should never fail as stdin is a valid file descriptor and
777780
// child is a valid group id and is in the same session
778781
// as the shell process
779-
tcsetpgrp(io::stdin().as_fd(), child).unwrap();
782+
tcsetpgrp(io::stdin().as_fd(), child_pgid).unwrap();
780783
pipeline_exit_status = self.wait_child_process(child)?;
781784
// should never fail
782785
tcsetpgrp(io::stdin().as_fd(), getpgrp()).unwrap();

0 commit comments

Comments
 (0)