* process.c (pst_to_s): returns a string such as "pid 10220 exit 1"
instead of "256". [ruby-dev:32053] (pst_inspect): change format "#<Process::Status: pid=10220,exited(1)>" to "#<Process::Status: pid 10220 exit 1>". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
cb1d63724c
commit
8c3658fd1b
@ -1,3 +1,11 @@
|
|||||||
|
Mon Oct 15 10:24:19 2007 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* process.c (pst_to_s): returns a string such as "pid 10220 exit 1"
|
||||||
|
instead of "256". [ruby-dev:32053]
|
||||||
|
(pst_inspect): change format
|
||||||
|
"#<Process::Status: pid=10220,exited(1)>" to
|
||||||
|
"#<Process::Status: pid 10220 exit 1>".
|
||||||
|
|
||||||
Mon Oct 15 09:58:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Mon Oct 15 09:58:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* marshal.c (r_bytes0): check if source has enough data.
|
* marshal.c (r_bytes0): check if source has enough data.
|
||||||
|
117
process.c
117
process.c
@ -246,20 +246,6 @@ pst_to_i(VALUE st)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* call-seq:
|
|
||||||
* stat.to_s => string
|
|
||||||
*
|
|
||||||
* Equivalent to _stat_<code>.to_i.to_s</code>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static VALUE
|
|
||||||
pst_to_s(VALUE st)
|
|
||||||
{
|
|
||||||
return rb_fix2str(pst_to_i(st), 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* stat.pid => fixnum
|
* stat.pid => fixnum
|
||||||
@ -277,6 +263,68 @@ pst_pid(VALUE st)
|
|||||||
return rb_iv_get(st, "pid");
|
return rb_iv_get(st, "pid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
pst_message(VALUE str, rb_pid_t pid, int status)
|
||||||
|
{
|
||||||
|
char buf[256];
|
||||||
|
snprintf(buf, sizeof(buf), "pid %ld", (long)pid);
|
||||||
|
rb_str_cat2(str, buf);
|
||||||
|
if (WIFSTOPPED(status)) {
|
||||||
|
int stopsig = WSTOPSIG(status);
|
||||||
|
const char *signame = ruby_signal_name(stopsig);
|
||||||
|
if (signame) {
|
||||||
|
snprintf(buf, sizeof(buf), " stopped SIG%s (signal %d)", signame, stopsig);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
snprintf(buf, sizeof(buf), " stopped signal %d", stopsig);
|
||||||
|
}
|
||||||
|
rb_str_cat2(str, buf);
|
||||||
|
}
|
||||||
|
if (WIFSIGNALED(status)) {
|
||||||
|
int termsig = WTERMSIG(status);
|
||||||
|
const char *signame = ruby_signal_name(termsig);
|
||||||
|
if (signame) {
|
||||||
|
snprintf(buf, sizeof(buf), " SIG%s (signal %d)", signame, termsig);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
snprintf(buf, sizeof(buf), " signal %d", termsig);
|
||||||
|
}
|
||||||
|
rb_str_cat2(str, buf);
|
||||||
|
}
|
||||||
|
if (WIFEXITED(status)) {
|
||||||
|
snprintf(buf, sizeof(buf), " exit %d", WEXITSTATUS(status));
|
||||||
|
rb_str_cat2(str, buf);
|
||||||
|
}
|
||||||
|
#ifdef WCOREDUMP
|
||||||
|
if (WCOREDUMP(status)) {
|
||||||
|
rb_str_cat2(str, " (core dumped)");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* stat.to_s => string
|
||||||
|
*
|
||||||
|
* Show pid and exit status as a string.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
pst_to_s(VALUE st)
|
||||||
|
{
|
||||||
|
rb_pid_t pid;
|
||||||
|
int status;
|
||||||
|
VALUE str;
|
||||||
|
|
||||||
|
pid = NUM2LONG(pst_pid(st));
|
||||||
|
status = NUM2INT(pst_to_i(st));
|
||||||
|
|
||||||
|
str = rb_str_buf_new(0);
|
||||||
|
pst_message(str, pid, status);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
@ -288,46 +336,15 @@ pst_pid(VALUE st)
|
|||||||
static VALUE
|
static VALUE
|
||||||
pst_inspect(VALUE st)
|
pst_inspect(VALUE st)
|
||||||
{
|
{
|
||||||
VALUE pid;
|
rb_pid_t pid;
|
||||||
int status;
|
int status;
|
||||||
VALUE str;
|
VALUE str;
|
||||||
char buf[256];
|
|
||||||
|
|
||||||
pid = pst_pid(st);
|
pid = NUM2LONG(pst_pid(st));
|
||||||
status = NUM2INT(st);
|
status = NUM2INT(pst_to_i(st));
|
||||||
|
|
||||||
str = rb_sprintf("#<%s: pid=%ld", rb_class2name(CLASS_OF(st)), NUM2LONG(pid));
|
str = rb_sprintf("#<%s: ", rb_class2name(CLASS_OF(st)));
|
||||||
if (WIFSTOPPED(status)) {
|
pst_message(str, pid, status);
|
||||||
int stopsig = WSTOPSIG(status);
|
|
||||||
const char *signame = ruby_signal_name(stopsig);
|
|
||||||
if (signame) {
|
|
||||||
snprintf(buf, sizeof(buf), ",stopped(SIG%s=%d)", signame, stopsig);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
snprintf(buf, sizeof(buf), ",stopped(%d)", stopsig);
|
|
||||||
}
|
|
||||||
rb_str_cat2(str, buf);
|
|
||||||
}
|
|
||||||
if (WIFSIGNALED(status)) {
|
|
||||||
int termsig = WTERMSIG(status);
|
|
||||||
const char *signame = ruby_signal_name(termsig);
|
|
||||||
if (signame) {
|
|
||||||
snprintf(buf, sizeof(buf), ",signaled(SIG%s=%d)", signame, termsig);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
snprintf(buf, sizeof(buf), ",signaled(%d)", termsig);
|
|
||||||
}
|
|
||||||
rb_str_cat2(str, buf);
|
|
||||||
}
|
|
||||||
if (WIFEXITED(status)) {
|
|
||||||
snprintf(buf, sizeof(buf), ",exited(%d)", WEXITSTATUS(status));
|
|
||||||
rb_str_cat2(str, buf);
|
|
||||||
}
|
|
||||||
#ifdef WCOREDUMP
|
|
||||||
if (WCOREDUMP(status)) {
|
|
||||||
rb_str_cat2(str, ",coredumped");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
rb_str_cat2(str, ">");
|
rb_str_cat2(str, ">");
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user