functions.php
changeset 69 73780a159e15
parent 64 ee64bb096f56
child 74 7719085707d8
equal deleted inserted replaced
68:32f6e2ee15ab 69:73780a159e15
    88  * @return mixed output of DCOP command
    88  * @return mixed output of DCOP command
    89  */
    89  */
    90 
    90 
    91 function dcop_action($component, $action)
    91 function dcop_action($component, $action)
    92 {
    92 {
    93   $tmpfile = tempnam('amaweb', '');
    93   file_put_contents('php://stderr', "[dcop] start...");
    94   if ( !$tmpfile )
    94   if ( function_exists('proc_open') )
    95     burnout('tempnam() failed us');
    95   {
    96   system("dcop amarok $component $action > $tmpfile");
    96     $descriptorspec = array(
    97   $output = @file_get_contents($tmpfile);
    97         0 => array('pipe', 'r'),
    98   @unlink($tmpfile);
    98         1 => array('pipe', 'w'),
       
    99         2 => array('pipe', 'w')
       
   100       );
       
   101     $dcop_command = "dcop amarok $component $action";
       
   102     $dcop_process = proc_open($dcop_command, $descriptorspec, $dcop_pipes);
       
   103     do
       
   104     {
       
   105       $status = proc_get_status($dcop_process);
       
   106       usleep(2000);
       
   107     } while ( $status['running'] );
       
   108     pcntl_waitpid($status['pid'], $status);
       
   109     $output = fgets($dcop_pipes[1], 1024);
       
   110     proc_close($dcop_process);
       
   111   }
       
   112   else
       
   113   {
       
   114     $tmpfile = tempnam('amaweb', '');
       
   115     if ( !$tmpfile )
       
   116       burnout('tempnam() failed us');
       
   117     
       
   118     // This is freezing up for some reason.
       
   119     system("dcop amarok $component $action > $tmpfile");
       
   120     $output = @file_get_contents($tmpfile);
       
   121     @unlink($tmpfile);
       
   122   }
       
   123   file_put_contents('php://stderr', "got it...\r");
    99   $output = trim($output);
   124   $output = trim($output);
   100   
   125   
   101   // detect type of output
   126   // detect type of output
   102   if ( $output == 'true' )
   127   if ( $output == 'true' )
   103     return true;
   128     return true;
   163   }
   188   }
   164   // if we're a child process, signal the parent to update
   189   // if we're a child process, signal the parent to update
   165   if ( defined('HTTPD_WS_CHILD') )
   190   if ( defined('HTTPD_WS_CHILD') )
   166   {
   191   {
   167     global $httpd;
   192     global $httpd;
   168     posix_kill($httpd->parent_pid, SIGUSR1);
   193     posix_kill($httpd->parent_pid, SIGHUP);
   169   }
   194   }
   170 }
   195 }
   171 
   196 
   172 /**
   197 /**
   173  * Builds the correct MD5 check for the specified playlist XML file. This is designed to base on the list of actual tracks, disregarding
   198  * Builds the correct MD5 check for the specified playlist XML file. This is designed to base on the list of actual tracks, disregarding