Ejemplo n.º 1
0
 public static function manageConnections()
 {
     $still_waiting = array();
     foreach (self::$pending_connections as $cSocket) {
         if ($kid =& self::getChild($cSocket)) {
             $pid = pcntl_fork();
             if ($pid == -1) {
                 Octave_logger::log("Failed forking!", LOG_ERR);
                 exit;
             } elseif ($pid) {
                 // Parent
                 Octave_daemon::$child_pids[$pid] = true;
                 $kid->pid = $pid;
                 $kid->close();
             } else {
                 // Child
                 Octave_daemon::childMode();
                 chdir(self::$home_directory);
                 $kid->entertain();
                 $kid->killSocket();
                 exit;
             }
         } else {
             $still_waiting[] = $cSocket;
         }
     }
     self::$pending_connections = $still_waiting;
 }
Ejemplo n.º 2
0
 private static function writePID()
 {
     if (!isset(self::$config->globals["pid_file"]) || !self::$config->globals["pid_file"]) {
         return true;
     }
     $fp = @fopen(self::$config->globals["pid_file"], 'w');
     if (!$fp) {
         self::$lastError = "Failed opening PID file for writing.";
         return false;
     }
     if (!@fputs($fp, getmypid() . "\n")) {
         self::$lastError = "Failed saving PID in PID file.";
         return false;
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * The class destructor.
  *
  * Cleanly quits Octave, closes the pipes and the process.
  * @return void
  */
 public function __destruct()
 {
     if (!is_resource($this->process)) {
         // Already dead
         return;
     }
     if ($this->hangingProcess) {
         $this->_closePipes();
         return;
     }
     $this->_send("quit\n");
     $this->_closePipes();
     $status = proc_close($this->process);
     if ($status == -1) {
         throw new RuntimeException("Failed closing process");
     }
     Octave_daemon::manageDeadPID($this->pid);
 }