From d0553ffbb53c10ff5354d063c4c4d15348fe955e Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 4 Nov 2010 16:21:38 +0000 Subject: [PATCH] * process.c (proc_exec_v, proc_spawn_v): try to execute with sh if no shebang. [ruby-core:32745] [EXPERIMENTAL] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ process.c | 32 +++++++++++++++++++++++++------- test/ruby/test_process.rb | 14 ++++++++++++++ test/ruby/test_system.rb | 11 +++++++++++ 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index e3d993e885..14fcd2e6ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Nov 5 01:21:31 2010 Nobuyoshi Nakada + + * process.c (proc_exec_v, proc_spawn_v): try to execute with sh if + no shebang. [ruby-core:32745] [EXPERIMENTAL] + Fri Nov 5 00:39:00 2010 Nobuyoshi Nakada * io.c (rb_io_readlines, rb_io_each_line): limit must not be zero. diff --git a/process.c b/process.c index 55b83b10b8..dbcf9219c1 100644 --- a/process.c +++ b/process.c @@ -1014,6 +1014,21 @@ security(const char *str) } } +#ifdef HAVE_FORK +#define try_with_sh(prog, argv) ((saved_errno == ENOEXEC) ? exec_with_sh(prog, argv) : (void)0) +static void +exec_with_sh(const char *prog, char **argv) +{ + *argv = (char *)prog; + *--argv = (char *)"sh"; + execv("/bin/sh", argv); +} +#define ALLOCA_ARGV(n) ALLOCA_N(char*, (n)+1) +#else +#define try_with_sh(prog, argv) (void)0 +#define ALLOCA_ARGV(n) ALLOCA_N(char*, n) +#endif + static int proc_exec_v(char **argv, const char *prog) { @@ -1058,7 +1073,7 @@ proc_exec_v(char **argv, const char *prog) #endif /* __EMX__ */ before_exec(); execv(prog, argv); - preserving_errno(after_exec()); + preserving_errno(try_with_sh(prog, argv); after_exec()); return -1; } @@ -1068,7 +1083,7 @@ rb_proc_exec_n(int argc, VALUE *argv, const char *prog) char **args; int i; - args = ALLOCA_N(char*, argc+1); + args = ALLOCA_ARGV(argc+1); for (i=0; i