Avoid infinite loops when the day of the week in cron is out of limits
Former-commit-id: 6c0a87a29818219364fb9c08c44b48cb79dd74a8
This commit is contained in:
parent
e50fb4c585
commit
873525726e
|
@ -2102,6 +2102,12 @@ sub cron_next_execution {
|
||||||
|
|
||||||
# Get day of the week and month from cron config
|
# Get day of the week and month from cron config
|
||||||
my ($wday) = (split (/\s/, $cron))[4];
|
my ($wday) = (split (/\s/, $cron))[4];
|
||||||
|
# Check the wday values to avoid infinite loop
|
||||||
|
my ($wday_down, $wday_up) = cron_get_interval($wday);
|
||||||
|
if ($wday_down ne "*" && ($wday_down > 6 || (defined($wday_up) && $wday_up > 6))) {
|
||||||
|
log_message('setup', "Invalid cron configuration $cron. Day of the week is out of limits.");
|
||||||
|
$wday = "*";
|
||||||
|
}
|
||||||
|
|
||||||
# Get current time and day of the week
|
# Get current time and day of the week
|
||||||
my $cur_time = time();
|
my $cur_time = time();
|
||||||
|
@ -2110,7 +2116,6 @@ sub cron_next_execution {
|
||||||
my $nex_time = cron_next_execution_date ($cron, $cur_time, $interval);
|
my $nex_time = cron_next_execution_date ($cron, $cur_time, $interval);
|
||||||
|
|
||||||
# Check the day
|
# Check the day
|
||||||
print localtime($nex_time)->strftime('%c') . " - OUTSIDE\n";
|
|
||||||
while (!cron_check_interval($wday, (localtime ($nex_time))[6])) {
|
while (!cron_check_interval($wday, (localtime ($nex_time))[6])) {
|
||||||
# If it does not acomplish the day of the week, go to the next day.
|
# If it does not acomplish the day of the week, go to the next day.
|
||||||
$nex_time += 86400;
|
$nex_time += 86400;
|
||||||
|
|
|
@ -83,6 +83,11 @@ function cron_next_execution($cron, $module_interval, $module_id)
|
||||||
$cur_time = ($last_execution !== false) ? $last_execution : time();
|
$cur_time = ($last_execution !== false) ? $last_execution : time();
|
||||||
$nex_time = cron_next_execution_date($cron, $cur_time, $module_interval);
|
$nex_time = cron_next_execution_date($cron, $cur_time, $module_interval);
|
||||||
$nex_wday = (int) date('w', $nex_time);
|
$nex_wday = (int) date('w', $nex_time);
|
||||||
|
// Check the wday values to avoid infinite loop.
|
||||||
|
$wday_int = cron_get_interval($wday);
|
||||||
|
if ($wday_int['down'] !== '*' && ($wday_int['down'] > 6 || ($wday_int['up'] !== false && $wday_int['up'] > 6))) {
|
||||||
|
$wday = '*';
|
||||||
|
}
|
||||||
|
|
||||||
// Check day of the way.
|
// Check day of the way.
|
||||||
while (!cron_check_interval($nex_wday, $wday)) {
|
while (!cron_check_interval($nex_wday, $wday)) {
|
||||||
|
|
|
@ -1360,6 +1360,11 @@ sub cron_next_execution {
|
||||||
|
|
||||||
# Get day of the week and month from cron config
|
# Get day of the week and month from cron config
|
||||||
my ($wday) = (split (/\s/, $cron))[4];
|
my ($wday) = (split (/\s/, $cron))[4];
|
||||||
|
# Check the wday values to avoid infinite loop
|
||||||
|
my ($wday_down, $wday_up) = cron_get_interval($wday);
|
||||||
|
if ($wday_down ne "*" && ($wday_down > 6 || (defined($wday_up) && $wday_up > 6))) {
|
||||||
|
$wday = "*";
|
||||||
|
}
|
||||||
|
|
||||||
# Get current time and day of the week
|
# Get current time and day of the week
|
||||||
my $cur_time = time();
|
my $cur_time = time();
|
||||||
|
|
Loading…
Reference in New Issue