summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-10 06:23:44 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-10 06:23:44 +0000
commit60b2446bea0297c47f56deb308c29a5c1af64cc9 (patch)
tree2bcb6184518b5e93ec49a03b275258a817511abd /process.c
parent4dcd8a95c7acf13a87283c11f72f7a8a7ad15019 (diff)
* sprintf.c (rb_f_sprintf): preceding ".." for negative numbers
still left; removed. * sprintf.c (rb_f_sprintf): should not prepend '0' if width > prec for example "%5.3d". * process.c (Init_process): add Process.exit and Process.abort * pack.c (utf8_to_uv): raise ArgumentError for malformed/redundant UTF-8 sequences. * process.c (last_status_set): add pid attribute to Process::Status. * pack.c (uv_to_utf8): limit maximum length of the encoded string to 6 bytes, even when the platform supports 8 bytes long integers. * pack.c (utf8_to_uv): do not decode sequences longer than 6 bytes. * object.c (copy_object): use "copy_object" method, not "become". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3123 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c53
1 files changed, 33 insertions, 20 deletions
diff --git a/process.c b/process.c
index a0ab34e..31b6926 100644
--- a/process.c
+++ b/process.c
@@ -85,11 +85,12 @@ static VALUE rb_cProcStatus;
VALUE rb_last_status = Qnil;
static void
-last_status_set(status)
- int status;
+last_status_set(status, pid)
+ int status, pid;
{
rb_last_status = rb_obj_alloc(rb_cProcStatus);
rb_iv_set(rb_last_status, "status", INT2FIX(status));
+ rb_iv_set(rb_last_status, "pid", INT2FIX(pid));
}
static VALUE
@@ -107,6 +108,13 @@ pst_to_s(st)
}
static VALUE
+pst_pid(st)
+ VALUE st;
+{
+ return rb_iv_get(st, "pid");
+}
+
+static VALUE
pst_equal(st1, st2)
VALUE st1, st2;
{
@@ -258,7 +266,7 @@ rb_waitpid(pid, st, flags)
}
#else /* NO_WAITPID */
if (pid_tbl && st_lookup(pid_tbl, pid, st)) {
- last_status_set(*st);
+ last_status_set(*st, pid);
st_delete(pid_tbl, &pid, NULL);
return pid;
}
@@ -287,7 +295,9 @@ rb_waitpid(pid, st, flags)
if (!rb_thread_alone()) rb_thread_schedule();
}
#endif
- last_status_set(*st);
+ if (result > 0) {
+ last_status_set(*st, result);
+ }
return result;
}
@@ -298,24 +308,24 @@ struct wait_data {
};
static int
-wait_each(key, value, data)
- int key, value;
+wait_each(pid, status, data)
+ int pid, status;
struct wait_data *data;
{
if (data->status != -1) return ST_STOP;
- data->pid = key;
- data->status = value;
+ data->pid = pid;
+ data->status = status;
return ST_DELETE;
}
static int
-waitall_each(key, value, data)
- int key, value;
- VALUE data;
+waitall_each(pid, status, ary)
+ int pid, status;
+ VALUE ary;
{
- last_status_set(value);
- rb_ary_push(data, rb_assoc_new(INT2NUM(key), rb_last_status));
+ last_status_set(status, pid);
+ rb_ary_push(ary, rb_assoc_new(INT2NUM(pid), rb_last_status));
return ST_DELETE;
}
#endif
@@ -342,8 +352,7 @@ proc_wait(argc, argv)
if ((pid = rb_waitpid(pid, &status, flags)) < 0)
rb_sys_fail(0);
if (pid == 0) {
- rb_last_status = Qnil;
- return Qnil;
+ return rb_last_status = Qnil;
}
return INT2FIX(pid);
}
@@ -381,7 +390,7 @@ proc_waitall()
}
rb_sys_fail(0);
}
- last_status_set(status);
+ last_status_set(status, pid);
rb_ary_push(result, rb_assoc_new(INT2NUM(pid), rb_last_status));
}
#else
@@ -817,7 +826,7 @@ rb_f_system(argc, argv)
SafeStringValue(cmd);
status = do_spawn(RSTRING(cmd)->ptr);
- last_status_set(status);
+ last_status_set(status, 0);
if (status == 0) return Qtrue;
return Qfalse;
@@ -840,7 +849,7 @@ rb_f_system(argc, argv)
SafeStringValue(cmd);
status = system(RSTRING(cmd)->ptr);
- last_status_set((status & 0xff) << 8);
+ last_status_set((status & 0xff) << 8, 0);
if (status == 0) return Qtrue;
return Qfalse;
@@ -870,7 +879,7 @@ rb_f_system(argc, argv)
else {
status = proc_spawn_n(argc, argv, prog);
}
- last_status_set(status == -1 ? 127 : status);
+ last_status_set(status == -1 ? 127 : status, 0);
return status == 0 ? Qtrue : Qfalse;
#elif defined(__VMS)
VALUE cmd;
@@ -891,7 +900,7 @@ rb_f_system(argc, argv)
SafeStringValue(cmd);
status = system(RSTRING(cmd)->ptr);
- last_status_set((status & 0xff) << 8);
+ last_status_set((status & 0xff) << 8, 0);
if (status == 0) return Qtrue;
return Qfalse;
@@ -1301,6 +1310,8 @@ Init_process()
rb_define_singleton_method(rb_mProcess, "fork", rb_f_fork, 0);
rb_define_singleton_method(rb_mProcess, "exit!", rb_f_exit_bang, -1);
+ rb_define_singleton_method(rb_mProcess, "exit", rb_f_exit, -1);
+ rb_define_singleton_method(rb_mProcess, "abort", rb_f_abort, -1);
rb_define_module_function(rb_mProcess, "kill", rb_f_kill, -1);
rb_define_module_function(rb_mProcess, "wait", proc_wait, -1);
@@ -1320,6 +1331,8 @@ Init_process()
rb_define_method(rb_cProcStatus, "to_s", pst_to_s, 0);
rb_define_method(rb_cProcStatus, "inspect", pst_to_s, 0);
+ rb_define_method(rb_cProcStatus, "pid", pst_pid, 0);
+
rb_define_method(rb_cProcStatus, "stopped?", pst_wifstopped, 0);
rb_define_method(rb_cProcStatus, "stopsig", pst_wstopsig, 0);
rb_define_method(rb_cProcStatus, "signaled?", pst_wifsignaled, 0);