mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +01: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:
parent
fcb75d0503
commit
5f0535934d
1 changed files with 16 additions and 9 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue