diff --git a/scripts/daemon/exec/exec_daemon.php b/scripts/daemon/exec/exec_daemon.php --- a/scripts/daemon/exec/exec_daemon.php +++ b/scripts/daemon/exec/exec_daemon.php @@ -1,6 +1,8 @@ #!/usr/bin/env php argv = $argv; if (!self::$sighandlerInstalled) { @@ -81,7 +80,7 @@ pcntl_signal(SIGTERM, __CLASS__.'::exitOnSignal'); } - pcntl_signal(SIGINT, array($this, 'onGracefulSignal')); + pcntl_signal(SIGINT, array($this, 'onGracefulSignal')); pcntl_signal(SIGUSR2, array($this, 'onNotifySignal')); // Without discard mode, this consumes unbounded amounts of memory. Keep @@ -102,7 +101,7 @@ $daemon = get_class($this); fprintf( STDERR, - "<%s> %s %s\n", + "%s %s %s\n", '', $daemon, pht( @@ -168,7 +167,9 @@ } public static function exitOnSignal($signo) { - // Normally, PHP doesn't invoke destructors when existing in response to + self::didCatchSignal($signo); + + // Normally, PHP doesn't invoke destructors when exiting in response to // a signal. This forces it to do so, so we have a fighting chance of // releasing any locks, leases or resources on our way out. exit(128 + $signo); @@ -207,10 +208,12 @@ } final public function onGracefulSignal($signo) { + self::didCatchSignal($signo); $this->inGracefulShutdown = true; } final public function onNotifySignal($signo) { + self::didCatchSignal($signo); $this->notifyReceived = true; $this->onNotify($signo); } @@ -230,10 +233,20 @@ final protected function log($message) { if ($this->verbose) { $daemon = get_class($this); - fprintf(STDERR, "<%s> %s %s\n", '', $daemon, $message); + fprintf(STDERR, "%s %s %s\n", '', $daemon, $message); } } + private static function didCatchSignal($signo) { + $signame = phutil_get_signal_name($signo); + fprintf( + STDERR, + "%s Caught signal %s (%s).\n", + '', + $signo, + $signame); + } + /* -( Communicating With the Overseer )------------------------------------ */ @@ -250,6 +263,7 @@ if (!strlen($data)) { return ''; } + return $this->encodeOverseerMessage(self::MESSAGETYPE_STDOUT, $data); } diff --git a/src/daemon/PhutilDaemonHandle.php b/src/daemon/PhutilDaemonHandle.php --- a/src/daemon/PhutilDaemonHandle.php +++ b/src/daemon/PhutilDaemonHandle.php @@ -107,13 +107,16 @@ $stderr = trim($stderr); if (strlen($stderr)) { - $this->logMessage('STDE', $stderr); + foreach (phutil_split_lines($stderr, false) as $line) { + $this->logMessage('STDE', $line); + } } if ($result !== null) { list($err) = $result; + if ($err) { - $this->logMessage('FAIL', pht('Process exited with error %s', $err)); + $this->logMessage('FAIL', pht('Process exited with error %s.', $err)); } else { $this->logMessage('DONE', pht('Process exited normally.')); } diff --git a/src/future/exec/ExecFuture.php b/src/future/exec/ExecFuture.php --- a/src/future/exec/ExecFuture.php +++ b/src/future/exec/ExecFuture.php @@ -767,8 +767,18 @@ fclose($stderr); } + // If the subprocess got nuked with `kill -9`, we get a -1 exitcode. + // Upgrade this to a slightly more informative value by examining the + // terminating signal code. + $err = $status['exitcode']; + if ($err == -1) { + if ($status['signaled']) { + $err = 128 + $status['termsig']; + } + } + $this->result = array( - $status['exitcode'], + $err, $this->stdout, $this->stderr, ); @@ -854,6 +864,7 @@ } } $this->procStatus = proc_get_status($this->proc); + return $this->procStatus; }