Permalink
Browse files

* 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/trunk@33009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 2bd37c7 commit e9930a4b56c874a73d9400a5568e3fa52a139138 @nobu nobu committed Aug 19, 2011
Showing with 31 additions and 10 deletions.
  1. +8 −0 ChangeLog
  2. +1 −1 configure.in
  3. +22 −9 process.c
View
@@ -1,3 +1,11 @@
+Fri Aug 19 14:25:51 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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 <shugo@ruby-lang.org>
* lib/net/imap.rb (idle): raises a Net::IMAP::Error when the
View
@@ -1143,7 +1143,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 <sys/types.h>])
View
@@ -29,6 +29,9 @@
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
+#ifdef HAVE_PROCESS_H
+#include <process.h>
+#endif
#include <time.h>
#include <ctype.h>
@@ -1205,6 +1208,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
@@ -1222,14 +1234,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
@@ -1269,7 +1282,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;
@@ -2966,16 +2979,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) {

0 comments on commit e9930a4

Please sign in to comment.