Skip to content

Commit 83eaf96

Browse files
committed
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
1 parent bc9e937 commit 83eaf96

File tree

3 files changed

+82
-33
lines changed

3 files changed

+82
-33
lines changed

ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
Tue Jun 3 15:05:48 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* process.c (struct rb_exec_arg): proc should be a VALUE.
4+
5+
* process.c (rb_f_exec): suppress a warning.
6+
7+
* process.c (rb_detach_process): cast for the platforms where size of
8+
pointer differs from size of int.
9+
10+
* process.c (rb_f_exec, rb_f_system): should not exceptions after
11+
fork. [ruby-core:08262]
12+
113
Wed May 21 01:32:56 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
214

315
* lib/webrick/httpservlet/filehandler.rb: should normalize path

process.c

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -851,19 +851,19 @@ static VALUE
851851
detach_process_watcher(arg)
852852
void *arg;
853853
{
854-
int pid = (int)arg, status;
854+
int pid = (int)(VALUE)arg, status;
855855

856856
while (rb_waitpid(pid, &status, WNOHANG) == 0) {
857857
rb_thread_sleep(1);
858858
}
859-
return Qnil;
859+
return rb_last_status;
860860
}
861861

862862
VALUE
863863
rb_detach_process(pid)
864864
int pid;
865865
{
866-
return rb_thread_create(detach_process_watcher, (void*)pid);
866+
return rb_thread_create(detach_process_watcher, (void*)(VALUE)pid);
867867
}
868868

869869

