utils.c (nagios-4.4.3) | : | utils.c (nagios-4.4.4) | ||
---|---|---|---|---|
skipping to change at line 1364 | skipping to change at line 1364 | |||
log_debug_info(DEBUGL_FUNCTIONS, 0, "get_next_valid_time()\n"); | log_debug_info(DEBUGL_FUNCTIONS, 0, "get_next_valid_time()\n"); | |||
/* get time right now, preferred time must be now or in the future */ | /* get time right now, preferred time must be now or in the future */ | |||
time(¤t_time); | time(¤t_time); | |||
pref_time = (pref_time < current_time) ? current_time : pref_time; | pref_time = (pref_time < current_time) ? current_time : pref_time; | |||
_get_next_valid_time(pref_time, valid_time, tperiod); | _get_next_valid_time(pref_time, valid_time, tperiod); | |||
} | } | |||
/* Given the next valid time in a timeperiod, the timeperiod itself, and the nor | ||||
mal rescheduling window, */ | ||||
/* return the next check time */ | ||||
time_t reschedule_within_timeperiod(time_t starting_valid_time, timeperiod* chec | ||||
k_period_ptr, time_t check_window) { | ||||
log_debug_info(DEBUGL_FUNCTIONS, 0, "reschedule_within_timeperiod"); | ||||
/* First, find the next time that is outside the timeperiod */ | ||||
time_t ending_valid_time; | ||||
_get_next_invalid_time(starting_valid_time, &ending_valid_time, check_per | ||||
iod_ptr); | ||||
/* _get_next_invalid_time returns the first invalid minute. The maximum a | ||||
llowable should be a minute earlier */ | ||||
ending_valid_time -= 60; | ||||
/* Determine whether the next invalid time or the outside of the check_wi | ||||
ndow is closer */ | ||||
time_t max_nudge = ending_valid_time - starting_valid_time; | ||||
/* max_nudge will be less than zero when there's no 'invalid' time */ | ||||
/* Otherwise, use the closest of the two times to reschedule the check */ | ||||
if (max_nudge <= 0 || max_nudge > check_window) { | ||||
log_debug_info(DEBUGL_CHECKS, 0, "Using raw check_window instead | ||||
of timeperiod for scheduling \n"); | ||||
max_nudge = check_window; | ||||
} | ||||
/* Reschedule within the smaller range */ | ||||
return starting_valid_time + ranged_urand(0, max_nudge); | ||||
} | ||||
/* tests if a date range covers just a single day */ | /* tests if a date range covers just a single day */ | |||
int is_daterange_single_day(daterange *dr) { | int is_daterange_single_day(daterange *dr) { | |||
if(dr == NULL) | if(dr == NULL) | |||
return FALSE; | return FALSE; | |||
if(dr->syear != dr->eyear) | if(dr->syear != dr->eyear) | |||
return FALSE; | return FALSE; | |||
if(dr->smon != dr->emon) | if(dr->smon != dr->emon) | |||
return FALSE; | return FALSE; | |||
skipping to change at line 1542 | skipping to change at line 1570 | |||
return midnight; | return midnight; | |||
} | } | |||
/* get the next time to schedule a log rotation */ | /* get the next time to schedule a log rotation */ | |||
time_t get_next_log_rotation_time(void) { | time_t get_next_log_rotation_time(void) { | |||
time_t current_time; | time_t current_time; | |||
struct tm *t, tm_s; | struct tm *t, tm_s; | |||
int is_dst_now = FALSE; | int is_dst_now = FALSE; | |||
time_t run_time; | time_t run_time; | |||
int expected_mday; | ||||
time(¤t_time); | time(¤t_time); | |||
t = localtime_r(¤t_time, &tm_s); | t = localtime_r(¤t_time, &tm_s); | |||
t->tm_min = 0; | t->tm_min = 0; | |||
t->tm_sec = 0; | t->tm_sec = 0; | |||
is_dst_now = (t->tm_isdst > 0) ? TRUE : FALSE; | is_dst_now = (t->tm_isdst > 0) ? TRUE : FALSE; | |||
switch(log_rotation_method) { | switch(log_rotation_method) { | |||
case LOG_ROTATION_HOURLY: | case LOG_ROTATION_HOURLY: | |||
t->tm_hour++; | t->tm_hour++; | |||
skipping to change at line 1575 | skipping to change at line 1604 | |||
default: | default: | |||
t->tm_mon++; | t->tm_mon++; | |||
t->tm_mday = 1; | t->tm_mday = 1; | |||
t->tm_hour = 0; | t->tm_hour = 0; | |||
run_time = mktime(t); | run_time = mktime(t); | |||
break; | break; | |||
} | } | |||
if(is_dst_now == TRUE && t->tm_isdst == 0) | if(is_dst_now == TRUE && t->tm_isdst == 0) | |||
run_time += 3600; | run_time += 3600; | |||
else if(is_dst_now == FALSE && t->tm_isdst > 0) | ||||
run_time -= 3600; | ||||
return run_time; | return run_time; | |||
} | } | |||
/******************************************************************/ | /******************************************************************/ | |||
/******************** SIGNAL HANDLER FUNCTIONS ********************/ | /******************** SIGNAL HANDLER FUNCTIONS ********************/ | |||
/******************************************************************/ | /******************************************************************/ | |||
/* trap signals so we can exit gracefully */ | /* trap signals so we can exit gracefully */ | |||
void setup_sighandler(void) { | void setup_sighandler(void) { | |||
skipping to change at line 1999 | skipping to change at line 2026 | |||
lseek(lockfile, 0, SEEK_SET); | lseek(lockfile, 0, SEEK_SET); | |||
ftruncate(lockfile, 0); | ftruncate(lockfile, 0); | |||
sprintf(buf, "%d\n", (int)getpid()); | sprintf(buf, "%d\n", (int)getpid()); | |||
write(lockfile, buf, strlen(buf)); | write(lockfile, buf, strlen(buf)); | |||
/* make sure lock file stays open while program is executing... */ | /* make sure lock file stays open while program is executing... */ | |||
val = fcntl(lockfile, F_GETFD, 0); | val = fcntl(lockfile, F_GETFD, 0); | |||
val |= FD_CLOEXEC; | val |= FD_CLOEXEC; | |||
fcntl(lockfile, F_SETFD, val); | fcntl(lockfile, F_SETFD, val); | |||
#ifdef USE_EVENT_BROKER | ||||
/* send program data to broker */ | ||||
broker_program_state(NEBTYPE_PROCESS_DAEMONIZE, NEBFLAG_NONE, NEBATTR_NON | ||||
E, NULL); | ||||
#endif | ||||
return OK; | return OK; | |||
} | } | |||
/******************************************************************/ | /******************************************************************/ | |||
/*********************** SECURITY FUNCTIONS ***********************/ | /*********************** SECURITY FUNCTIONS ***********************/ | |||
/******************************************************************/ | /******************************************************************/ | |||
/* drops privileges */ | /* drops privileges */ | |||
int drop_privileges(char *user, char *group) { | int drop_privileges(char *user, char *group) { | |||
uid_t uid = -1; | uid_t uid = -1; | |||
End of changes. 4 change blocks. | ||||
8 lines changed or deleted | 35 lines changed or added |