Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/PhabricatorDaemon.php
| Show All 28 Lines | abstract class PhabricatorDaemon extends PhutilDaemon { | ||||
| */ | */ | ||||
| public static function sudoCommandAsDaemonUser($command) { | public static function sudoCommandAsDaemonUser($command) { | ||||
| $user = PhabricatorEnv::getEnvConfig('phd.user'); | $user = PhabricatorEnv::getEnvConfig('phd.user'); | ||||
| if (!$user) { | if (!$user) { | ||||
| // No daemon user is set, so just run this as ourselves. | // No daemon user is set, so just run this as ourselves. | ||||
| return $command; | return $command; | ||||
| } | } | ||||
| // We may reach this method while already running as the daemon user: for | |||||
| // example, active and passive synchronization of clustered repositories | |||||
| // run the same commands through the same code, but as different users. | |||||
| // By default, `sudo` won't let you sudo to yourself, so we can get into | |||||
| // trouble if we're already running as the daemon user unless the host has | |||||
| // been configured to let the daemon user run commands as itself. | |||||
| // Since this is silly and more complicated than doing this check, don't | |||||
| // use `sudo` if we're already running as the correct user. | |||||
| if (function_exists('posix_getuid')) { | |||||
| $uid = posix_getuid(); | |||||
| $info = posix_getpwuid($uid); | |||||
| if ($info && $info['name'] == $user) { | |||||
| return $command; | |||||
| } | |||||
| } | |||||
| // Get the absolute path so we're safe against the caller wiping out | // Get the absolute path so we're safe against the caller wiping out | ||||
| // PATH. | // PATH. | ||||
| $sudo = Filesystem::resolveBinary('sudo'); | $sudo = Filesystem::resolveBinary('sudo'); | ||||
| if (!$sudo) { | if (!$sudo) { | ||||
| throw new Exception(pht("Unable to find 'sudo'!")); | throw new Exception(pht("Unable to find 'sudo'!")); | ||||
| } | } | ||||
| // Flags here are: | // Flags here are: | ||||
| Show All 9 Lines | |||||