summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-03 06:09:11 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-03 06:09:11 +0000
commit83eaf96a6a1e71a7d3cdf2c43ea0bf3280244206 (patch)
tree6be8bf8b708d354ed36f744f35315102e52c8c22
parentbc9e9376332bdba8601a71ff18eada31cb90de6b (diff)
merge revision(s) 13479:13481:
* process.c (struct rb_exec_arg): proc should be a VALUE. * process.c (rb_f_exec): suppress a warning. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_5@16775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog12
-rw-r--r--process.c93
-rw-r--r--version.h10
3 files changed, 82 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index 287909d..557fc4b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Tue Jun 3 15:05:48 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * process.c (struct rb_exec_arg): proc should be a VALUE.
+
+ * process.c (rb_f_exec): suppress a warning.
+
+ * process.c (rb_detach_process): cast for the platforms where size of
+ pointer differs from size of int.
+
+ * process.c (rb_f_exec, rb_f_system): should not exceptions after
+ fork. [ruby-core:08262]
+
Wed May 21 01:32:56 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/httpservlet/filehandler.rb: should normalize path
diff --git a/process.c b/process.c
index 079b2b9..0f45891 100644
--- a/process.c
+++ b/process.c
@@ -851,19 +851,19 @@ static VALUE
detach_process_watcher(arg)
void *arg;
{
- int pid = (int)arg, status;
+ int pid = (int)(VALUE)arg, status;
while (rb_waitpid(pid, &status, WNOHANG) == 0) {
rb_thread_sleep(1);
}
- return Qnil;
+ return rb_last_status;
}
VALUE
rb_detach_process(pid)
int pid;
{
- return rb_thread_create(detach_process_watcher, (void*)pid);
+ return rb_thread_create(detach_process_watcher, (void*)(VALUE)pid);
}
@@ -882,6 +882,11 @@ rb_detach_process(pid)
* terminate. <code>detach</code> only checks the status
* periodically (currently once each second).
*
+ * The waiting thread returns the exit status of the detached process
+ * when it terminates, so you can use <code>Thread#join</code> to
+ * know the result. If specified _pid_ is not a valid child process
+ * ID, the thread returns +nil+ immediately.
+ *
* In this first example, we don't reap the first child process, so
* it appears as a zombie in the process status display.
*
@@ -1069,8 +1074,8 @@ rb_proc_exec(str)
a = argv = ALLOCA_N(char*, (s-str)/2+2);
ss = ALLOCA_N(char, s-str+1);
strcpy(ss, str);
- if (*a++ = strtok(ss, " \t")) {
- while (t = strtok(NULL, " \t")) {
+ if ((*a++ = strtok(ss, " \t")) != 0) {
+ while ((t = strtok(NULL, " \t")) != 0) {
*a++ = t;
}
*a = NULL;
@@ -1189,6 +1194,53 @@ proc_spawn(sv)
#endif
#endif
+struct rb_exec_arg {
+ int argc;
+ VALUE *argv;
+ VALUE prog;
+};
+
+static void
+proc_prepare_args(e, argc, argv, prog)
+ struct rb_exec_arg *e;
+ int argc;
+ VALUE *argv;
+ VALUE prog;
+{
+ int i;
+
+ MEMZERO(e, struct rb_exec_arg, 1);
+ if (prog) {
+ SafeStringValue(prog);
+ StringValueCStr(prog);
+ }
+ for (i = 0; i < argc; i++) {
+ SafeStringValue(argv[i]);
+ StringValueCStr(argv[i]);
+ }
+ security(RSTRING(prog ? prog : argv[0])->ptr);
+ e->prog = prog;
+ e->argc = argc;
+ e->argv = argv;
+}
+
+static VALUE
+proc_exec_args(earg)
+ VALUE earg;
+{
+ struct rb_exec_arg *e = (struct rb_exec_arg *)earg;
+ int argc = e->argc;
+ VALUE *argv = e->argv;
+ VALUE prog = e->prog;
+
+ if (argc == 1 && prog == 0) {
+ return (VALUE)rb_proc_exec(RSTRING(argv[0])->ptr);
+ }
+ else {
+ return (VALUE)proc_exec_n(argc, argv, prog);
+ }
+}
+
/*
* call-seq:
* exec(command [, arg, ...])
@@ -1221,8 +1273,10 @@ rb_f_exec(argc, argv)
{
VALUE prog = 0;
VALUE tmp;
+ struct rb_exec_arg earg;
if (argc == 0) {
+ rb_last_status = Qnil;
rb_raise(rb_eArgError, "wrong number of arguments");
}
@@ -1235,15 +1289,8 @@ rb_f_exec(argc, argv)
argv[0] = RARRAY(tmp)->ptr[1];
SafeStringValue(prog);
}
- if (argc == 1 && prog == 0) {
- VALUE cmd = argv[0];
-
- SafeStringValue(cmd);
- rb_proc_exec(RSTRING(cmd)->ptr);
- }
- else {
- proc_exec_n(argc, argv, prog);
- }
+ proc_prepare_args(&earg, argc, argv, prog);
+ proc_exec_args((VALUE)&earg);
rb_sys_fail(RSTRING(argv[0])->ptr);
return Qnil; /* dummy */
}
@@ -1500,7 +1547,7 @@ rb_f_system(argc, argv)
#else
volatile VALUE prog = 0;
int pid;
- int i;
+ struct rb_exec_arg earg;
RETSIGTYPE (*chfunc)(int);
fflush(stdout);
@@ -1517,25 +1564,15 @@ rb_f_system(argc, argv)
prog = RARRAY(argv[0])->ptr[0];
argv[0] = RARRAY(argv[0])->ptr[1];
}
+ proc_prepare_args(&earg, argc, argv, prog);
- if (prog) {
- SafeStringValue(prog);
- }
- for (i = 0; i < argc; i++) {
- SafeStringValue(argv[i]);
- }
- security(RSTRING(prog ? prog : argv[0])->ptr);
chfunc = signal(SIGCHLD, SIG_DFL);
retry:
pid = fork();
if (pid == 0) {
/* child process */
- if (argc == 1 && prog == 0) {
- rb_proc_exec(RSTRING(argv[0])->ptr);
- }
- else {
- proc_exec_n(argc, argv, prog);
- }
+ rb_thread_atfork();
+ rb_protect(proc_exec_args, (VALUE)&earg, NULL);
_exit(127);
}
if (pid < 0) {
diff --git a/version.h b/version.h
index 3451837..6ad5458 100644
--- a/version.h
+++ b/version.h
@@ -1,15 +1,15 @@
#define RUBY_VERSION "1.8.5"
-#define RUBY_RELEASE_DATE "2008-05-18"
+#define RUBY_RELEASE_DATE "2008-06-03"
#define RUBY_VERSION_CODE 185
-#define RUBY_RELEASE_CODE 20080518
-#define RUBY_PATCHLEVEL 120
+#define RUBY_RELEASE_CODE 20080603
+#define RUBY_PATCHLEVEL 122
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8
#define RUBY_VERSION_TEENY 5
#define RUBY_RELEASE_YEAR 2008
-#define RUBY_RELEASE_MONTH 5
-#define RUBY_RELEASE_DAY 21
+#define RUBY_RELEASE_MONTH 6
+#define RUBY_RELEASE_DAY 3
#ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[];