Skip to content

Commit 09a5f7a

Browse files
committed
Inline function
1 parent 15cbba4 commit 09a5f7a

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

src/exec/use_pty/monitor.rs

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{
99
common::bin_serde::BinPipe,
1010
exec::{
1111
event::{EventRegistry, Process},
12+
exec_command,
1213
io_util::{retry_while_interrupted, was_interrupted},
1314
use_pty::backchannel::{MonitorBackchannel, MonitorMessage, ParentMessage},
1415
},
@@ -93,14 +94,23 @@ pub(super) fn exec_monitor(
9394
else {
9495
drop(errpipe_rx);
9596

96-
match exec_command(
97-
command,
98-
foreground,
99-
pty_follower,
100-
file_closer,
101-
errpipe_tx,
102-
original_set,
103-
) {}
97+
// FIXME (ogsudo): Do any additional configuration that needs to be run after `fork` but before `exec`
98+
let command_pid = ProcessId::new(std::process::id() as i32);
99+
100+
setpgid(ProcessId::new(0), command_pid).ok();
101+
102+
// Wait for the monitor to set us as the foreground group for the pty if we are in the
103+
// foreground.
104+
if foreground {
105+
while !pty_follower.tcgetpgrp().is_ok_and(|pid| pid == command_pid) {
106+
std::thread::yield_now();
107+
}
108+
}
109+
110+
// Done with the pty follower.
111+
drop(pty_follower);
112+
113+
exec_command(file_closer, command, original_set, errpipe_tx)
104114
};
105115

106116
// Send the command's PID to the parent.
@@ -188,33 +198,6 @@ pub(super) fn exec_monitor(
188198
_exit(1);
189199
}
190200

191-
fn exec_command(
192-
command: Command,
193-
foreground: bool,
194-
pty_follower: PtyFollower,
195-
file_closer: FileCloser,
196-
errpipe_tx: BinPipe<i32, i32>,
197-
original_set: Option<SignalSet>,
198-
) -> ! {
199-
// FIXME (ogsudo): Do any additional configuration that needs to be run after `fork` but before `exec`
200-
let command_pid = ProcessId::new(std::process::id() as i32);
201-
202-
setpgid(ProcessId::new(0), command_pid).ok();
203-
204-
// Wait for the monitor to set us as the foreground group for the pty if we are in the
205-
// foreground.
206-
if foreground {
207-
while !pty_follower.tcgetpgrp().is_ok_and(|pid| pid == command_pid) {
208-
std::thread::yield_now();
209-
}
210-
}
211-
212-
// Done with the pty follower.
213-
drop(pty_follower);
214-
215-
crate::exec::exec_command(file_closer, command, original_set, errpipe_tx)
216-
}
217-
218201
struct MonitorClosure<'a> {
219202
/// The command PID.
220203
///

0 commit comments

Comments
 (0)