Changeset View
Standalone View
src/filesystem/PhutilProcessRef.php
<?php | <?php | ||||
final class PhutilProcessRef | final class PhutilProcessRef | ||||
extends Phobject { | extends Phobject { | ||||
private $pid; | private $pid; | ||||
private $command; | private $command; | ||||
private $isOverseer; | private $isOverseer; | ||||
private $instance; | private $instance; | ||||
private $argv; | |||||
public function setPID($pid) { | public function setPID($pid) { | ||||
$this->pid = $pid; | $this->pid = $pid; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getPID() { | public function getPID() { | ||||
return $this->pid; | return $this->pid; | ||||
} | } | ||||
public function setCommand($command) { | public function getCommand() { | ||||
$this->command = $command; | if (!$this->command) { | ||||
return $this; | $this->command = phutil_string_cast(csprintf('%LR', $this->argv)); | ||||
} | } | ||||
public function getCommand() { | |||||
return $this->command; | return $this->command; | ||||
} | } | ||||
public function setIsOverseer($is_overseer) { | public function getIsOverseer() { | ||||
$this->isOverseer = $is_overseer; | if ($this->isOverseer === null) { | ||||
return $this; | $this->isOverseer = $this->getCommandMatch( | ||||
array( | |||||
array('phd-daemon'), | |||||
array('php', 'phd-daemon'), | |||||
amckinley: Is the HHVM binary also called `php`? What if someone uses a `start_phabricator.go` file that… | |||||
Done Inline ActionsThe "php" comes from the #!/usr/bin/env php shebang line in the phd-daemon file. I believe you'd have to aggressively try to inject misbehavior here to break anything. For example, if I symlink quack to php and then use #!/usr/bin/env quack, the process comes up named "quack" -- so I suspect this is robust even in the face of php -> php5 or similar. If not, we may need to add more patterns here, but we can cross that bridge when we come to it. Although I'm not sure my testing is exhaustive, I can't find any way to change the process title under macOS as long as some parent process runs bin/phd start. Some stuff I tried:
These all ultimately produce a process with the same name. It's definitely possible there's some other trick here, but I wasn't able to find one anywhere near the beaten path. Obviously, you can do something other than bin/phd start to start a daemon process that has a different process title, but I think it's fair to say "if you don't use bin/phd start to start the process, you should not expect bin/phd status/restart/etc to manage it". epriestley: The "php" comes from the `#!/usr/bin/env php` shebang line in the `phd-daemon` file. I believe… | |||||
)); | |||||
} | } | ||||
public function getIsOverseer() { | |||||
return $this->isOverseer; | return $this->isOverseer; | ||||
} | } | ||||
public function setInstance($instance) { | public function setInstance($instance) { | ||||
$this->instance = $instance; | $this->instance = $instance; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getInstance() { | public function getInstance() { | ||||
return $this->instance; | return $this->instance; | ||||
} | } | ||||
private function getCommandMatch(array $patterns) { | |||||
$argv = $this->getArgv(); | |||||
foreach ($patterns as $pattern) { | |||||
$pattern = array_values($pattern); | |||||
$is_match = true; | |||||
for ($ii = 0; $ii < count($pattern); $ii++) { | |||||
if (basename($argv[$ii]) !== $pattern[$ii]) { | |||||
$is_match = false; | |||||
break; | |||||
} | |||||
} | |||||
if ($is_match) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
public function setArgv(array $argv) { | |||||
$this->argv = $argv; | |||||
return $this; | |||||
} | |||||
public function getArgv() { | |||||
return $this->argv; | |||||
} | |||||
} | } |
Is the HHVM binary also called php? What if someone uses a start_phabricator.go file that does fork/exec to start the daemons?