Skip to content

Commit 7a39215

Browse files
committed
posix_spawn: handle eargp->fd_dup2_child
1 parent c246d9f commit 7a39215

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

process.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4723,6 +4723,20 @@ rb_posix_spawn(struct rb_execarg *eargp)
47234723
}
47244724
}
47254725

4726+
if (RTEST(eargp->fd_dup2_child)) {
4727+
for (long index = 0; index < RARRAY_LEN(eargp->fd_dup2_child); index++) {
4728+
VALUE pair = RARRAY_AREF(eargp->fd_dup2_child, index);
4729+
VALUE fd = RARRAY_AREF(pair, 0);
4730+
VALUE params = RARRAY_AREF(pair, 1);
4731+
4732+
int new_fd = NUM2INT(params); // TODO: params may not be a FD, may need more massaging.
4733+
fprintf(stderr, "posix_spawn_file_actions_adddup2(fops, %d, %d)\n", new_fd, NUM2INT(fd));
4734+
if ((err = posix_spawn_file_actions_adddup2(&file_actions, new_fd, NUM2INT(fd)))) {
4735+
rb_syserr_fail(err, "posix_spawn_file_actions_adddup2");
4736+
}
4737+
}
4738+
}
4739+
47264740
if (RTEST(eargp->fd_close)) {
47274741
for (long index = 0; index < RARRAY_LEN(eargp->fd_close); index++) {
47284742
VALUE pair = RARRAY_AREF(eargp->fd_close, index);

0 commit comments

Comments
 (0)