mirror of
https://github.com/opnsense/core.git
synced 2026-10-12 02:20:36 +00:00
plugins: add error returns to plugins_configure()
These are not really errors. They indicate a possible issue but should not error. An unknown hook may be normal given that the plugin owning the hook is not installed. We also don't consider hooks to return errors in a meaningful way as they are meant as machinery to run a reconfiguration which can register its own errors elsewhere in the system. But this can give the user running manual queries a useful hint.
This commit is contained in:
@@ -262,6 +262,7 @@ function plugins_configure($hook, $verbose = false, $args = [])
|
||||
{
|
||||
$logargs = [];
|
||||
$glob = '*';
|
||||
$ret = 1; /* no hook executed */
|
||||
|
||||
array_unshift($args, $verbose);
|
||||
|
||||
@@ -318,6 +319,7 @@ function plugins_configure($hook, $verbose = false, $args = [])
|
||||
$argf,
|
||||
implode(',', array_slice($logargs, 0, $argc))
|
||||
), LOG_DEBUG);
|
||||
$ret = 0;
|
||||
try {
|
||||
call_user_func_array($argf, array_slice($args, 0, $argc));
|
||||
} catch (\Error $e) {
|
||||
@@ -328,6 +330,8 @@ function plugins_configure($hook, $verbose = false, $args = [])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function plugins_run($hook, $args = [])
|
||||
|
||||
+5
-1
@@ -344,7 +344,11 @@ if (isset($opts['h'])) {
|
||||
/* second argument is hook */
|
||||
$hook = array_shift($args);
|
||||
/* other arguments are passed as is */
|
||||
plugins_configure($hook, !isset($opts['q']), $args);
|
||||
$ret_int = plugins_configure($hook, !isset($opts['q']), $args);
|
||||
/* cannot taint $ret in this case */
|
||||
if ($ret_int && !isset($opts['q'])) {
|
||||
echo "The configuration hook `$hook' is not known to the system." . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
exit($ret);
|
||||
|
||||
Reference in New Issue
Block a user