Skip to content

Commit

Permalink
Merge branch 'cleanup_warnings' of https://github.com/dougnazar/nagio…
Browse files Browse the repository at this point in the history
…score into dougnazar-cleanup_warnings
  • Loading branch information
Sebastian Wolf committed Apr 21, 2023
2 parents 459730e + 587d19e commit 03c2375
Show file tree
Hide file tree
Showing 24 changed files with 114 additions and 177 deletions.
38 changes: 0 additions & 38 deletions base/checks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,44 +1092,6 @@ static inline void host_propagate_checks_to_immediate_children(host * hst, int c
/******************************************************************************
******* Logic chunks propagating dependency checks
*****************************************************************************/
static inline void service_propagate_dependency_checks(service * svc, time_t current_time)
{
if (svc->current_attempt == (svc->max_attempts - 1)
&& execute_service_checks == TRUE
&& enable_predictive_service_dependency_checks == TRUE) {

servicedependency *temp_dependency = NULL;
service *master_service = NULL;
objectlist *list;

log_debug_info(DEBUGL_CHECKS, 1, "Propagating predictive dependency checks to services this one depends on...\n");

/* check services that THIS ONE depends on for notification AND execution */
/* we do this because we might be sending out a notification soon and we want the dependency logic to be accurate */
for(list = svc->exec_deps; list; list = list->next) {
temp_dependency = (servicedependency *)list->object_ptr;
if (temp_dependency->dependent_service_ptr == svc && temp_dependency->master_service_ptr != NULL) {

master_service = (service *)temp_dependency->master_service_ptr;

log_debug_info(DEBUGL_CHECKS, 2, "Predictive check of service '%s' on host '%s' queued.\n", master_service->description, master_service->host_name);
schedule_service_check(master_service, current_time, CHECK_OPTION_DEPENDENCY_CHECK);
}
}

for(list = svc->notify_deps; list; list = list->next) {
temp_dependency = (servicedependency *)list->object_ptr;
if (temp_dependency->dependent_service_ptr == svc && temp_dependency->master_service_ptr != NULL) {

master_service = (service *)temp_dependency->master_service_ptr;

log_debug_info(DEBUGL_CHECKS, 2, "Predictive check of service '%s' on host '%s' queued.\n", master_service->description, master_service->host_name);
schedule_service_check(master_service, current_time, CHECK_OPTION_DEPENDENCY_CHECK);
}
}
}
}
/*****************************************************************************/
static inline void host_propagate_dependency_checks(host * hst, time_t current_time)
{
/* we do to help ensure that the dependency checks are accurate before it comes time to notify */
Expand Down
2 changes: 1 addition & 1 deletion base/nagios.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static void set_loadctl_defaults(void)
static int test_path_access(const char *program, int mode)
{
char *envpath, *p, *colon;
int ret, our_errno = 1500; /* outside errno range */
int ret = 0, our_errno = 1500; /* outside errno range */

if (program[0] == '/' || !(envpath = getenv("PATH")))
return access(program, mode);
Expand Down
2 changes: 1 addition & 1 deletion base/nagiostats.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
static char *main_config_file = NULL;
char *status_file = NULL;
static char *mrtg_variables = NULL;
static const char *mrtg_delimiter = NULL;
static char *mrtg_delimiter = NULL;

static int mrtg_mode = FALSE;

Expand Down
30 changes: 18 additions & 12 deletions base/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,7 @@ int drop_privileges(char *user, char *group) {
/******************************************************************/

/* processes files in the check result queue directory */
int process_check_result_queue(char *dirname) {
int process_check_result_queue(const char *dirname) {
char file[MAX_FILENAME_LENGTH];
DIR *dirp = NULL;
struct dirent *dirfile = NULL;
Expand All @@ -2176,6 +2176,7 @@ int process_check_result_queue(char *dirname) {
char *temp_buffer = NULL;
int result = OK, check_result_files = 0;
time_t start;
int ofs = 0;

/* make sure we have what we need */
if(dirname == NULL) {
Expand All @@ -2193,6 +2194,11 @@ int process_check_result_queue(char *dirname) {

start = time(NULL);

strncpy(file, dirname, sizeof(file));
file[sizeof(file) - 1] = '\0';
ensure_path_separator(file, sizeof(file));
ofs = strlen(file);

/* process all files in the directory... */
while((dirfile = readdir(dirp)) != NULL) {

Expand All @@ -2208,9 +2214,12 @@ int process_check_result_queue(char *dirname) {
break;
}

/* skip if it's too long */
if (ofs + strlen(dirfile->d_name) + 1 > sizeof(file))
continue;

/* create /path/to/file */
snprintf(file, sizeof(file), "%s/%s", dirname, dirfile->d_name);
file[sizeof(file) - 1] = '\x0';
strncpy(file + ofs, dirfile->d_name, sizeof(file) - ofs);

/* process this if it's a check result file...
remember it needs to be in the format of
Expand Down Expand Up @@ -2319,7 +2328,7 @@ int process_check_result(check_result *cr)
/* static char *unescape_check_result_file_output(char*); */

/* reads check result(s) from a file */
int process_check_result_file(char *fname)
int process_check_result_file(const char *fname)
{
mmapfile *thefile = NULL;
char *input = NULL;
Expand Down Expand Up @@ -2522,7 +2531,7 @@ int process_check_result_file(char *fname)


/* deletes as check result file, as well as its ok-to-go file */
int delete_check_result_file(char *fname)
int delete_check_result_file(const char *fname)
{
char *temp_buffer = NULL;
int result = OK;
Expand Down Expand Up @@ -2797,7 +2806,7 @@ int my_rename(char *source, char *dest) {
*/
int my_fdcopy(char *source, char *dest, int dest_fd) {
int source_fd, rd_result = 0, wr_result = 0;
int tot_written = 0, tot_read = 0, buf_size = 0;
int tot_written = 0, buf_size = 0;
struct stat st;
char *buf;

Expand Down Expand Up @@ -2844,7 +2853,6 @@ int my_fdcopy(char *source, char *dest, int dest_fd) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: my_fcopy() failed to read from '%s': %s\n", source, strerror(errno));
break;
}
tot_read += rd_result;

while(loop_wr < rd_result) {
wr_result = write(dest_fd, buf + loop_wr, rd_result - loop_wr);
Expand Down Expand Up @@ -3286,7 +3294,7 @@ int check_for_nagios_updates(int force, int reschedule) {
/* we didn't do an update, so calculate next possible update time */
if(do_check == FALSE) {
next_check = last_update_check + BASE_UPDATE_CHECK_INTERVAL;
next_check = next_check + (unsigned long)(((float)randnum / RAND_MAX) * UPDATE_CHECK_INTERVAL_WOBBLE);
next_check = next_check + (unsigned long)(((float)randnum / (float)RAND_MAX) * UPDATE_CHECK_INTERVAL_WOBBLE);
}

/* we tried to check for an update */
Expand All @@ -3295,13 +3303,13 @@ int check_for_nagios_updates(int force, int reschedule) {
/* api query was okay */
if(api_result == OK) {
next_check = current_time + BASE_UPDATE_CHECK_INTERVAL;
next_check += (unsigned long)(((float)randnum / RAND_MAX) * UPDATE_CHECK_INTERVAL_WOBBLE);
next_check += (unsigned long)(((float)randnum / (float)RAND_MAX) * UPDATE_CHECK_INTERVAL_WOBBLE);
}

/* query resulted in an error - retry at a shorter interval */
else {
next_check = current_time + BASE_UPDATE_CHECK_RETRY_INTERVAL;
next_check += (unsigned long)(((float)randnum / RAND_MAX) * UPDATE_CHECK_RETRY_INTERVAL_WOBBLE);
next_check += (unsigned long)(((float)randnum / (float)RAND_MAX) * UPDATE_CHECK_RETRY_INTERVAL_WOBBLE);
}
}

Expand Down Expand Up @@ -3330,7 +3338,6 @@ int query_update_api(void) {
char recv_buf[1024];
int report_install = FALSE;
char *ptr = NULL;
int current_line = 0;
int buf_index = 0;
int in_header = TRUE;
char *var = NULL;
Expand Down Expand Up @@ -3419,7 +3426,6 @@ int query_update_api(void) {
while((ptr = get_next_string_from_buf(recv_buf, &buf_index, sizeof(recv_buf)))) {

strip(ptr);
current_line++;

if(!strcmp(ptr, "")) {
in_header = FALSE;
Expand Down
22 changes: 6 additions & 16 deletions base/wpres-phash.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* C code produced by gperf version 3.0.3 */
/* ANSI-C code produced by gperf version 3.1 */
/* Command-line: gperf -S 1 -t -H wpres_key_phash -N wpres_get_key wpres.gperf */
/* Computed positions: -k'4-5,7' */

Expand Down Expand Up @@ -26,7 +26,7 @@
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
/* The character set is not based on ISO-646. */
error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu[email protected]>."
#error "gperf generated tables don't work with this execution character set. Please report a bug to <[email protected]>."
#endif

#line 1 "wpres.gperf"
Expand Down Expand Up @@ -84,9 +84,7 @@ inline
#endif
#endif
static unsigned int
wpres_key_phash (str, len)
register const char *str;
register unsigned int len;
wpres_key_phash (register const char *str, register size_t len)
{
static unsigned char asso_values[] =
{
Expand Down Expand Up @@ -117,7 +115,7 @@ wpres_key_phash (str, len)
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65
};
register int hval = len;
register unsigned int hval = len;

switch (hval)
{
Expand All @@ -135,16 +133,8 @@ wpres_key_phash (str, len)
return hval;
}

#ifdef __GNUC__
__inline
#ifdef __GNUC_STDC_INLINE__
__attribute__ ((__gnu_inline__))
#endif
#endif
struct wpres_key *
wpres_get_key (str, len)
register const char *str;
register unsigned int len;
wpres_get_key (register const char *str, register size_t len)
{
static struct wpres_key wordlist[] =
{
Expand Down Expand Up @@ -210,7 +200,7 @@ wpres_get_key (str, len)

if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = wpres_key_phash (str, len);
register unsigned int key = wpres_key_phash (str, len);

if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
{
Expand Down
58 changes: 26 additions & 32 deletions cgi/cgiutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,21 @@ static command *find_bang_command(char *name)
return cmd;
}

/*
* build path with prefix (must already be / terminated) and a subdir
*/
void build_subdir_path(char* path, size_t size, const char* prefix, const char* subdir)
{
const size_t prefix_len = strlen(prefix);
const size_t subdir_len = strlen(subdir);

if (prefix_len + subdir_len >= size)
return;

memcpy(path, prefix, prefix_len);
memcpy(path + prefix_len, subdir, subdir_len);
path[prefix_len + subdir_len] = '\0';
}

/**********************************************************
***************** CLEANUP FUNCTIONS **********************
Expand Down Expand Up @@ -329,14 +343,10 @@ int read_cgi_config_file(const char *filename, read_config_callback callback) {
strncpy(physical_html_path, val, sizeof(physical_html_path));
physical_html_path[sizeof(physical_html_path) - 1] = '\x0';
strip(physical_html_path);
if(physical_html_path[strlen(physical_html_path) - 1] != '/' && (strlen(physical_html_path) < sizeof(physical_html_path) - 1))
strcat(physical_html_path, "/");
ensure_path_separator(physical_html_path, sizeof(physical_html_path));

snprintf(physical_images_path, sizeof(physical_images_path), "%simages/", physical_html_path);
physical_images_path[sizeof(physical_images_path) - 1] = '\x0';

snprintf(physical_ssi_path, sizeof(physical_images_path), "%sssi/", physical_html_path);
physical_ssi_path[sizeof(physical_ssi_path) - 1] = '\x0';
build_subdir_path(physical_images_path, sizeof(physical_images_path), physical_html_path, "images/");
build_subdir_path(physical_ssi_path, sizeof(physical_ssi_path), physical_html_path, "ssi/");
}

else if(!strcmp(var, "url_html_path")) {
Expand All @@ -345,31 +355,15 @@ int read_cgi_config_file(const char *filename, read_config_callback callback) {
url_html_path[sizeof(url_html_path) - 1] = '\x0';

strip(url_html_path);
if(url_html_path[strlen(url_html_path) - 1] != '/' && (strlen(url_html_path) < sizeof(url_html_path) - 1))
strcat(url_html_path, "/");

snprintf(url_docs_path, sizeof(url_docs_path), "%sdocs/", url_html_path);
url_docs_path[sizeof(url_docs_path) - 1] = '\x0';

snprintf(url_context_help_path, sizeof(url_context_help_path), "%scontexthelp/", url_html_path);
url_context_help_path[sizeof(url_context_help_path) - 1] = '\x0';

snprintf(url_images_path, sizeof(url_images_path), "%simages/", url_html_path);
url_images_path[sizeof(url_images_path) - 1] = '\x0';

snprintf(url_logo_images_path, sizeof(url_logo_images_path), "%slogos/", url_images_path);
url_logo_images_path[sizeof(url_logo_images_path) - 1] = '\x0';

snprintf(url_stylesheets_path, sizeof(url_stylesheets_path), "%sstylesheets/", url_html_path);
url_stylesheets_path[sizeof(url_stylesheets_path) - 1] = '\x0';

snprintf(url_media_path, sizeof(url_media_path), "%smedia/", url_html_path);
url_media_path[sizeof(url_media_path) - 1] = '\x0';

/* added JS directory 2/1/2012 -MG */
snprintf(url_js_path, sizeof(url_js_path), "%sjs/", url_html_path);
url_js_path[sizeof(url_js_path) - 1] = '\x0';

ensure_path_separator(url_html_path, sizeof(url_html_path));

build_subdir_path(url_docs_path, sizeof(url_docs_path), url_html_path, "docs/");
build_subdir_path(url_context_help_path, sizeof(url_context_help_path), url_html_path, "contexthelp/");
build_subdir_path(url_images_path, sizeof(url_images_path), url_html_path, "images/");
build_subdir_path(url_logo_images_path, sizeof(url_logo_images_path), url_html_path, "logos/");
build_subdir_path(url_stylesheets_path, sizeof(url_stylesheets_path), url_html_path, "stylesheets/");
build_subdir_path(url_media_path, sizeof(url_media_path), url_html_path, "media/");
build_subdir_path(url_js_path, sizeof(url_js_path), url_html_path, "js/");
}

else if(!strcmp(var, "service_critical_sound"))
Expand Down
2 changes: 1 addition & 1 deletion cgi/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ void display_timeperiods(void) {
int day = 0;
int x = 0;
const char *bg_class = "";
char timestring[10];
char timestring[32];
int hours = 0;
int minutes = 0;
int seconds = 0;
Expand Down
12 changes: 0 additions & 12 deletions cgi/extinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1963,13 +1963,11 @@ void show_performance_data(void) {
int active_service_checks_15min = 0;
int active_service_checks_1hour = 0;
int active_service_checks_start = 0;
int active_service_checks_ever = 0;
int passive_service_checks_1min = 0;
int passive_service_checks_5min = 0;
int passive_service_checks_15min = 0;
int passive_service_checks_1hour = 0;
int passive_service_checks_start = 0;
int passive_service_checks_ever = 0;
int total_active_host_checks = 0;
int total_passive_host_checks = 0;
double min_host_execution_time = 0.0;
Expand All @@ -1992,13 +1990,11 @@ void show_performance_data(void) {
int active_host_checks_15min = 0;
int active_host_checks_1hour = 0;
int active_host_checks_start = 0;
int active_host_checks_ever = 0;
int passive_host_checks_1min = 0;
int passive_host_checks_5min = 0;
int passive_host_checks_15min = 0;
int passive_host_checks_1hour = 0;
int passive_host_checks_start = 0;
int passive_host_checks_ever = 0;
time_t current_time;


Expand Down Expand Up @@ -2059,8 +2055,6 @@ void show_performance_data(void) {
active_service_checks_1hour++;
if(temp_servicestatus->last_check >= program_start)
active_service_checks_start++;
if(temp_servicestatus->last_check != (time_t)0)
active_service_checks_ever++;
}

else {
Expand All @@ -2086,8 +2080,6 @@ void show_performance_data(void) {
passive_service_checks_1hour++;
if(temp_servicestatus->last_check >= program_start)
passive_service_checks_start++;
if(temp_servicestatus->last_check != (time_t)0)
passive_service_checks_ever++;
}
}

Expand Down Expand Up @@ -2146,8 +2138,6 @@ void show_performance_data(void) {
active_host_checks_1hour++;
if(temp_hoststatus->last_check >= program_start)
active_host_checks_start++;
if(temp_hoststatus->last_check != (time_t)0)
active_host_checks_ever++;
}

else {
Expand All @@ -2173,8 +2163,6 @@ void show_performance_data(void) {
passive_host_checks_1hour++;
if(temp_hoststatus->last_check >= program_start)
passive_host_checks_start++;
if(temp_hoststatus->last_check != (time_t)0)
passive_host_checks_ever++;
}
}

Expand Down
Loading

0 comments on commit 03c2375

Please sign in to comment.