Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

get_status returns a Process::Status object

  • Loading branch information...
commit fb11a41671b5bc1b15372d319280cecf086c9104 1 parent ee1843e
Aman Gupta authored February 10, 2009
10  ext/cmain.cpp
@@ -310,9 +310,13 @@ evma_get_subprocess_pid
310 310
 extern "C" int evma_get_subprocess_pid (const char *binding, pid_t *pid)
311 311
 {
312 312
 	ensure_eventmachine("evma_get_subprocess_pid");
313  
-	EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
314  
-	if (ed) {
315  
-		return ed->GetSubprocessPid (pid) ? 1 : 0;
  313
+	PipeDescriptor *pd = dynamic_cast <PipeDescriptor*> (Bindable_t::GetObject (binding));
  314
+	if (pd) {
  315
+		return pd->GetSubprocessPid (pid) ? 1 : 0;
  316
+	}
  317
+	else if (pid && EventMachine->SubprocessPid) {
  318
+		*pid = EventMachine->SubprocessPid;
  319
+		return 1;
316 320
 	}
317 321
 	else
318 322
 		return 0;
1  ext/em.h
@@ -89,6 +89,7 @@ class EventMachine_t
89 89
 		static void SetuidString (const char*);
90 90
 		static int SetRlimitNofile (int);
91 91
 
  92
+		pid_t SubprocessPid;
92 93
 		int SubprocessExitStatus;
93 94
 
94 95
 		// Temporary:
3  ext/pipe.cpp
@@ -94,6 +94,9 @@ PipeDescriptor::~PipeDescriptor()
94 94
 
95 95
 	assert (MyEventMachine);
96 96
 
  97
+	/* Another hack to make the SubprocessPid available to get_subprocess_status */
  98
+	MyEventMachine->SubprocessPid = SubprocessPid;
  99
+
97 100
 	// check if the process is already dead
98 101
 	if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) == 0) {
99 102
 		kill (SubprocessPid, SIGTERM);
22  ext/rubymain.cpp
@@ -42,6 +42,8 @@ static VALUE Intern_receive_data;
42 42
 static VALUE Intern_notify_readable;
43 43
 static VALUE Intern_notify_writable;
44 44
 
  45
+static VALUE rb_cProcStatus;
  46
+
45 47
 /****************
46 48
 t_event_callback
47 49
 ****************/
@@ -242,16 +244,20 @@ t_get_subprocess_status
242 244
 
243 245
 static VALUE t_get_subprocess_status (VALUE self, VALUE signature)
244 246
 {
  247
+	VALUE proc_status = Qnil;
  248
+
245 249
 	int status;
  250
+	pid_t pid;
  251
+
246 252
 	if (evma_get_subprocess_status (StringValuePtr (signature), &status)) {
247  
-#ifdef WEXITSTATUS
248  
-		return INT2NUM (WEXITSTATUS(status));
249  
-#else
250  
-		return INT2NUM (status);
251  
-#endif
  253
+		if (evma_get_subprocess_pid (StringValuePtr (signature), &pid)) {
  254
+			proc_status = rb_obj_alloc(rb_cProcStatus);
  255
+			rb_iv_set(proc_status, "status", INT2FIX(status));
  256
+			rb_iv_set(proc_status, "pid", INT2FIX(pid));
  257
+		}
252 258
 	}
253 259
 
254  
-	return Qnil;
  260
+	return proc_status;
255 261
 }
256 262
 
257 263
 /*****************************
@@ -644,6 +650,10 @@ Init_rubyeventmachine
644 650
 
645 651
 extern "C" void Init_rubyeventmachine()
646 652
 {
  653
+	// Lookup Process::Status for get_subprocess_status
  654
+	VALUE rb_mProcess = rb_const_get(rb_cObject, rb_intern("Process"));
  655
+	rb_cProcStatus = rb_const_get(rb_mProcess, rb_intern("Status"));
  656
+
647 657
 	// Tuck away some symbol values so we don't have to look 'em up every time we need 'em.
648 658
 	Intern_at_signature = rb_intern ("@signature");
649 659
 	Intern_at_timers = rb_intern ("@timers");

0 notes on commit fb11a41

Please sign in to comment.
Something went wrong with that request. Please try again.