Page MenuHomePhabricator

D15977.id38462.diff
No OneTemporary

D15977.id38462.diff

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
<?php
+declare(ticks = 1);
+
require_once dirname(__FILE__).'/../../__init_script__.php';
if (!posix_isatty(STDOUT)) {
diff --git a/src/daemon/PhutilDaemon.php b/src/daemon/PhutilDaemon.php
--- a/src/daemon/PhutilDaemon.php
+++ b/src/daemon/PhutilDaemon.php
@@ -73,7 +73,6 @@
private static $sighandlerInstalled;
final public function __construct(array $argv) {
- declare(ticks = 1);
$this->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",
'<RAMS>',
$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", '<VERB>', $daemon, $message);
+ fprintf(STDERR, "%s %s %s\n", '<VERB>', $daemon, $message);
}
}
+ private static function didCatchSignal($signo) {
+ $signame = phutil_get_signal_name($signo);
+ fprintf(
+ STDERR,
+ "%s Caught signal %s (%s).\n",
+ '<SGNL>',
+ $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;
}

File Metadata

Mime Type
text/plain
Expires
Wed, Oct 16, 11:34 AM (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6717290
Default Alt Text
D15977.id38462.diff (4 KB)

Event Timeline