Skip to content

Commit 5b4f8a8

Browse files
committed
posix_spawn: support eargp->fd_close
1 parent 5a4ede0 commit 5b4f8a8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

process.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4691,6 +4691,26 @@ rb_posix_spawn(struct rb_execarg *eargp)
46914691
posix_spawn_file_actions_t file_actions;
46924692
posix_spawn_file_actions_init(&file_actions);
46934693

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+
46944714
if (RTEST(eargp->fd_dup2)) {
46954715
for (long index = 0; index < RARRAY_LEN(eargp->fd_dup2); index++) {
46964716
VALUE pair = RARRAY_AREF(eargp->fd_dup2, index);
@@ -4705,6 +4725,18 @@ rb_posix_spawn(struct rb_execarg *eargp)
47054725
}
47064726
}
47074727

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+
47084740
err = posix_spawn(&pid, abspath, &file_actions, &attr, argv, envp);
47094741
posix_spawnattr_destroy(&attr);
47104742
posix_spawn_file_actions_destroy(&file_actions);

0 commit comments

Comments
 (0)