@@ -882,6 +882,11 @@ rb_detach_process(pid)
882882
* terminate. <code>detach</code> only checks the status
883883
* periodically (currently once each second).
884884
*
885+
* The waiting thread returns the exit status of the detached process
886+
* when it terminates, so you can use <code>Thread#join</code> to
887+
* know the result. If specified _pid_ is not a valid child process
888+
* ID, the thread returns +nil+ immediately.
889+
*
885890
* In this first example, we don't reap the first child process, so
886891
* it appears as a zombie in the process status display.
887892
*
@@ -1069,8 +1074,8 @@ rb_proc_exec(str)
10691074
a = argv = ALLOCA_N(char*, (s-str)/2+2);
10701075
ss = ALLOCA_N(char, s-str+1);
10711076
strcpy(ss, str);
1072-
if (*a++ = strtok(ss, " \t")) {
1073-
while (t = strtok(NULL, " \t")) {
1077+
if ((*a++ = strtok(ss, " \t")) != 0) {
1078+
while ((t = strtok(NULL, " \t")) != 0) {
10741079
*a++ = t;
10751080
}
10761081
*a = NULL;
@@ -1189,6 +1194,53 @@ proc_spawn(sv)
11891194
#endif
11901195
#endif
11911196

1197+
struct rb_exec_arg {
1198+
int argc;
1199+
VALUE *argv;
1200+
VALUE prog;
1201+
};
1202+
1203+
static void
1204+
proc_prepare_args(e, argc, argv, prog)
1205+
struct rb_exec_arg *e;
1206+
int argc;
1207+
VALUE *argv;
1208+
VALUE prog;
1209+
{
1210+
int i;
1211+
1212+
MEMZERO(e, struct rb_exec_arg, 1);
1213+
if (prog) {
1214+
SafeStringValue(prog);
1215+
StringValueCStr(prog);
1216+
}
1217+
for (i = 0; i < argc; i++) {
1218+
SafeStringValue(argv[i]);
1219+
StringValueCStr(argv[i]);
1220+
}
1221+
security(RSTRING(prog ? prog : argv[0])->ptr);
1222+
e->prog = prog;
1223+
e->argc = argc;
1224+
e->argv = argv;
1225+
}
1226+
1227+
static VALUE
1228+
proc_exec_args(earg)
1229+
VALUE earg;
1230+
{
1231+
struct rb_exec_arg *e = (struct rb_exec_arg *)earg;
1232+
int argc = e->argc;
1233+
VALUE *argv = e->argv;
1234+
VALUE prog = e->prog;
1235+
1236+
if (argc == 1 && prog == 0) {
1237+
return (VALUE)rb_proc_exec(RSTRING(argv[0])->ptr);
1238+
}
1239+
else {
1240+
return (VALUE)proc_exec_n(argc, argv, prog);
1241+
}
1242+
}
1243+
11921244
/*
11931245
* call-seq:
11941246
* exec(command [, arg, ...])
@@ -1221,8 +1273,10 @@ rb_f_exec(argc, argv)
12211273
{
12221274
VALUE prog = 0;
12231275
VALUE tmp;
1276+
struct rb_exec_arg earg;
12241277

12251278
if (argc == 0) {
1279+
rb_last_status = Qnil;
12261280
rb_raise(rb_eArgError, "wrong number of arguments");
12271281
}
12281282

@@ -1235,15 +1289,8 @@ rb_f_exec(argc, argv)
12351289
argv[0] = RARRAY(tmp)->ptr[1];
12361290
SafeStringValue(prog);
12371291
}
1238-
if (argc == 1 && prog == 0) {
1239-
VALUE cmd = argv[0];
1240-
1241-
SafeStringValue(cmd);
1242-
rb_proc_exec(RSTRING(cmd)->ptr);
1243-
}
1244-
else {
1245-
proc_exec_n(argc, argv, prog);
1246-
}
1292+
proc_prepare_args(&earg, argc, argv, prog);
1293+
proc_exec_args((VALUE)&earg);
12471294
rb_sys_fail(RSTRING(argv[0])->ptr);
12481295
return Qnil; /* dummy */
12491296
}
@@ -1500,7 +1547,7 @@ rb_f_system(argc, argv)
15001547
#else
15011548
volatile VALUE prog = 0;
15021549
int pid;
1503-
int i;
1550+
struct rb_exec_arg earg;
15041551
RETSIGTYPE (*chfunc)(int);
15051552

15061553
fflush(stdout);
@@ -1517,25 +1564,15 @@ rb_f_system(argc, argv)
15171564
prog = RARRAY(argv[0])->ptr[0];
15181565
argv[0] = RARRAY(argv[0])->ptr[1];
15191566
}
1567+
proc_prepare_args(&earg, argc, argv, prog);
15201568

1521-
if (prog) {
1522-
SafeStringValue(prog);
1523-
}
1524-
for (i = 0; i < argc; i++) {
1525-
SafeStringValue(argv[i]);
1526-
}
1527-
security(RSTRING(prog ? prog : argv[0])->ptr);
15281569
chfunc = signal(SIGCHLD, SIG_DFL);
15291570
retry:
15301571
pid = fork();
15311572
if (pid == 0) {
15321573
/* child process */
1533-
if (argc == 1 && prog == 0) {
1534-
rb_proc_exec(RSTRING(argv[0])->ptr);
1535-
}
1536-
else {
1537-
proc_exec_n(argc, argv, prog);
1538-
}
1574+
rb_thread_atfork();
1575+
rb_protect(proc_exec_args, (VALUE)&earg, NULL);
15391576
_exit(127);
15401577
}
15411578
if (pid < 0) {

version.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#define RUBY_VERSION "1.8.5"
2-
#define RUBY_RELEASE_DATE "2008-05-18"
2+
#define RUBY_RELEASE_DATE "2008-06-03"
33
#define RUBY_VERSION_CODE 185
4-
#define RUBY_RELEASE_CODE 20080518
5-
#define RUBY_PATCHLEVEL 120
4+
#define RUBY_RELEASE_CODE 20080603
5+
#define RUBY_PATCHLEVEL 122
66

77
#define RUBY_VERSION_MAJOR 1
88
#define RUBY_VERSION_MINOR 8
99
#define RUBY_VERSION_TEENY 5
1010
#define RUBY_RELEASE_YEAR 2008
11-
#define RUBY_RELEASE_MONTH 5
12-
#define RUBY_RELEASE_DAY 21
11+
#define RUBY_RELEASE_MONTH 6
12+
#define RUBY_RELEASE_DAY 3
1313

1414
#ifdef RUBY_EXTERN
1515
RUBY_EXTERN const char ruby_version[];

0 commit comments

Comments
 (0)