@@ -4691,6 +4691,26 @@ rb_posix_spawn(struct rb_execarg *eargp)
4691
4691
posix_spawn_file_actions_t file_actions ;
4692
4692
posix_spawn_file_actions_init (& file_actions );
4693
4693
4694
+ // TODO: do we need it? Currently the `open` seem to be done in the parent.
4695
+ // if (RTEST(eargp->fd_open)) {
4696
+ // for (long index = 0; index < RARRAY_LEN(eargp->fd_open); index++) {
4697
+ // VALUE pair = RARRAY_AREF(eargp->fd_open, index);
4698
+ // VALUE fd = RARRAY_AREF(pair, 0);
4699
+ // VALUE params = RARRAY_AREF(pair, 1);
4700
+ //
4701
+ // VALUE path = RARRAY_AREF(param, 0);
4702
+ // VALUE flags = RARRAY_AREF(param, 1);
4703
+ // // param = rb_ary_new3(4, path, flags, perm, Qnil);
4704
+ //
4705
+ //
4706
+ // int new_fd = NUM2INT(params); // TODO: params may not be a FD, may need more massaging.
4707
+ // fprintf(stderr, "posix_spawn_file_actions_addopen(fops, %d, %d)\n", new_fd, NUM2INT(fd));
4708
+ // if ((err = posix_spawn_file_actions_addopen(&file_actions, fd, RSTRING_PTR(path), NUM2INT(flags)))) {
4709
+ // rb_syserr_fail(err, "posix_spawn_file_actions_addopen");
4710
+ // }
4711
+ // }
4712
+ // }
4713
+
4694
4714
if (RTEST (eargp -> fd_dup2 )) {
4695
4715
for (long index = 0 ; index < RARRAY_LEN (eargp -> fd_dup2 ); index ++ ) {
4696
4716
VALUE pair = RARRAY_AREF (eargp -> fd_dup2 , index );
@@ -4705,6 +4725,18 @@ rb_posix_spawn(struct rb_execarg *eargp)
4705
4725
}
4706
4726
}
4707
4727
4728
+ if (RTEST (eargp -> fd_close )) {
4729
+ for (long index = 0 ; index < RARRAY_LEN (eargp -> fd_close ); index ++ ) {
4730
+ VALUE pair = RARRAY_AREF (eargp -> fd_close , index );
4731
+ VALUE fd = RARRAY_AREF (pair , 0 );
4732
+
4733
+ fprintf (stderr , "posix_spawn_file_actions_addclose(fops, %d)\n" , NUM2INT (fd ));
4734
+ if ((err = posix_spawn_file_actions_addclose (& file_actions , NUM2INT (fd )))) {
4735
+ rb_syserr_fail (err , "posix_spawn_file_actions_addclose" );
4736
+ }
4737
+ }
4738
+ }
4739
+
4708
4740
err = posix_spawn (& pid , abspath , & file_actions , & attr , argv , envp );
4709
4741
posix_spawnattr_destroy (& attr );
4710
4742
posix_spawn_file_actions_destroy (& file_actions );
0 commit comments