Skip to content

Commit d5faf7f

Browse files
committed
Support eargp->use_shell in rb_posix_spawn
1 parent edb12dd commit d5faf7f

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
@@ -4626,16 +4626,36 @@ rb_posix_spawn(struct rb_execarg *eargp)
46264626
char *abspath = NULL;
46274627
char **argv = NULL;
46284628

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

4637-
argv = ARGVSTR2ARGV(eargp->invoke.cmd.argv_str);
4638-
46394659
VALUE envp_str = eargp->envp_str;
46404660
char **envp = RTEST(envp_str) ? RB_IMEMO_TMPBUF_PTR(envp_str) : NULL;
46414661

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

46634683
#if HAVE_POSIX_SPAWN
4664-
if (!eargp->use_shell &&
4684+
if (//!eargp->use_shell &&
46654685
!eargp->pgroup_given &&
46664686
!eargp->umask_given &&
46674687
!eargp->unsetenv_others_given &&

0 commit comments

Comments
 (0)