Permalink
Browse files

get_status returns a Process::Status object

  • Loading branch information...
1 parent ee1843e commit fb11a41671b5bc1b15372d319280cecf086c9104 @tmm1 tmm1 committed Feb 11, 2009
Showing with 27 additions and 9 deletions.
  1. +7 −3 ext/cmain.cpp
  2. +1 −0 ext/em.h
  3. +3 −0 ext/pipe.cpp
  4. +16 −6 ext/rubymain.cpp
View
@@ -310,9 +310,13 @@ evma_get_subprocess_pid
extern "C" int evma_get_subprocess_pid (const char *binding, pid_t *pid)
{
ensure_eventmachine("evma_get_subprocess_pid");
- EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
- if (ed) {
- return ed->GetSubprocessPid (pid) ? 1 : 0;
+ PipeDescriptor *pd = dynamic_cast <PipeDescriptor*> (Bindable_t::GetObject (binding));
+ if (pd) {
+ return pd->GetSubprocessPid (pid) ? 1 : 0;
+ }
+ else if (pid && EventMachine->SubprocessPid) {
+ *pid = EventMachine->SubprocessPid;
+ return 1;
}
else
return 0;
View
@@ -89,6 +89,7 @@ class EventMachine_t
static void SetuidString (const char*);
static int SetRlimitNofile (int);
+ pid_t SubprocessPid;
int SubprocessExitStatus;
// Temporary:
View
@@ -94,6 +94,9 @@ PipeDescriptor::~PipeDescriptor()
assert (MyEventMachine);
+ /* Another hack to make the SubprocessPid available to get_subprocess_status */
+ MyEventMachine->SubprocessPid = SubprocessPid;
+
// check if the process is already dead
if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) == 0) {
kill (SubprocessPid, SIGTERM);
View
@@ -42,6 +42,8 @@ static VALUE Intern_receive_data;
static VALUE Intern_notify_readable;
static VALUE Intern_notify_writable;
+static VALUE rb_cProcStatus;
+
/****************
t_event_callback
****************/
@@ -242,16 +244,20 @@ t_get_subprocess_status
static VALUE t_get_subprocess_status (VALUE self, VALUE signature)
{
+ VALUE proc_status = Qnil;
+
int status;
+ pid_t pid;
+
if (evma_get_subprocess_status (StringValuePtr (signature), &status)) {
-#ifdef WEXITSTATUS
- return INT2NUM (WEXITSTATUS(status));
-#else
- return INT2NUM (status);
-#endif
+ if (evma_get_subprocess_pid (StringValuePtr (signature), &pid)) {
+ proc_status = rb_obj_alloc(rb_cProcStatus);
+ rb_iv_set(proc_status, "status", INT2FIX(status));
+ rb_iv_set(proc_status, "pid", INT2FIX(pid));
+ }
}
- return Qnil;
+ return proc_status;
}
/*****************************
@@ -644,6 +650,10 @@ Init_rubyeventmachine
extern "C" void Init_rubyeventmachine()
{
+ // Lookup Process::Status for get_subprocess_status
+ VALUE rb_mProcess = rb_const_get(rb_cObject, rb_intern("Process"));
+ rb_cProcStatus = rb_const_get(rb_mProcess, rb_intern("Status"));
+
// Tuck away some symbol values so we don't have to look 'em up every time we need 'em.
Intern_at_signature = rb_intern ("@signature");
Intern_at_timers = rb_intern ("@timers");

0 comments on commit fb11a41

Please sign in to comment.