DCOP: added safeguards for mysterious zombie behavior
authorDan
Tue, 26 May 2009 15:25:30 -0400
changeset 69 73780a159e15
parent 68 32f6e2ee15ab
child 70 efabb54a418d
DCOP: added safeguards for mysterious zombie behavior
functions.php
--- a/functions.php	Tue May 26 15:24:26 2009 -0400
+++ b/functions.php	Tue May 26 15:25:30 2009 -0400
@@ -90,12 +90,37 @@
 
 function dcop_action($component, $action)
 {
-  $tmpfile = tempnam('amaweb', '');
-  if ( !$tmpfile )
-    burnout('tempnam() failed us');
-  system("dcop amarok $component $action > $tmpfile");
-  $output = @file_get_contents($tmpfile);
-  @unlink($tmpfile);
+  file_put_contents('php://stderr', "[dcop] start...");
+  if ( function_exists('proc_open') )
+  {
+    $descriptorspec = array(
+        0 => array('pipe', 'r'),
+        1 => array('pipe', 'w'),
+        2 => array('pipe', 'w')
+      );
+    $dcop_command = "dcop amarok $component $action";
+    $dcop_process = proc_open($dcop_command, $descriptorspec, $dcop_pipes);
+    do
+    {
+      $status = proc_get_status($dcop_process);
+      usleep(2000);
+    } while ( $status['running'] );
+    pcntl_waitpid($status['pid'], $status);
+    $output = fgets($dcop_pipes[1], 1024);
+    proc_close($dcop_process);
+  }
+  else
+  {
+    $tmpfile = tempnam('amaweb', '');
+    if ( !$tmpfile )
+      burnout('tempnam() failed us');
+    
+    // This is freezing up for some reason.
+    system("dcop amarok $component $action > $tmpfile");
+    $output = @file_get_contents($tmpfile);
+    @unlink($tmpfile);
+  }
+  file_put_contents('php://stderr', "got it...\r");
   $output = trim($output);
   
   // detect type of output
@@ -165,7 +190,7 @@
   if ( defined('HTTPD_WS_CHILD') )
   {
     global $httpd;
-    posix_kill($httpd->parent_pid, SIGUSR1);
+    posix_kill($httpd->parent_pid, SIGHUP);
   }
 }