From e20f354a7389148ec1068e2f4c5ccae4626d4c64 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 19 Aug 2011 05:25:52 +0000 Subject: * process.c (proc_spawn_v, proc_spawn): should not wait the spawned process. * process.c (proc_spawn_v): fix missing argument, and try with /bin/sh only if failed with ENOEXEC. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@33009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ configure.in | 2 +- process.c | 31 ++++++++++++++++++++++--------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index fbaca6b390..45338d68d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Fri Aug 19 14:25:51 2011 Nobuyoshi Nakada + + * process.c (proc_spawn_v, proc_spawn): should not wait the + spawned process. + + * process.c (proc_spawn_v): fix missing argument, and try with + /bin/sh only if failed with ENOEXEC. + Fri Aug 19 14:12:57 2011 Shugo Maeda * backport r33007 from trunk. diff --git a/configure.in b/configure.in index e742e74ae3..e613cd7292 100644 --- a/configure.in +++ b/configure.in @@ -1154,7 +1154,7 @@ AC_CHECK_HEADERS(limits.h sys/file.h sys/ioctl.h sys/syscall.h\ syscall.h pwd.h grp.h a.out.h utime.h direct.h sys/resource.h \ sys/mkdev.h sys/utime.h xti.h netinet/in_systm.h float.h ieeefp.h \ ucontext.h intrinsics.h langinfo.h locale.h sys/sendfile.h time.h \ - net/socket.h sys/socket.h) + net/socket.h sys/socket.h process.h) AC_TYPE_SIZE_T RUBY_CHECK_SIZEOF(size_t, [int long void*], [], [@%:@include ]) diff --git a/process.c b/process.c index 3b8fda313f..2a167577c5 100644 --- a/process.c +++ b/process.c @@ -29,6 +29,9 @@ #ifdef HAVE_FCNTL_H #include #endif +#ifdef HAVE_PROCESS_H +#include +#endif #include #include @@ -1216,6 +1219,15 @@ rb_proc_exec(const char *str) #endif #if !defined(HAVE_FORK) && defined(HAVE_SPAWNV) +# define USE_SPAWNV 1 +#else +# define USE_SPAWNV 0 +#endif +#ifndef P_NOWAIT +# define P_NOWAIT _P_NOWAIT +#endif + +#if USE_SPAWNV #if defined(_WIN32) #define proc_spawn_v(argv, prog) rb_w32_aspawn(P_NOWAIT, (prog), (argv)) #else @@ -1233,14 +1245,15 @@ proc_spawn_v(char **argv, char *prog) return -1; before_exec(); - status = spawnv(P_WAIT, prog, argv); - preserving_errno({ - rb_last_status_set(status == -1 ? 127 : status, 0); + status = spawnv(P_NOWAIT, prog, (const char **)argv); + if (status == -1 && errno == ENOEXEC) { *argv = (char *)prog; *--argv = (char *)"sh"; - status = spawnv("/bin/sh", argv); + status = spawnv(P_NOWAIT, "/bin/sh", (const char **)argv); after_exec(); - }); + if (status == -1) errno = ENOEXEC; + } + rb_last_status_set(status == -1 ? 127 : status, 0); return status; } #endif @@ -1280,7 +1293,7 @@ proc_spawn(char *str) if (*s != ' ' && !ISALPHA(*s) && strchr("*?{}[]<>()~&|\\$;'`\"\n",*s)) { char *shell = dln_find_exe_r("sh", 0, fbuf, sizeof(fbuf)); before_exec(); - status = shell?spawnl(P_WAIT,shell,"sh","-c",str,(char*)NULL):system(str); + status = spawnl(P_NOWAIT, (shell ? shell : "/bin/sh"), "sh", "-c", str, (char*)NULL); rb_last_status_set(status == -1 ? 127 : status, 0); after_exec(); return status; @@ -3011,16 +3024,16 @@ static rb_pid_t rb_spawn_process(struct rb_exec_arg *earg, VALUE prog, char *errmsg, size_t errmsg_buflen) { rb_pid_t pid; -#if defined HAVE_FORK || !defined HAVE_SPAWNV +#if !USE_SPAWNV int status; #endif -#if !defined HAVE_FORK +#if !defined HAVE_FORK || USE_SPAWNV struct rb_exec_arg sarg; int argc; VALUE *argv; #endif -#if defined HAVE_FORK +#if defined HAVE_FORK && !USE_SPAWNV pid = rb_fork_err(&status, rb_exec_atfork, earg, earg->redirect_fds, errmsg, errmsg_buflen); #else if (rb_run_exec_options_err(earg, &sarg, errmsg, errmsg_buflen) < 0) { -- cgit v1.2.3