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