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
Support eargp->use_shell in rb_posix_spawn
  • Loading branch information
byroot committed Jan 24, 2024
commit 37b89b6b398ecacfc97ca8ad754aa4f5c99d1d38
36 changes: 28 additions & 8 deletions process.c
Original file line number Diff line number Diff line change
@@ -4626,16 +4626,36 @@ rb_posix_spawn(struct rb_execarg *eargp)
char *abspath = NULL;
char **argv = NULL;

if (RTEST(eargp->invoke.cmd.command_abspath)) {
abspath = RSTRING_PTR(eargp->invoke.cmd.command_abspath);
if (eargp->use_shell) {
char *s = RSTRING_PTR(eargp->invoke.sh.shell_script);
while (*s == ' ' || *s == '\t' || *s == '\n') {
s++;
}

if (!*s) {
errno = ENOENT;
return -1;
}

// TODO: do we need dln_find_exe_r for __CYGWIN32__? Does __CYGWIN32__ even have posix_spawn?
abspath = (char *)"/bin/sh";
argv = ALLOCA_N(char *, 4);
argv[0] = (char *)"sh";
argv[1] = (char *)"-c";
argv[2] = s;
argv[3] = NULL;
}
else {
errno = ENOENT;
return -1;
else { // no-shell
if (RTEST(eargp->invoke.cmd.command_abspath)) {
abspath = RSTRING_PTR(eargp->invoke.cmd.command_abspath);
}
else {
errno = ENOENT;
return -1;
}
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;

@@ -4661,7 +4681,7 @@ rb_spawn_process(struct rb_execarg *eargp, char *errmsg, size_t errmsg_buflen)
#endif

#if HAVE_POSIX_SPAWN
if (!eargp->use_shell &&
if (//!eargp->use_shell &&
!eargp->pgroup_given &&
!eargp->umask_given &&
!eargp->unsetenv_others_given &&