Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use posix spawn #551

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
wip
Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
  • Loading branch information
etiennebarrie and byroot committed Jan 24, 2024
commit 0d408515b4ca5b268ed69186a4e3ca0574400e2d
10 changes: 7 additions & 3 deletions process.c
Original file line number Diff line number Diff line change
@@ -4624,21 +4624,25 @@ rb_posix_spawn(struct rb_execarg *eargp)
{
pid_t pid;
char *abspath = NULL;
char **argv = NULL;

if (!NIL_P(eargp->invoke.cmd.command_abspath)) {
if (RTEST(eargp->invoke.cmd.command_abspath)) {
abspath = RSTRING_PTR(eargp->invoke.cmd.command_abspath);
}
else {
errno = ENOENT;
return -1;
}

char **argv = ARGVSTR2ARGV(eargp->invoke.cmd.argv_str);
argv = ARGVSTR2ARGV(eargp->invoke.cmd.argv_str);

VALUE envp_str = eargp->envp_str;
char **envp = RTEST(envp_str) ? RB_IMEMO_TMPBUF_PTR(envp_str) : NULL;

pid = posix_spawn(&pid, abspath, NULL, NULL, argv, envp);
int err = posix_spawn(&pid, abspath, NULL, NULL, argv, envp);
if (err) {
rb_sys_fail(abspath);
}

return (rb_pid_t)pid;
}