@@ -3558,6 +3558,18 @@ rb_execarg_run_options(const struct rb_execarg *eargp, struct rb_execarg *sargp,
3558
3558
{
3559
3559
VALUE obj ;
3560
3560
3561
+ if (eargp -> fd_dup2 != Qfalse ) {
3562
+ fprintf (stderr , "eargp->fd_dup2 set\n" );
3563
+ }
3564
+
3565
+ if (eargp -> fd_dup2_child != Qfalse ) {
3566
+ fprintf (stderr , "eargp->fd_dup2_child set\n" );
3567
+ }
3568
+
3569
+ if (eargp -> fd_close != Qfalse ) {
3570
+ fprintf (stderr , "eargp->fd_close set\n" );
3571
+ }
3572
+
3561
3573
if (sargp ) {
3562
3574
/* assume that sargp is always NULL on fork-able environments */
3563
3575
MEMZERO (sargp , struct rb_execarg , 1 );
@@ -4676,8 +4688,26 @@ rb_posix_spawn(struct rb_execarg *eargp)
4676
4688
}
4677
4689
}
4678
4690
4679
- err = posix_spawn (& pid , abspath , NULL , & attr , argv , envp );
4691
+ posix_spawn_file_actions_t file_actions ;
4692
+ posix_spawn_file_actions_init (& file_actions );
4693
+
4694
+ if (RTEST (eargp -> fd_dup2 )) {
4695
+ for (long index = 0 ; index < RARRAY_LEN (eargp -> fd_dup2 ); index ++ ) {
4696
+ VALUE pair = RARRAY_AREF (eargp -> fd_dup2 , index );
4697
+ VALUE fd = RARRAY_AREF (pair , 0 );
4698
+ VALUE params = RARRAY_AREF (pair , 1 );
4699
+
4700
+ int new_fd = NUM2INT (params ); // TODO: params may not be a FD, may need more massaging.
4701
+ fprintf (stderr , "posix_spawn_file_actions_adddup2(fops, %d, %d)\n" , new_fd , NUM2INT (fd ));
4702
+ if ((err = posix_spawn_file_actions_adddup2 (& file_actions , new_fd , NUM2INT (fd )))) {
4703
+ rb_syserr_fail (err , "posix_spawn_file_actions_adddup2" );
4704
+ }
4705
+ }
4706
+ }
4707
+
4708
+ err = posix_spawn (& pid , abspath , & file_actions , & attr , argv , envp );
4680
4709
posix_spawnattr_destroy (& attr );
4710
+ posix_spawn_file_actions_destroy (& file_actions );
4681
4711
4682
4712
if (err ) {
4683
4713
rb_sys_fail (abspath );
@@ -4700,9 +4730,10 @@ rb_spawn_process(struct rb_execarg *eargp, char *errmsg, size_t errmsg_buflen)
4700
4730
#endif
4701
4731
4702
4732
#if HAVE_POSIX_SPAWN
4733
+ // fprintf(stderr, "eargp->close_others_maxhint = %d\n", eargp->close_others_maxhint);
4703
4734
if (//!eargp->use_shell &&
4704
4735
// !eargp->pgroup_given &&
4705
- eargp -> close_others_maxhint == -1 &&
4736
+ // eargp->close_others_maxhint == -1 &&
4706
4737
!eargp -> umask_given &&
4707
4738
!eargp -> unsetenv_others_given &&
4708
4739
!eargp -> close_others_given &&
0 commit comments