diff --git a/src/libs/zbxexpr/interval.c b/src/libs/zbxexpr/interval.c index 05c367a4329..fd59a68126e 100644 --- a/src/libs/zbxexpr/interval.c +++ b/src/libs/zbxexpr/interval.c @@ -1690,7 +1690,7 @@ int zbx_get_report_nextcheck(int now, unsigned char cycle, unsigned char weekday { struct tm *tm; time_t yesterday = now - SEC_PER_DAY; - int nextcheck, tm_hour, tm_min, tm_sec; + int prevcheck = -1, nextcheck, tm_hour, tm_min, tm_sec; if (NULL == (tm = zbx_localtime(&yesterday, tz))) return -1; @@ -1719,9 +1719,17 @@ int zbx_get_report_nextcheck(int now, unsigned char cycle, unsigned char weekday if (0 == weekdays) return -1; zbx_tm_round_up(tm, ZBX_TIME_UNIT_DAY, tz); - + int cntcheck = 0; while (0 == (weekdays & (1 << (tm->tm_wday + 6) % 7))) + { + if(cntcheck++ > 10) + { + zabbix_log(LOG_LEVEL_WARNING, "%s() weekdays loop weekdays=%d tm->tm_wday=%d tz=%s, now=%d start_time=%d cycle=%d", __func__, weekdays, tm->tm_wday, tz, now, start_time, cycle ); + break; + } + zbx_tm_add(tm, 1, ZBX_TIME_UNIT_DAY, tz); + } break; case ZBX_REPORT_CYCLE_DAILY: @@ -1734,6 +1742,12 @@ int zbx_get_report_nextcheck(int now, unsigned char cycle, unsigned char weekday tm->tm_hour = tm_hour; nextcheck = (int)mktime(tm); + if (prevcheck >= nextcheck) + { + zabbix_log(LOG_LEVEL_WARNING, "%s() nextcheck loop prevcheck=%d nextcheck=%d tz=%s now=%d start_time=%d cycle=%d", __func__, prevcheck, nextcheck, tz, now, start_time, cycle); + break; + } + prevcheck = nextcheck; } while (-1 != nextcheck && nextcheck <= now);