Address PHPStan warning and tweak 'tasks'+'interval' handling in 'update_daemon2.php'.

This ensures both are of the expected type (int) and meet a reasonable minimum.
This commit is contained in:
wn_ 2021-11-11 12:11:30 +00:00
parent 7a919a79d7
commit 0f324b77df
1 changed files with 12 additions and 5 deletions

View File

@ -130,7 +130,7 @@
$options = getopt("", $longopts); $options = getopt("", $longopts);
if (isset($options["help"]) ) { if ($options === false || isset($options["help"]) ) {
print "Tiny Tiny RSS update daemon.\n\n"; print "Tiny Tiny RSS update daemon.\n\n";
print "Options:\n"; print "Options:\n";
print " --log FILE - log messages to FILE\n"; print " --log FILE - log messages to FILE\n";
@ -161,21 +161,28 @@
if (isset($options["tasks"])) { if (isset($options["tasks"])) {
Debug::log("Set to spawn " . $options["tasks"] . " children."); Debug::log("Set to spawn " . $options["tasks"] . " children.");
$max_jobs = $options["tasks"]; $max_jobs = (int) $options["tasks"];
} else { } else {
$max_jobs = Config::get(Config::DAEMON_MAX_JOBS); $max_jobs = Config::get(Config::DAEMON_MAX_JOBS);
} }
if ($max_jobs < 1) {
$max_jobs = 1;
Debug::log("Enforced minimum task count of $max_jobs.");
}
if (isset($options["interval"])) { if (isset($options["interval"])) {
Debug::log("Spawn interval: " . $options["interval"] . " seconds."); Debug::log("Spawn interval: " . $options["interval"] . " seconds.");
$spawn_interval = $options["interval"]; $spawn_interval = (int) $options["interval"];
} else { } else {
$spawn_interval = Config::get(Config::DAEMON_SLEEP_INTERVAL); $spawn_interval = Config::get(Config::DAEMON_SLEEP_INTERVAL);
} }
// let's enforce a minimum spawn interval as to not forkbomb the host // let's enforce a minimum spawn interval as to not forkbomb the host
$spawn_interval = max(60, $spawn_interval); if ($spawn_interval < 60) {
Debug::log("Spawn interval: $spawn_interval sec"); $spawn_interval = 60;
Debug::log("Enforced minimum task spawn interval of $spawn_interval seconds.");
}
if (file_is_locked("update_daemon.lock")) { if (file_is_locked("update_daemon.lock")) {
die("error: Can't create lockfile. ". die("error: Can't create lockfile. ".