Skip to content

Commit cdc0a79

Browse files
committed
Support eargp->use_shell in rb_posix_spawn
1 parent afb20fc commit cdc0a79

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

process.c

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4624,16 +4624,36 @@ rb_posix_spawn(struct rb_execarg *eargp)
46244624
char *abspath = NULL;
46254625
char **argv = NULL;
46264626

4627-
if (RTEST(eargp->invoke.cmd.command_abspath)) {
4628-
abspath = RSTRING_PTR(eargp->invoke.cmd.command_abspath);
4627+
if (eargp->use_shell) {
4628+
char *s = RSTRING_PTR(eargp->invoke.sh.shell_script);
4629+
while (*s == ' ' || *s == '\t' || *s == '\n') {
4630+
s++;
4631+
}
4632+
4633+
if (!*s) {
4634+
errno = ENOENT;
4635+
return -1;
4636+
}
4637+
4638+
// TODO: do we need dln_find_exe_r for __CYGWIN32__? Does __CYGWIN32__ even have posix_spawn?
4639+
abspath = (char *)"/bin/sh";
4640+
argv = ALLOCA_N(char *, 4);
4641+
argv[0] = (char *)"sh";
4642+
argv[1] = (char *)"-c";
4643+
argv[2] = s;
4644+
argv[3] = NULL;
46294645
}
4630-
else {
4631-
errno = ENOENT;
4632-
return -1;
4646+
else { // no-shell
4647+
if (RTEST(eargp->invoke.cmd.command_abspath)) {
4648+
abspath = RSTRING_PTR(eargp->invoke.cmd.command_abspath);
4649+
}
4650+
else {
4651+
errno = ENOENT;
4652+
return -1;
4653+
}
4654+
argv = ARGVSTR2ARGV(eargp->invoke.cmd.argv_str);
46334655
}
46344656

4635-
argv = ARGVSTR2ARGV(eargp->invoke.cmd.argv_str);
4636-
46374657
VALUE envp_str = eargp->envp_str;
46384658
char **envp = RTEST(envp_str) ? RB_IMEMO_TMPBUF_PTR(envp_str) : NULL;
46394659

@@ -4659,7 +4679,7 @@ rb_spawn_process(struct rb_execarg *eargp, char *errmsg, size_t errmsg_buflen)
46594679
#endif
46604680

46614681
#if HAVE_POSIX_SPAWN
4662-
if (!eargp->use_shell &&
4682+
if (//!eargp->use_shell &&
46634683
!eargp->pgroup_given &&
46644684
!eargp->umask_given &&
46654685
!eargp->unsetenv_others_given &&

0 commit comments

Comments
 (0)