check for function availability before trying to restart

This commit is contained in:
Steffen Schröder 2014-06-15 01:02:59 +02:00
parent 609d451895
commit 6319a6a58a
2 changed files with 30 additions and 1 deletions

View File

@ -246,11 +246,20 @@ class ManiaControl implements CommandListener, TimerListener {
$this->log('Restarting ManiaControl!'); $this->log('Restarting ManiaControl!');
// Execute start script in background // Execute start script in background
// TODO: restart the .php script itself ($_SERVER['scriptname'] or something + $argv)
if (SystemUtil::isUnix()) { if (SystemUtil::isUnix()) {
// Unix
if (!SystemUtil::checkFunctionAvailability('exec')) {
$this->log("Can't restart ManiaControl because the function 'exec' is disabled!");
return;
}
$command = 'sh ' . escapeshellarg(ManiaControlDir . 'ManiaControl.sh') . ' > /dev/null &'; $command = 'sh ' . escapeshellarg(ManiaControlDir . 'ManiaControl.sh') . ' > /dev/null &';
exec($command); exec($command);
} else { } else {
// Windows
if (!SystemUtil::checkFunctionAvailability('system')) {
$this->log("Can't restart ManiaControl because the function 'system' is disabled!");
return;
}
$command = escapeshellarg(ManiaControlDir . "ManiaControl.bat"); $command = escapeshellarg(ManiaControlDir . "ManiaControl.bat");
system($command); // TODO: windows gets stuck here as long controller is running system($command); // TODO: windows gets stuck here as long controller is running
} }

View File

@ -45,4 +45,24 @@ class SystemUtil {
public static function isUnix() { public static function isUnix() {
return (self::getOS() === self::OS_UNIX); return (self::getOS() === self::OS_UNIX);
} }
/**
* Check whether the given Function is available
*
* @param string $functionName
* @return bool
*/
public static function checkFunctionAvailability($functionName) {
return (function_exists($functionName) && !in_array($functionName, self::getDisabledFunctions()));
}
/**
* Get the Array of Disabled Functions
*
* @return array
*/
public static function getDisabledFunctions() {
$disabledText = ini_get('disable_functions');
return explode(',', $disabledText);
}
} }