@@ -9,6 +9,7 @@ use crate::{
9
9
common:: bin_serde:: BinPipe ,
10
10
exec:: {
11
11
event:: { EventRegistry , Process } ,
12
+ exec_command,
12
13
io_util:: { retry_while_interrupted, was_interrupted} ,
13
14
use_pty:: backchannel:: { MonitorBackchannel , MonitorMessage , ParentMessage } ,
14
15
} ,
@@ -93,14 +94,23 @@ pub(super) fn exec_monitor(
93
94
else {
94
95
drop ( errpipe_rx) ;
95
96
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)
104
114
} ;
105
115
106
116
// Send the command's PID to the parent.
@@ -188,33 +198,6 @@ pub(super) fn exec_monitor(
188
198
_exit ( 1 ) ;
189
199
}
190
200
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
-
218
201
struct MonitorClosure < ' a > {
219
202
/// The command PID.
220
203
///
0 commit comments