diff --git a/base/events.c b/base/events.c index d601e970f..bb27b3240 100644 --- a/base/events.c +++ b/base/events.c @@ -351,13 +351,12 @@ void init_timing_loop(void) { */ check_delay = mult_factor * scheduling_info.service_inter_check_delay; - time_t check_window = reschedule_within_timeperiod(next_valid_time, temp_service->check_period_ptr, check_window(temp_service)) - current_time; - if(check_delay > check_window) { + if(check_delay > check_window(temp_service)) { log_debug_info(DEBUGL_EVENTS, 0, " Fixing check time %lu secs too far away\n", - check_delay - check_window); + check_delay - check_window(temp_service)); fixed_services++; - check_delay = check_window; + check_delay = check_window(temp_service); log_debug_info(DEBUGL_EVENTS, 0, " New check offset: %d\n", check_delay); } @@ -370,7 +369,8 @@ void init_timing_loop(void) { if(is_valid_time == ERROR) { log_debug_info(DEBUGL_EVENTS, 2, "Preferred Time is Invalid In Timeperiod '%s': %lu --> %s\n", temp_service->check_period_ptr->name, (unsigned long)temp_service->next_check, ctime(&temp_service->next_check)); get_next_valid_time(temp_service->next_check, &next_valid_time, temp_service->check_period_ptr); - temp_service->next_check = reschedule_within_timeperiod(next_valid_time, temp_service->check_period_ptr, check_window(temp_service)); + temp_service->next_check = + (time_t)(next_valid_time + check_delay); } log_debug_info(DEBUGL_EVENTS, 2, "Actual Check Time: %lu --> %s\n", (unsigned long)temp_service->next_check, ctime(&temp_service->next_check)); @@ -508,7 +508,7 @@ void init_timing_loop(void) { log_debug_info(DEBUGL_EVENTS, 1, "Fixing check time (off by %lu)\n", check_delay - check_window(temp_host)); fixed_hosts++; - check_delay = reschedule_within_timeperiod(next_valid_time, temp_host->check_period_ptr, check_window(temp_host)); + check_delay = ranged_urand(0, check_window(temp_host)); } temp_host->next_check = (time_t)(current_time + check_delay); diff --git a/cgi/status.c b/cgi/status.c index ae723c683..2f6a60fde 100644 --- a/cgi/status.c +++ b/cgi/status.c @@ -221,8 +221,26 @@ int main(void) { document_header(TRUE); /* if a navbar search was performed, find the host by name, address or partial name */ - if(navbar_search == TRUE) { - if(host_name != NULL && NULL != strstr(host_name, "*")) { + if(navbar_search == TRUE && host_name != NULL) { + + /* Remove trailing spaces from host_name */ + len = strlen(host_name); + for (i = len - 1; i >= 0; i--) { + if (!isspace(host_name[i])) { + host_name[i+1] = '\0'; + break; + } + } + + /* Remove leading spaces from host_name */ + for (i = 0; i < len; i++) { + if (!isspace(host_name[i])) { + break; + } + } + strcpy(host_name, host_name + i); + + if(NULL != strstr(host_name, "*")) { /* allocate for 3 extra chars, ^, $ and \0 */ host_filter = malloc(sizeof(char) * (strlen(host_name) * 2 + 3)); len = strlen(host_name); @@ -238,7 +256,7 @@ int main(void) { host_filter[regex_i++] = '$'; host_filter[regex_i] = '\0'; } - else if (host_name != NULL) { + else { if((temp_host = find_host(host_name)) == NULL) { for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) { if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE) diff --git a/lib/worker.c b/lib/worker.c index 4f7cbc384..a94719cc4 100644 --- a/lib/worker.c +++ b/lib/worker.c @@ -215,7 +215,7 @@ int worker_buf2kvvec_prealloc(struct kvvec *kvv, char *buf, unsigned long len, i } while (0) /* forward declaration */ -static int gather_output(child_process *cp, iobuf *io, int final); +static void gather_output(child_process *cp, iobuf *io, int final); static void destroy_job(child_process *cp) { @@ -258,23 +258,15 @@ static void destroy_job(child_process *cp) int finish_job(child_process *cp, int reason) { static struct kvvec resp = KVVEC_INITIALIZER; - int i, ret, rd; + int i, ret; /* get rid of still open filedescriptors */ if (cp->outstd.fd != -1) { - - rd = 1; - while(rd > 0) { - rd = gather_output(cp, &cp->outstd, 0); - } + gather_output(cp, &cp->outstd, 1); iobroker_close(iobs, cp->outstd.fd); } if (cp->outerr.fd != -1) { - - rd = 1; - while(rd > 0) { - rd = gather_output(cp, &cp->outerr, 0); - } + gather_output(cp, &cp->outerr, 1); iobroker_close(iobs, cp->outerr.fd); } @@ -450,13 +442,13 @@ static void kill_job(child_process *cp, int reason) destroy_job(cp); } -static int gather_output(child_process *cp, iobuf *io, int final) +static void gather_output(child_process *cp, iobuf *io, int final) { int retry = 5; - int rd; for (;;) { char buf[4096]; + int rd; rd = read(io->fd, buf, sizeof(buf)); if (rd < 0) { @@ -492,13 +484,13 @@ static int gather_output(child_process *cp, iobuf *io, int final) if (rd <= 0 || final) { iobroker_close(iobs, io->fd); io->fd = -1; + if (!final) + check_completion(cp, WNOHANG); break; } break; } - - return rd; }