@@ -320,6 +320,10 @@ impl Command {
320320 cvt ( libc:: chdir ( cwd. as_ptr ( ) ) ) ?;
321321 }
322322
323+ if let Some ( pgroup) = self . get_pgroup ( ) {
324+ cvt ( libc:: setpgid ( 0 , pgroup) ) ?;
325+ }
326+
323327 // emscripten has no signal support.
324328 #[ cfg( not( target_os = "emscripten" ) ) ]
325329 {
@@ -459,6 +463,8 @@ impl Command {
459463 None => None ,
460464 } ;
461465
466+ let pgroup = self . get_pgroup ( ) ;
467+
462468 // Safety: -1 indicates we don't have a pidfd.
463469 let mut p = unsafe { Process :: new ( 0 , -1 ) } ;
464470
@@ -487,6 +493,8 @@ impl Command {
487493 cvt_nz ( libc:: posix_spawnattr_init ( attrs. as_mut_ptr ( ) ) ) ?;
488494 let attrs = PosixSpawnattr ( & mut attrs) ;
489495
496+ let mut flags = 0 ;
497+
490498 let mut file_actions = MaybeUninit :: uninit ( ) ;
491499 cvt_nz ( libc:: posix_spawn_file_actions_init ( file_actions. as_mut_ptr ( ) ) ) ?;
492500 let file_actions = PosixSpawnFileActions ( & mut file_actions) ;
@@ -516,13 +524,18 @@ impl Command {
516524 cvt_nz ( f ( file_actions. 0 . as_mut_ptr ( ) , cwd. as_ptr ( ) ) ) ?;
517525 }
518526
527+ if let Some ( pgroup) = pgroup {
528+ flags |= libc:: POSIX_SPAWN_SETPGROUP ;
529+ cvt_nz ( libc:: posix_spawnattr_setpgroup ( attrs. 0 . as_mut_ptr ( ) , pgroup) ) ?;
530+ }
531+
519532 let mut set = MaybeUninit :: < libc:: sigset_t > :: uninit ( ) ;
520533 cvt ( sigemptyset ( set. as_mut_ptr ( ) ) ) ?;
521534 cvt_nz ( libc:: posix_spawnattr_setsigmask ( attrs. 0 . as_mut_ptr ( ) , set. as_ptr ( ) ) ) ?;
522535 cvt ( sigaddset ( set. as_mut_ptr ( ) , libc:: SIGPIPE ) ) ?;
523536 cvt_nz ( libc:: posix_spawnattr_setsigdefault ( attrs. 0 . as_mut_ptr ( ) , set. as_ptr ( ) ) ) ?;
524537
525- let flags = libc:: POSIX_SPAWN_SETSIGDEF | libc:: POSIX_SPAWN_SETSIGMASK ;
538+ flags | = libc:: POSIX_SPAWN_SETSIGDEF | libc:: POSIX_SPAWN_SETSIGMASK ;
526539 cvt_nz ( libc:: posix_spawnattr_setflags ( attrs. 0 . as_mut_ptr ( ) , flags as _ ) ) ?;
527540
528541 // Make sure we synchronize access to the global `environ` resource
0 commit comments