1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Manage PIDs more carefully in DaemonHandle

Summary:
Ref T13555. Although these callsites may not actually impact anything, it's possible for an active handle to have no PID (e.g., if the subprocess failed to start).

Handle these cases more carefully.

Test Plan: Started daemons, saw them run fine. See also next change.

Maniphest Tasks: T13555

Differential Revision: https://secure.phabricator.com/D21424
This commit is contained in:
epriestley 2020-07-23 09:27:14 -07:00
parent fcb75d0503
commit 5f0535934d

View file

@ -327,13 +327,14 @@ final class PhutilDaemonHandle extends Phobject {
private function annihilateProcessGroup() {
$pid = $this->getPID();
$pgid = posix_getpgid($pid);
if ($pid && $pgid) {
posix_kill(-$pgid, SIGTERM);
sleep($this->getKillDelay());
posix_kill(-$pgid, SIGKILL);
$this->pid = null;
if ($pid) {
$pgid = posix_getpgid($pid);
if ($pgid) {
posix_kill(-$pgid, SIGTERM);
sleep($this->getKillDelay());
posix_kill(-$pgid, SIGKILL);
$this->pid = null;
}
}
}
@ -440,7 +441,10 @@ final class PhutilDaemonHandle extends Phobject {
// naturally be restarted after it exits, as though it had exited after an
// unhandled exception.
posix_kill($this->getPID(), SIGINT);
$pid = $this->getPID();
if ($pid) {
posix_kill($pid, SIGINT);
}
}
public function didReceiveGracefulSignal($signo) {
@ -461,7 +465,10 @@ final class PhutilDaemonHandle extends Phobject {
$this->logMessage('DONE', $sigmsg, $signo);
posix_kill($this->getPID(), SIGINT);
$pid = $this->getPID();
if ($pid) {
posix_kill($pid, SIGINT);
}
}
public function didReceiveTerminateSignal($signo) {