Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package cacti-spine for openSUSE:Factory checked in at 2022-10-03 13:46:34 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/cacti-spine (Old) and /work/SRC/openSUSE:Factory/.cacti-spine.new.2275 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "cacti-spine" Mon Oct 3 13:46:34 2022 rev:37 rq:1007576 version:1.2.22 Changes: -------- --- /work/SRC/openSUSE:Factory/cacti-spine/cacti-spine.changes 2022-05-30 12:44:20.664421993 +0200 +++ /work/SRC/openSUSE:Factory/.cacti-spine.new.2275/cacti-spine.changes 2022-10-03 13:47:22.509694340 +0200 @@ -1,0 +2,11 @@ +Sun Oct 2 18:13:33 UTC 2022 - Andreas Stieger <andreas.stie...@gmx.de> + +- cacti-spine 1.2.22, delivering a number of bug fixes: + * When polling time is exceed, spine does not always exit as expected + * Spine logging at `-V 5` includes an extra line feed + * Incorrect SNMP responses can cause spine to crash + * Properly handle devices that timeout responding to the Extended Uptime + * MariaDB can cause spine to abort prematurely despite error handling + * Spine should log the error time when exiting via signal + +------------------------------------------------------------------- Old: ---- cacti-spine-1.2.21.tar.gz New: ---- cacti-spine-1.2.22.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ cacti-spine.spec ++++++ --- /var/tmp/diff_new_pack.sPs06F/_old 2022-10-03 13:47:23.013695449 +0200 +++ /var/tmp/diff_new_pack.sPs06F/_new 2022-10-03 13:47:23.017695457 +0200 @@ -18,7 +18,7 @@ %{!?make_build: %define make_build make %{?_smp_mflags}} Name: cacti-spine -Version: 1.2.21 +Version: 1.2.22 Release: 0 Summary: Threaded poller for Cacti written in C License: LGPL-2.1-or-later ++++++ cacti-spine-1.2.21.tar.gz -> cacti-spine-1.2.22.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.21/CHANGELOG new/cacti-spine-1.2.22/CHANGELOG --- old/cacti-spine-1.2.21/CHANGELOG 2022-05-18 23:20:59.000000000 +0200 +++ new/cacti-spine-1.2.22/CHANGELOG 2022-08-14 23:44:27.000000000 +0200 @@ -1,5 +1,13 @@ The Cacti Group | spine +1.2.22 +-issue#269: When polling time is exceed, spine does not always exit as expected +-issue#270: Spine logging at `-V 5` includes an extra line feed +-issue#271: Incorrect SNMP responses can cause spine to crash +-issue#272: Properly handle devices that timeout responding to the Extended Uptime +-issue#274: MariaDB can cause spine to abort prematurely despite error handling +-feature#273: Spine should log the error time when exiting via signal + 1.2.21 -issue#258: Disable DES if Net-SNMP doesn't have it diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.21/configure.ac new/cacti-spine-1.2.22/configure.ac --- old/cacti-spine-1.2.21/configure.ac 2022-05-18 23:20:59.000000000 +0200 +++ new/cacti-spine-1.2.22/configure.ac 2022-08-14 23:44:27.000000000 +0200 @@ -1,5 +1,5 @@ AC_PREREQ([2.63]) -AC_INIT([Spine Poller],[1.2.21],[http://www.cacti.net/issues.php]) +AC_INIT([Spine Poller],[1.2.22],[http://www.cacti.net/issues.php]) AC_CONFIG_AUX_DIR(config) AC_SUBST(ac_aux_dir) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.21/error.c new/cacti-spine-1.2.22/error.c --- old/cacti-spine-1.2.21/error.c 2022-05-18 23:20:59.000000000 +0200 +++ new/cacti-spine-1.2.22/error.c 2022-08-14 23:44:27.000000000 +0200 @@ -48,15 +48,32 @@ set.exit_code = spine_signal; + /* variables for time display */ + time_t nowbin; + struct tm now_time; + struct tm *now_ptr; + struct timeval now; + + /* get time for poller_output table */ + nowbin = time(&nowbin); + + localtime_r(&nowbin,&now_time); + now_ptr = &now_time; + + char *log_fmt = get_date_format(); + char logtime[50]; + + strftime(logtime, 50, log_fmt, now_ptr); + switch (spine_signal) { case SIGABRT: - fprintf(stderr, "FATAL: Spine Interrupted by Abort Signal\n"); + fprintf(stderr, "%s FATAL: Spine Interrupted by Abort Signal\n", logtime); break; case SIGINT: - fprintf(stderr, "FATAL: Spine Interrupted by Console Operator\n"); + fprintf(stderr, "%s FATAL: Spine Interrupted by Console Operator\n", logtime); break; case SIGSEGV: - fprintf(stderr, "FATAL: Spine Encountered a Segmentation Fault\n"); + fprintf(stderr, "%s FATAL: Spine Encountered a Segmentation Fault\n", logtime); #ifdef HAVE_EXECINFO_H int row = 0; @@ -82,19 +99,19 @@ break; case SIGBUS: - fprintf(stderr, "FATAL: Spine Encountered a Bus Error\n"); + fprintf(stderr, "%s FATAL: Spine Encountered a Bus Error\n", logtime); break; case SIGFPE: - fprintf(stderr, "FATAL: Spine Encountered a Floating Point Exception\n"); + fprintf(stderr, "%s FATAL: Spine Encountered a Floating Point Exception\n", logtime); break; case SIGQUIT: - fprintf(stderr, "FATAL: Spine Encountered a Keyboard Quit Command\n"); + fprintf(stderr, "%s FATAL: Spine Encountered a Keyboard Quit Command\n", logtime); break; case SIGPIPE: - fprintf(stderr, "FATAL: Spine Encountered a Broken Pipe\n"); + fprintf(stderr, "%s FATAL: Spine Encountered a Broken Pipe\n", logtime); break; default: - fprintf(stderr, "FATAL: Spine Encountered An Unhandled Exception Signal Number: '%d'\n", spine_signal); + fprintf(stderr, "%s FATAL: Spine Encountered An Unhandled Exception Signal Number: '%d'\n", logtime, spine_signal); break; } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.21/locks.c new/cacti-spine-1.2.22/locks.c --- old/cacti-spine-1.2.21/locks.c 2022-05-18 23:20:59.000000000 +0200 +++ new/cacti-spine-1.2.22/locks.c 2022-08-14 23:44:27.000000000 +0200 @@ -71,6 +71,7 @@ DEFINE_SPINE_LOCK(php_proc_13) DEFINE_SPINE_LOCK(php_proc_14) DEFINE_SPINE_LOCK(thdet) +DEFINE_SPINE_LOCK(host_time) void init_mutexes() { pthread_once((pthread_once_t*) get_attr(LOCK_SNMP_O), init_snmp_lock); @@ -95,6 +96,7 @@ pthread_once((pthread_once_t*) get_attr(LOCK_PHP_PROC_13_O), init_php_proc_13_lock); pthread_once((pthread_once_t*) get_attr(LOCK_PHP_PROC_14_O), init_php_proc_14_lock); pthread_once((pthread_once_t*) get_attr(LOCK_THDET_O), init_thdet_lock); + pthread_once((pthread_once_t*) get_attr(LOCK_HOST_TIME_O), init_host_time_lock); } const char* get_name(int lock) { @@ -121,6 +123,7 @@ case LOCK_PHP_PROC_13: return "php_proc_13"; case LOCK_PHP_PROC_14: return "php_proc_14"; case LOCK_THDET: return "thdet"; + case LOCK_HOST_TIME: return "host_time"; } return "Unknown lock"; @@ -152,6 +155,7 @@ case LOCK_PHP_PROC_13: ret_val = &php_proc_13_cond; break; case LOCK_PHP_PROC_14: ret_val = &php_proc_14_cond; break; case LOCK_THDET: ret_val = &thdet_cond; break; + case LOCK_HOST_TIME: ret_val = &host_time_cond; break; } SPINE_LOG_DEVDBG(( "LOCKS: [ RET ] Returning cond for %s", get_name(lock) )); @@ -185,6 +189,7 @@ case LOCK_PHP_PROC_13: ret_val = &php_proc_13_lock; break; case LOCK_PHP_PROC_14: ret_val = &php_proc_14_lock; break; case LOCK_THDET: ret_val = &thdet_lock; break; + case LOCK_HOST_TIME: ret_val = &host_time_lock; break; } SPINE_LOG_DEVDBG(( "LOCKS: [ RET ] Returning lock for %s", get_name(lock) )); @@ -218,6 +223,7 @@ case LOCK_PHP_PROC_13_O: ret_val = &php_proc_13_lock_o; break; case LOCK_PHP_PROC_14_O: ret_val = &php_proc_14_lock_o; break; case LOCK_THDET_O: ret_val = &thdet_lock_o; break; + case LOCK_HOST_TIME_O: ret_val = &host_time_lock_o; break; } SPINE_LOG_DEVDBG(( "LOCKS: [ RET ] Returning attr for %s", get_name(locko) )); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.21/ping.c new/cacti-spine-1.2.22/ping.c --- old/cacti-spine-1.2.21/ping.c 2022-05-18 23:20:59.000000000 +0200 +++ new/cacti-spine-1.2.22/ping.c 2022-08-14 23:44:27.000000000 +0200 @@ -96,7 +96,7 @@ switch (host->availability_method) { case AVAIL_SNMP_AND_PING: - if ((strlen(host->snmp_community) == 0) && (host->snmp_version < 3)) { + if (strlen(host->snmp_community) == 0 && host->snmp_version < 3) { if (ping_result == HOST_UP) { return HOST_UP; } else { @@ -110,7 +110,7 @@ return HOST_DOWN; } case AVAIL_SNMP_OR_PING: - if ((strlen(host->snmp_community) == 0) && (host->snmp_version < 3)) { + if (strlen(host->snmp_community) == 0 && host->snmp_version < 3) { if (ping_result == HOST_UP) { return HOST_UP; } else { @@ -172,7 +172,7 @@ } if (host->snmp_session) { - if ((strlen(host->snmp_community) != 0) || (host->snmp_version == 3)) { + if (strlen(host->snmp_community) != 0 || host->snmp_version == 3) { /* by default, we look at sysUptime */ if (host->availability_method == AVAIL_SNMP_GET_NEXT) { oid = strdup(".1.3"); @@ -196,7 +196,7 @@ /* record end time */ end_time = get_time_as_double(); - free(oid); + SPINE_FREE(oid); total_time = (end_time - begin_time) * one_thousand; @@ -204,7 +204,9 @@ if (host->snmp_status == SNMPERR_UNKNOWN_OBJID) { snprintf(ping->snmp_response, SMALL_BUFSIZE, "Device responded to SNMP"); snprintf(ping->snmp_status, 50, "%.5f", total_time); - free(poll_result); + + SPINE_FREE(poll_result); + return HOST_UP; } else if (host->snmp_status != SNMPERR_SUCCESS) { if (is_debug_device(host->id)) { @@ -220,18 +222,24 @@ SPINE_LOG_MEDIUM(("Device[%i] SNMP Ping Unknown Error", host->id)); } } + snprintf(ping->snmp_response, SMALL_BUFSIZE, "Device did not respond to SNMP"); - free(poll_result); + + SPINE_FREE(poll_result); + return HOST_DOWN; } else { snprintf(ping->snmp_response, SMALL_BUFSIZE, "Device responded to SNMP"); snprintf(ping->snmp_status, 50, "%.5f", total_time); - free(poll_result); + + SPINE_FREE(poll_result); + return HOST_UP; } } else { snprintf(ping->snmp_status, 50, "0.00"); snprintf(ping->snmp_response, SMALL_BUFSIZE, "Device does not require SNMP"); + return HOST_UP; } } else { @@ -859,7 +867,7 @@ inet_ntop(res->ai_family, ptr, addrstr, 100); - SPINE_LOG_HIGH(("Device[%d] IPv%d address %s (%s)\n", host->id, res->ai_family == PF_INET6 ? 6:4, addrstr, res->ai_canonname)); + SPINE_LOG_HIGH(("Device[%d] IPv%d address %s (%s)", host->id, res->ai_family == PF_INET6 ? 6:4, addrstr, res->ai_canonname)); if (res->ai_family != PF_INET6) { freeaddrinfo(res_list); @@ -973,9 +981,11 @@ name_t *get_namebyhost(char *hostname, name_t *name) { if (name == NULL) { SPINE_LOG_DEBUG(("get_namebyhost(%s) - Allocating name_t", hostname)); + if (!(name = (name_t *) malloc(sizeof(name_t)))) { die("ERROR: Fatal malloc error: ping.c get_namebyhost->name"); } + memset(name, '\0', sizeof(name_t)); } @@ -986,6 +996,7 @@ if (!(stack = (char *) malloc(strlen(hostname)+1))) { die("ERROR: Fatal malloc error: ping.c get_namebyhost->stack"); } + memset(stack, '\0', strlen(hostname)+1); strncopy(stack, hostname, strlen(stack)); token = strtok(stack, ":"); @@ -1124,14 +1135,14 @@ switch (availability_method) { case AVAIL_SNMP_OR_PING: case AVAIL_SNMP_AND_PING: - if ((strlen(host->snmp_community) == 0) && (host->snmp_version < 3)) { + if (strlen(host->snmp_community) == 0 && host->snmp_version < 3) { snprintf(host->status_last_error, BUFSIZE, "%s", ping->ping_response); } else { snprintf(host->status_last_error, BUFSIZE, "%s, %s", ping->snmp_response, ping->ping_response); } break; case AVAIL_SNMP: - if ((strlen(host->snmp_community) == 0) && (host->snmp_version < 3)) { + if (strlen(host->snmp_community) == 0 && host->snmp_version < 3) { snprintf(host->status_last_error, BUFSIZE, "%s", "Device does not require SNMP"); } else { snprintf(host->status_last_error, BUFSIZE, "%s", ping->snmp_response); @@ -1157,6 +1168,7 @@ if (set.ping_failure_count == 1) { snprintf(host->status_fail_date, 40, "%s", current_date); } + /* host is down, but not ready to issue log message */ } else { /* host down for the first time, set event date */ @@ -1164,6 +1176,7 @@ snprintf(host->status_fail_date, 40, "%s", current_date); } } + /* host is recovering, put back in failed state */ } else if (host->status == HOST_RECOVERING) { host->status_event_count = 1; @@ -1176,6 +1189,7 @@ } else { host->status_event_count++; } + /* host is up!! */ } else { /* update total polls and availability */ @@ -1184,14 +1198,14 @@ /* determine the ping statistic to set and do so */ if (availability_method == AVAIL_SNMP_AND_PING) { - if (strlen(host->snmp_community) == 0) { + if (strlen(host->snmp_community) == 0 && host->snmp_version < 3) { ping_time = atof(ping->ping_status); } else { /* calculate the average of the two times */ ping_time = (atof(ping->snmp_status) + atof(ping->ping_status)) / 2; } } else if (availability_method == AVAIL_SNMP) { - if (strlen(host->snmp_community) == 0) { + if (strlen(host->snmp_community) == 0 && host->snmp_version < 3) { ping_time = 0.000; } else { ping_time = atof(ping->snmp_status); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.21/poller.c new/cacti-spine-1.2.22/poller.c --- old/cacti-spine-1.2.21/poller.c 2022-05-18 23:20:59.000000000 +0200 +++ new/cacti-spine-1.2.22/poller.c 2022-08-14 23:44:27.000000000 +0200 @@ -92,8 +92,11 @@ host_threads = poller_details.host_threads; host_data_ids = poller_details.host_data_ids; host_time_double = poller_details.host_time_double; + snprintf(host_time, SMALL_BUFSIZE, "%s", poller_details.host_time); + thread_mutex_unlock(LOCK_HOST_TIME); + /* Allows main thread to proceed with creation of other threads */ sem_post(poller_details.thread_init_sem); @@ -216,12 +219,12 @@ pool_t *local_cnn; pool_t *remote_cnn; - reindex_t *reindex; - host_t *host; - ping_t *ping; - name_t *name; - target_t *poller_items; - snmp_oids_t *snmp_oids; + reindex_t *reindex = NULL; + host_t *host = NULL; + ping_t *ping = NULL; + name_t *name = NULL; + target_t *poller_items = NULL; + snmp_oids_t *snmp_oids = NULL; error_string = malloc(DBL_BUFSIZE); buf_size = malloc(sizeof(int)); @@ -260,13 +263,6 @@ /* set zeros */ memset(ping, 0, sizeof(ping_t)); - if (!(name = (name_t *) malloc(sizeof(name_t)))) { - die("ERROR: Fatal malloc error: poller.c name struct!"); - } - - /* set zeros */ - memset(name, 0, sizeof(name_t)); - if (!(reindex = (reindex_t *) malloc(sizeof(reindex_t)))) { die("ERROR: Fatal malloc error: poller.c reindex poll!"); } @@ -550,6 +546,10 @@ } } + SPINE_FREE(host); + SPINE_FREE(reindex); + SPINE_FREE(ping); + return; } @@ -558,8 +558,8 @@ if (row) { /* initialize variables first */ - host->id = 0; // 0 - host->hostname[0] = '\0'; // 1 + host->id = 0; // 0 + host->hostname[0] = '\0'; // 1 host->snmp_session = NULL; // - host->snmp_community[0] = '\0'; // 2 host->snmp_version = 1; // 3 @@ -606,7 +606,9 @@ name = get_namebyhost(row[1], NULL); STRNCOPY(host->hostname, name->hostname); host->ping_port = name->port; + SPINE_FREE(name); } + if (row[2] != NULL) STRNCOPY(host->snmp_community, row[2]); if (row[3] != NULL) host->snmp_version = atoi(row[3]); @@ -860,34 +862,50 @@ switch(reindex->action) { case POLLER_ACTION_SNMP: /* snmp */ /* if there is no snmp session, don't probe */ - if (!host->snmp_session) { + if (host->snmp_session == NULL) { reindex_err = TRUE; } /* check to see if you are checking uptime */ if (!reindex_err) { - if (strstr(reindex->arg1, ".1.3.6.1.2.1.1.3.0") && - (strlen(sysUptime) > 0)) { + if ((strstr(reindex->arg1, ".1.3.6.1.2.1.1.3.0") || + strstr(reindex->arg1, ".1.3.6.1.6.3.10.2.1.3.0")) && strlen(sysUptime) > 0) { + if (!(poll_result = (char *) malloc(BUFSIZE))) { die("ERROR: Fatal malloc error: poller.c poll_result"); } + poll_result[0] = '\0'; + snprintf(poll_result, BUFSIZE, "%s", sysUptime); } else if (strstr(reindex->arg1, ".1.3.6.1.2.1.1.3.0")) { - poll_result = snmp_get_base(host, ".1.3.6.1.6.3.10.2.1.3.0", false); + // Check the legacy poll result first + poll_result = snmp_get(host, reindex->arg1); + + if (poll_result && is_numeric(poll_result)) { + snprintf(sysUptime, BUFSIZE, "%s", poll_result); + } + if (is_debug_device(host->id)) { - SPINE_LOG(("Device[%i] HT[%i] DQ[%i] Extended Uptime Result: %s, Is Numeric: %d", host->id, host_thread, reindex->data_query_id, poll_result, is_numeric(poll_result) )); + SPINE_LOG(("Device[%i] HT[%i] DQ[%i] Legacy Uptime Result: %s, Is Numeric: %d", host->id, host_thread, reindex->data_query_id, poll_result, is_numeric(poll_result) )); } else { - SPINE_LOG_MEDIUM(("Device[%i] HT[%i] DQ[%i] Extended Uptime Result: %s, Is Numeric: %d", host->id, host_thread, reindex->data_query_id, poll_result, is_numeric(poll_result) )); + SPINE_LOG_MEDIUM(("Device[%i] HT[%i] DQ[%i] Legacy Uptime Result: %s, Is Numeric: %d", host->id, host_thread, reindex->data_query_id, poll_result, is_numeric(poll_result) )); } + SPINE_FREE(poll_result); + + // Check the modern uptimeInsance second + poll_result = snmp_get_base(host, ".1.3.6.1.6.3.10.2.1.3.0", false); + if (poll_result && is_numeric(poll_result)) { snprintf(sysUptime, BUFSIZE, "%llu", atoll(poll_result) * 100); snprintf(poll_result, BUFSIZE, "%s", sysUptime); + } + + if (is_debug_device(host->id)) { + SPINE_LOG(("Device[%i] HT[%i] DQ[%i] Extended Uptime Result: %s, Is Numeric: %d", host->id, host_thread, reindex->data_query_id, poll_result, is_numeric(poll_result) )); } else { - free(poll_result); - poll_result = snmp_get(host, reindex->arg1); - snprintf(sysUptime, BUFSIZE, "%s", poll_result); + SPINE_LOG_MEDIUM(("Device[%i] HT[%i] DQ[%i] Extended Uptime Result: %s, Is Numeric: %d", host->id, host_thread, reindex->data_query_id, poll_result, is_numeric(poll_result) )); } } else { poll_result = snmp_get(host, reindex->arg1); @@ -905,6 +923,7 @@ break; case POLLER_ACTION_SCRIPT: /* script (popen) */ poll_result = trim(exec_poll(host, reindex->arg1, reindex->data_query_id, "DQ")); + if (is_debug_device(host->id)) { SPINE_LOG(("Device[%i] HT[%i] DQ[%i] RECACHE CMD: %s, output: %s", host->id, host_thread, reindex->data_query_id, reindex->arg1, poll_result)); } else { @@ -914,7 +933,9 @@ break; case POLLER_ACTION_PHP_SCRIPT_SERVER: /* script (php script server) */ php_process = php_get_process(); + poll_result = trim(php_cmd(reindex->arg1, php_process)); + if (is_debug_device(host->id)) { SPINE_LOG(("Device[%i] HT[%i] DQ[%i] RECACHE SERVER: %s, output: %s", host->id, host_thread, reindex->data_query_id, reindex->arg1, poll_result)); } else { @@ -929,6 +950,7 @@ poll_result[0] = '\0'; snprintf(poll_result, BUFSIZE, "%d", snmp_count(host, reindex->arg1)); + if (is_debug_device(host->id)) { SPINE_LOG(("Device[%i] HT[%i] DQ[%i] RECACHE OID COUNT: %s, output: %s", host->id, host_thread, reindex->data_query_id, reindex->arg1, poll_result)); } else { @@ -943,6 +965,7 @@ poll_result[0] = '\0'; snprintf(poll_result, BUFSIZE, "%d", char_count(exec_poll(host, reindex->arg1, reindex->data_query_id, "DQ"), '\n')); + if (is_debug_device(host->id)) { SPINE_LOG(("Device[%i] HT[%i] DQ[%i] RECACHE CMD COUNT: %s, output: %s", host->id, host_thread, reindex->data_query_id, reindex->arg1, poll_result)); } else { @@ -957,7 +980,9 @@ poll_result[0] = '\0'; php_process = php_get_process(); + sprintf(poll_result, "%d", char_count(php_cmd(reindex->arg1, php_process), '\n')); + if (is_debug_device(host->id)) { SPINE_LOG(("Device[%i] HT[%i] DQ[%i] RECACHE SERVER COUNT: %s, output: %s", host->id, host_thread, reindex->data_query_id, reindex->arg1, poll_result)); } else { @@ -980,6 +1005,7 @@ if (is_debug_device(host->id) || set.spine_log_level == 2) { SPINE_LOG(("Device[%i] HT[%i] DQ[%i] RECACHE ASSERT FAILED: '%s=%s'", host->id, host_thread, reindex->data_query_id, reindex->assert_value, poll_result)); } + assert_fail = FALSE; } else if ((!strcmp(reindex->op, "=")) && (strcmp(reindex->assert_value, poll_result))) { if (is_debug_device(host->id) || set.spine_log_level == 2) { @@ -1004,6 +1030,7 @@ /* set zeros */ memset(query3, 0, buf_length); } + assert_fail = TRUE; previous_assert_failure = TRUE; } else if ((!strcmp(reindex->op, ">")) && (atoll(reindex->assert_value) < atoll(poll_result))) { @@ -1029,6 +1056,7 @@ /* set zeros */ memset(query3, 0, buf_length); } + assert_fail = TRUE; previous_assert_failure = TRUE; /* if uptime is set to '0' don't fail out */ @@ -1056,6 +1084,7 @@ /* set zeros */ memset(query3, 0, buf_length); } + assert_fail = TRUE; previous_assert_failure = TRUE; } @@ -1069,7 +1098,9 @@ if (host_thread == 1) { db_escape(&mysql, temp_poll_result, sizeof(temp_poll_result), poll_result); db_escape(&mysql, temp_arg1, sizeof(temp_arg1), reindex->arg1); + snprintf(query3, LRG_BUFSIZE, "UPDATE poller_reindex SET assert_value='%s' WHERE host_id='%i' AND data_query_id='%i' AND arg1='%s'", temp_poll_result, host_id, reindex->data_query_id, temp_arg1); + db_insert(&mysql, LOCAL, query3); /* set zeros */ @@ -1079,6 +1110,7 @@ if ((assert_fail) && ((!strcmp(reindex->op, "<")) || (!strcmp(reindex->arg1,".1.3.6.1.2.1.1.3.0")))) { spike_kill = TRUE; + if (is_debug_device(host->id) || set.spine_log_level == 2) { SPINE_LOG(("Device[%i] HT[%i] NOTICE: Spike Kill in Effect for '%s'", host_id, host_thread, host->hostname)); } else { @@ -1091,11 +1123,8 @@ } } - free(query3); - - if (poll_result != NULL) { - free(poll_result); - } + SPINE_FREE(query3); + SPINE_FREE(poll_result); } } } @@ -1114,7 +1143,7 @@ } /* close the host snmp session, we will create again momentarily */ - if (host->snmp_session) { + if (host->snmp_session != NULL) { snmp_host_cleanup(host->snmp_session); host->snmp_session = NULL; } @@ -1257,7 +1286,7 @@ } /* catch snmp initialization issues */ - if (!host->snmp_session) { + if (host->snmp_session == NULL) { host->ignore_host = TRUE; break; } @@ -1351,7 +1380,11 @@ memset(snmp_oids, 0, sizeof(snmp_oids_t)*host->max_oids); } - snmp_host_cleanup(host->snmp_session); + if (host->snmp_session != NULL) { + snmp_host_cleanup(host->snmp_session); + host->snmp_session = NULL; + } + host->snmp_session = snmp_host_init(host->id, poller_items[i].hostname, poller_items[i].snmp_version, poller_items[i].snmp_community, poller_items[i].snmp_username, poller_items[i].snmp_password, @@ -1498,7 +1531,7 @@ } } - if (poll_result) free(poll_result); + SPINE_FREE(poll_result); thread_end = get_time_as_double(); @@ -1556,7 +1589,7 @@ } } - if (poll_result) free(poll_result); + SPINE_FREE(poll_result); thread_end = get_time_as_double(); @@ -1778,26 +1811,26 @@ } /* cleanup memory and prepare for function exit */ - if (host->snmp_session) { + if (host->snmp_session != NULL) { snmp_host_cleanup(host->snmp_session); + host->snmp_session = NULL; } - free(query3); + SPINE_FREE(query3); if (set.boost_redirect && set.boost_enabled) { - free(query12); + SPINE_FREE(query12); } - free(poller_items); - free(snmp_oids); + SPINE_FREE(poller_items); + SPINE_FREE(snmp_oids); } else { /* free the mysql result */ mysql_free_result(result); } - free(host); - free(reindex); - free(ping); - free(name); + SPINE_FREE(host); + SPINE_FREE(reindex); + SPINE_FREE(ping); /* update poller_items table for next polling interval */ if (host_thread == host_threads && set.active_profiles != 1) { @@ -1851,9 +1884,9 @@ buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, 0, true); - free(error_string); - free(buf_size); - free(buf_errors); + SPINE_FREE(error_string); + SPINE_FREE(buf_size); + SPINE_FREE(buf_errors); *host_errors = errors; } @@ -1950,7 +1983,7 @@ if (poll_result) { db_escape(mysql, host->snmp_sysDescr, sizeof(host->snmp_sysDescr), poll_result); - free(poll_result); + SPINE_FREE(poll_result); } SPINE_LOG_DEVDBG(("DEVDBG: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.2.0');", host->id)); @@ -1959,28 +1992,29 @@ if (poll_result) { db_escape(mysql, host->snmp_sysObjectID, sizeof(host->snmp_sysObjectID), poll_result); - free(poll_result); + SPINE_FREE(poll_result); } - SPINE_LOG_DEVDBG(("DEVDBG: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.6.3.10.2.1.3.0');", host->id)); - poll_result = snmp_get_base(host, ".1.3.6.1.6.3.10.2.1.3.0", false); - SPINE_LOG_DEVDBG(("DEVDGB: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.6.3.10.2.1.3.0'); [complete]", host->id)); + // Get the legacy system uptime instance first + SPINE_LOG_DEVDBG(("DEVDBG: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0');", host->id)); + poll_result = snmp_get(host, ".1.3.6.1.2.1.1.3.0"); + SPINE_LOG_DEVDBG(("DEVDGB: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0'); [complete]", host->id)); if (poll_result && is_numeric(poll_result)) { - host->snmp_sysUpTimeInstance = atoll(poll_result) * 100; - snprintf(poll_result, BUFSIZE, "%llu", host->snmp_sysUpTimeInstance); - free(poll_result); - } else { - free(poll_result); + host->snmp_sysUpTimeInstance = atoll(poll_result); + SPINE_FREE(poll_result); - SPINE_LOG_DEVDBG(("DEVDBG: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0');", host->id)); - poll_result = snmp_get(host, ".1.3.6.1.2.1.1.3.0"); - SPINE_LOG_DEVDBG(("DEVDGB: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0'); [complete]", host->id)); + // Attempt to get the more modern version + SPINE_LOG_DEVDBG(("DEVDBG: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.6.3.10.2.1.3.0');", host->id)); + poll_result = snmp_get_base(host, ".1.3.6.1.6.3.10.2.1.3.0", false); + SPINE_LOG_DEVDBG(("DEVDGB: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.6.3.10.2.1.3.0'); [complete]", host->id)); if (poll_result && is_numeric(poll_result)) { - host->snmp_sysUpTimeInstance = atoll(poll_result); - free(poll_result); + host->snmp_sysUpTimeInstance = atoll(poll_result) * 100; + snprintf(poll_result, BUFSIZE, "%llu", host->snmp_sysUpTimeInstance); } + + SPINE_FREE(poll_result); } SPINE_LOG_DEVDBG(("DEVDBG: Device [%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.4.0');", host->id)); @@ -1989,7 +2023,7 @@ if (poll_result) { db_escape(mysql, host->snmp_sysContact, sizeof(host->snmp_sysContact), poll_result); - free(poll_result); + SPINE_FREE(poll_result); } SPINE_LOG_DEVDBG(("DEVDBG: Device [%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.5.0');", host->id)); @@ -1998,7 +2032,7 @@ if (poll_result) { db_escape(mysql, host->snmp_sysName, sizeof(host->snmp_sysName), poll_result); - free(poll_result); + SPINE_FREE(poll_result); } SPINE_LOG_DEVDBG(("DEVDBG: Device [%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.6.0');", host->id)); @@ -2007,7 +2041,7 @@ if (poll_result) { db_escape(mysql, host->snmp_sysLocation, sizeof(host->snmp_sysLocation), poll_result); - free(poll_result); + SPINE_FREE(poll_result); } } else { if (is_debug_device(host->id)) { @@ -2016,26 +2050,26 @@ SPINE_LOG_MEDIUM(("Device[%d] Updating Short System Information Table", host->id)); } - SPINE_LOG_DEVDBG(("DEVDBG: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.6.3.10.2.1.3.0');", host->id)); - poll_result = snmp_get(host, ".1.3.6.1.6.3.10.2.1.3.0"); - SPINE_LOG_DEVDBG(("DEVDGB: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.6.3.10.2.1.3.0'); [complete]", host->id)); + // Get the legacy system uptime instance first + SPINE_LOG_DEVDBG(("DEVDBG: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0');", host->id)); + poll_result = snmp_get(host, ".1.3.6.1.2.1.1.3.0"); + SPINE_LOG_DEVDBG(("DEVDGB: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0'); [complete]", host->id)); if (poll_result && is_numeric(poll_result)) { - host->snmp_sysUpTimeInstance = atoll(poll_result) * 100; - snprintf(poll_result, BUFSIZE, "%llu", host->snmp_sysUpTimeInstance); + host->snmp_sysUpTimeInstance = atoll(poll_result); + SPINE_FREE(poll_result); - free(poll_result); - } else { - free(poll_result); - - SPINE_LOG_DEVDBG(("DEVDBG: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0');", host->id)); - poll_result = snmp_get(host, ".1.3.6.1.2.1.1.3.0"); - SPINE_LOG_DEVDBG(("DEVDGB: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0'); [complete]", host->id)); + // Attempt to get the more modern version + SPINE_LOG_DEVDBG(("DEVDBG: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.6.3.10.2.1.3.0');", host->id)); + poll_result = snmp_get(host, ".1.3.6.1.6.3.10.2.1.3.0"); + SPINE_LOG_DEVDBG(("DEVDGB: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.6.3.10.2.1.3.0'); [complete]", host->id)); if (poll_result && is_numeric(poll_result)) { - host->snmp_sysUpTimeInstance = atoll(poll_result); - free(poll_result); + host->snmp_sysUpTimeInstance = atoll(poll_result) * 100; + snprintf(poll_result, BUFSIZE, "%llu", host->snmp_sysUpTimeInstance); } + + SPINE_FREE(poll_result); } } } @@ -2264,7 +2298,7 @@ } #if defined(__CYGWIN__) - free(proc_command); + SPINE_FREE(proc_command); #endif } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.21/snmp.c new/cacti-spine-1.2.22/snmp.c --- old/cacti-spine-1.2.21/snmp.c 2022-05-18 23:20:59.000000000 +0200 +++ new/cacti-spine-1.2.22/snmp.c 2022-08-14 23:44:27.000000000 +0200 @@ -407,50 +407,96 @@ pdu = snmp_pdu_create(SNMP_MSG_GET); SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_pdu_create(%s) [complete]", current_host->id, snmp_oid)); - SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_parse_oid(%s)", current_host->id, snmp_oid)); - if (!snmp_parse_oid(snmp_oid, anOID, &anOID_len)) { - SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_parse_oid(%s) [complete]", current_host->id, snmp_oid)); - SPINE_LOG(("Device[%i] ERROR: SNMP Get Problems parsing SNMP OID %s", current_host->id, snmp_oid)); - SET_UNDEFINED(result_string); - return result_string; - } else { - SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_parse_oid(%s) [complete]", current_host->id, snmp_oid)); - SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_add_null_var(%s)", current_host->id, snmp_oid)); - snmp_add_null_var(pdu, anOID, anOID_len); - SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_add_null_var(%s) [complete]", current_host->id, snmp_oid)); - } + if (pdu != NULL) { + SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_parse_oid(%s)", current_host->id, snmp_oid)); + + if (!snmp_parse_oid(snmp_oid, anOID, &anOID_len)) { + SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_parse_oid(%s) [complete]", current_host->id, snmp_oid)); + SPINE_LOG(("Device[%i] ERROR: SNMP Get Problems parsing SNMP OID %s", current_host->id, snmp_oid)); + SET_UNDEFINED(result_string); + return result_string; + } else { + SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_parse_oid(%s) [complete]", current_host->id, snmp_oid)); + SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_add_null_var(%s)", current_host->id, snmp_oid)); + snmp_add_null_var(pdu, anOID, anOID_len); + SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_add_null_var(%s) [complete]", current_host->id, snmp_oid)); + } - /* poll host */ - SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_sess_sync_response(%s)", current_host->id, snmp_oid)); - status = snmp_sess_synch_response(current_host->snmp_session, pdu, &response); - SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_sess_sync_response(%s) [complete]", current_host->id, snmp_oid)); + /* poll host */ + SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_sess_sync_response(%s)", current_host->id, snmp_oid)); + status = snmp_sess_synch_response(current_host->snmp_session, pdu, &response); + SPINE_LOG_DEVDBG(("Device[%i] DEBUG: snmp_sess_sync_response(%s) [complete]", current_host->id, snmp_oid)); + } /* add status to host structure */ current_host->snmp_status = status; /* liftoff, successful poll, process it!! */ - if (status == STAT_SUCCESS) { + if (status == STAT_DESCRIP_ERROR) { + SPINE_LOG(("ERROR: Unable to create SNMP PDU")); + + SET_UNDEFINED(result_string); + status = STAT_ERROR; + response = NULL; + } else if (status == STAT_SUCCESS) { if (response == NULL) { SPINE_LOG(("ERROR: An internal Net-Snmp error condition detected in Cacti snmp_get")); SET_UNDEFINED(result_string); status = STAT_ERROR; - } else { - if (response->errstat == SNMP_ERR_NOERROR) { - vars = response->variables; - + } else if (response->errstat == SNMP_ERR_NOERROR && + response->variables != NULL && + response->variables->name != NULL) { + + vars = response->variables; + + if (vars->type == SNMP_NOSUCHOBJECT) { + SET_UNDEFINED(result_string); + status = STAT_ERROR; + SPINE_LOG_HIGH(("ERROR: No such Object for oid '%s' for Device[%d] with Status[%d]", snmp_oid, current_host->id, status)); + } else if (vars->type == SNMP_NOSUCHINSTANCE) { + SET_UNDEFINED(result_string); + status = STAT_ERROR; + SPINE_LOG_HIGH(("ERROR: No such Instance for oid '%s' for Device[%d] with Status[%d]", snmp_oid, current_host->id, status)); + } else if (vars->type == SNMP_ENDOFMIBVIEW) { + SET_UNDEFINED(result_string); + status = STAT_ERROR; + SPINE_LOG_HIGH(("ERROR: End of Mib for oid '%s' for Device[%d] with Status[%d]", snmp_oid, current_host->id, status)); + } else { snprint_value(temp_result, RESULTS_BUFFER, vars->name, vars->name_length, vars); snprintf(result_string, RESULTS_BUFFER, "%s", trim(temp_result)); - } else { - SPINE_LOG_HIGH(("ERROR: Failed to get oid '%s' for Device[%d] with Response[%ld]", snmp_oid, current_host->id, response->errstat)); } + } else { + SPINE_LOG_HIGH(("ERROR: Failed to get oid '%s' for Device[%d] with Response[%ld]", snmp_oid, current_host->id, response->errstat)); + } + } else if (response != NULL && response->variables != NULL) { + vars = response->variables; + + if (vars->type == SNMP_NOSUCHOBJECT) { + SET_UNDEFINED(result_string); + status = STAT_ERROR; + SPINE_LOG_HIGH(("ERROR: No such Object for oid '%s' for Device[%d] with Status[%d]", snmp_oid, current_host->id, status)); + } else if (vars->type == SNMP_NOSUCHINSTANCE) { + SET_UNDEFINED(result_string); + status = STAT_ERROR; + SPINE_LOG_HIGH(("ERROR: No such Instance for oid '%s' for Device[%d] with Status[%d]", snmp_oid, current_host->id, status)); + } else if (vars->type == SNMP_ENDOFMIBVIEW) { + SET_UNDEFINED(result_string); + status = STAT_ERROR; + SPINE_LOG_HIGH(("ERROR: End of Mib for oid '%s' for Device[%d] with Status[%d]", snmp_oid, current_host->id, status)); + } else { + SET_UNDEFINED(result_string); + status = STAT_ERROR; + SPINE_LOG_HIGH(("ERROR: Unknown error getting oid '%s' for Device[%d] with Status[%d]", snmp_oid, current_host->id, status)); } + } else if (status == STAT_TIMEOUT) { + SPINE_LOG_HIGH(("ERROR: Timeout getting oid '%s' for Device[%d] with Status[%d]", snmp_oid, current_host->id, status)); } else { - SPINE_LOG_HIGH(("ERROR: Failed to get oid '%s' for Device[%d] with Status[%d]", snmp_oid, current_host->id, status)); + SPINE_LOG_HIGH(("ERROR: Unknown error getting oid '%s' for Device[%d] with Status[%d]", snmp_oid, current_host->id, status)); } - if (response) { + if (response != NULL && status != STAT_DESCRIP_ERROR) { snmp_free_pdu(response); response = NULL; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.21/spine.c new/cacti-spine-1.2.22/spine.c --- old/cacti-spine-1.2.21/spine.c 2022-05-18 23:20:59.000000000 +0200 +++ new/cacti-spine-1.2.22/spine.c 2022-08-14 23:44:27.000000000 +0200 @@ -103,6 +103,7 @@ sem_t available_threads; sem_t available_scripts; double start_time; +double total_time; config_t set; php_t *php_processes = 0; @@ -205,6 +206,7 @@ struct timespec until_spec; start_time = get_time_as_double(); + total_time = 0; #ifdef HAVE_LCAP if (geteuid() == 0) { @@ -234,6 +236,9 @@ int threads_missing = -1; int threads_count; + /* we must initilize snmp in the main thread */ + struct snmp_session session; + UNUSED_PARAMETER(argc); /* we operate strictly with argv */ /* install the spine signal handler */ @@ -649,6 +654,12 @@ die("ERROR: Fatal malloc error: spine.c host id's!"); } + if (!(host_time = (char *) malloc(SMALL_BUFSIZE))) { + die("ERROR: Fatal malloc error: util.c host_time"); + } + + memset(host_time, 0, SMALL_BUFSIZE); + /* initialize winsock library on Windows */ SOCK_STARTUP; @@ -697,6 +708,14 @@ change_host = TRUE; } + /** + * We must initilize the first snmp session + * in the main thread to initilize the mib files + * and other structures. After which it's snmp + * is thread safe in threads + */ + snmp_sess_init(&session); + /* loop through devices until done */ while (canexit == FALSE && device_counter < num_rows) { if (change_host) { @@ -747,13 +766,16 @@ db_free_result(tresult); - host_time = get_host_poll_time(); + sprintf(host_time, "%lu", (unsigned long) time(NULL)); + host_time_double = get_time_as_double(); + } else if (host_time_double == 0 || host_time == 0 || host_time == NULL) { + sprintf(host_time, "%lu", (unsigned long) time(NULL)); host_time_double = get_time_as_double(); } } else { items_per_thread = 0; - host_time = get_host_poll_time(); + sprintf(host_time, "%lu", (unsigned long) time(NULL)); host_time_double = get_time_as_double(); } @@ -767,7 +789,9 @@ poller_details->host_thread = current_thread; poller_details->host_threads = device_threads; poller_details->host_data_ids = items_per_thread; - poller_details->host_time = host_time; + + snprintf(poller_details->host_time, 40, "%s", host_time); + poller_details->host_time_double = host_time_double; poller_details->thread_init_sem = &thread_init_sem; poller_details->complete = FALSE; @@ -812,7 +836,16 @@ loop_count = 0; } - usleep(100000); + usleep(10000); + + total_time = get_time_as_double(); + + if (total_time - start_time > set.poller_interval) { + SPINE_LOG(("ERROR: Device[%i] HT[%i] Spine Timed Out While Processing Devices External", host_id, current_thread)); + spine_timeout = TRUE; + canexit = TRUE; + break; + } } loop_count = 0; @@ -845,13 +878,24 @@ loop_count = 0; } - usleep(100000); + usleep(10000); + + total_time = get_time_as_double(); + + if (total_time - start_time > set.poller_interval) { + SPINE_LOG(("ERROR: Device[%i] HT[%i] Spine Timed Out While Processing Devices Internal", host_id, current_thread)); + spine_timeout = TRUE; + canexit = TRUE; + break; + } } if (!spine_timeout) { /* create child process */ thread_retry: + thread_mutex_lock(LOCK_HOST_TIME); + thread_status = pthread_create(&threads[device_counter], &attr, child, poller_details); if (thread_status == 0) { @@ -875,7 +919,7 @@ poller_details->host_data_ids, poller_details->complete)); } else if (thread_status == EAGAIN) { - usleep(100000); + usleep(10000); goto thread_retry; } else if (thread_status == EINVAL) { SPINE_LOG(("ERROR: The Thread Attribute is Not Initialized")); @@ -940,7 +984,7 @@ } if (threads_missing > -1) { - SPINE_LOG_HIGH(("ERROR: There were %d threads which did not run", num_rows - threads_missing)); + SPINE_LOG(("WARNING: There were %d threads which did not run", num_rows - threads_missing)); } /* tell Spine that it is now parent */ @@ -986,15 +1030,16 @@ /* free malloc'd variables */ for (i = 0; i < num_rows; i++) { if (details[i] != NULL) { - free(details[i]); + SPINE_FREE(details[i]); } } - free(details); - free(threads); - free(ids); - free(conf_file); - free(debug_devices); + SPINE_FREE(details); + SPINE_FREE(threads); + SPINE_FREE(ids); + SPINE_FREE(conf_file); + SPINE_FREE(debug_devices); + SPINE_FREE(host_time); SPINE_LOG_DEBUG(("DEBUG: Allocated Variable Memory Freed")); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.21/spine.h new/cacti-spine-1.2.22/spine.h --- old/cacti-spine-1.2.21/spine.h 2022-05-18 23:20:59.000000000 +0200 +++ new/cacti-spine-1.2.22/spine.h 2022-08-14 23:44:27.000000000 +0200 @@ -190,6 +190,7 @@ #define LOCK_PHP_PROC_13 20 #define LOCK_PHP_PROC_14 21 #define LOCK_THDET 40 +#define LOCK_HOST_TIME 41 #define LOCK_SNMP_O 0 #define LOCK_SETEUID_O 2 @@ -213,6 +214,7 @@ #define LOCK_PHP_PROC_13_O 20 #define LOCK_PHP_PROC_14_O 21 #define LOCK_THDET_O 40 +#define LOCK_HOST_TIME_O 41 /* poller actions */ #define POLLER_ACTION_SNMP 0 @@ -235,6 +237,8 @@ #define IS_LOGGING_TO_SYSLOG() ((set.log_destination) == LOGDEST_SYSLOG || (set.log_destination) == LOGDEST_BOTH) #define IS_LOGGING_TO_STDOUT() ((set.log_destination) == LOGDEST_STDOUT ) +#define SPINE_FREE(s) do { if (s) { free((void *)s); s = NULL; } } while(0) + /* logging levels */ #define POLLER_VERBOSITY_NONE 1 #define POLLER_VERBOSITY_LOW 2 @@ -487,7 +491,7 @@ int host_data_ids; int threads_complete; int complete; - char *host_time; + char host_time[40]; double host_time_double; sem_t *thread_init_sem; } poller_thread_t; @@ -588,9 +592,9 @@ */ typedef struct name_port { // Method = 0 - default, 1 - tcp, 2 - udp - int method; - char hostname[SMALL_BUFSIZE]; - int port; + char hostname[SMALL_BUFSIZE]; + int method; + int port; } name_t; /*! MySQL Connection Pool Structure diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.21/sql.c new/cacti-spine-1.2.22/sql.c --- old/cacti-spine-1.2.21/sql.c 2022-05-18 23:20:59.000000000 +0200 +++ new/cacti-spine-1.2.22/sql.c 2022-08-14 23:44:27.000000000 +0200 @@ -52,6 +52,7 @@ char query_frag[LRG_BUFSIZE]; /* save a fragment just in case */ + memset(query_frag, 0, LRG_BUFSIZE); snprintf(query_frag, LRG_BUFSIZE, "%s", query); /* show the sql query */ @@ -148,6 +149,7 @@ char query_frag[LRG_BUFSIZE]; /* save a fragment just in case */ + memset(query_frag, 0, LRG_BUFSIZE); snprintf(query_frag, LRG_BUFSIZE, "%s", query); /* show the sql query */ @@ -260,8 +262,8 @@ tries = 2; success = FALSE; timeout = 5; - rtimeout = 10; - wtimeout = 20; + rtimeout = 30; + wtimeout = 30; reconnect = 1; attempts = 1; @@ -272,9 +274,9 @@ exit(1); } - MYSQL_SET_OPTION(MYSQL_OPT_READ_TIMEOUT, (char *)&rtimeout, "read timeout"); - MYSQL_SET_OPTION(MYSQL_OPT_WRITE_TIMEOUT, (char *)&wtimeout, "write timeout"); - MYSQL_SET_OPTION(MYSQL_OPT_CONNECT_TIMEOUT, (char *)&timeout, "general timeout"); + MYSQL_SET_OPTION(MYSQL_OPT_READ_TIMEOUT, (int *)&rtimeout, "read timeout"); + MYSQL_SET_OPTION(MYSQL_OPT_WRITE_TIMEOUT, (int *)&wtimeout, "write timeout"); + MYSQL_SET_OPTION(MYSQL_OPT_CONNECT_TIMEOUT, (int *)&timeout, "general timeout"); MYSQL_SET_OPTION(MYSQL_OPT_RECONNECT, &reconnect, "reconnect"); #ifdef HAS_MYSQL_OPT_RETRY_COUNT @@ -283,9 +285,9 @@ /* set SSL options if available */ #ifdef HAS_MYSQL_OPT_SSL_KEY - char *ssl_key; - char *ssl_ca; - char *ssl_cert; + char *ssl_key = NULL; + char *ssl_ca = NULL; + char *ssl_cert = NULL; if (type == REMOTE) { STRDUP_OR_DIE(ssl_key, set.rdb_ssl_key, "rdb_ssl_key"); @@ -348,6 +350,18 @@ free(hostname); } + if (ssl_key != NULL) { + free(ssl_key); + } + + if (ssl_ca != NULL) { + free(ssl_ca); + } + + if (ssl_cert != NULL) { + free(ssl_cert); + } + if (!success){ printf("FATAL: Connection Failed, Error:'%i', Message:'%s'\n", error, mysql_error(mysql)); exit(1); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.21/util.c new/cacti-spine-1.2.22/util.c --- old/cacti-spine-1.2.21/util.c 2022-05-18 23:20:59.000000000 +0200 +++ new/cacti-spine-1.2.22/util.c 2022-08-14 23:44:27.000000000 +0200 @@ -1659,26 +1659,6 @@ return (now).tv_sec + ((double) (now).tv_usec / 1000000); } -/*! \fn string *get_host_poll_time() - * \brief fetches start time for host being polled - * - * \return host_time as a string - */ -char *get_host_poll_time() { - char *host_time; - - #define HOST_TIME_STRING_LEN 20 - - if (!(host_time = (char *) malloc(HOST_TIME_STRING_LEN))) { - die("ERROR: Fatal malloc error: util.c host_time"); - } - host_time[0] = '\0'; - - sprintf(host_time, "%lu", (unsigned long) time(NULL)); - - return(host_time); -} - /*! \fn trim() * \brief removes leading and trailing blanks, tabs, line feeds and * carriage returns from a string. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.21/util.h new/cacti-spine-1.2.22/util.h --- old/cacti-spine-1.2.21/util.h 2022-05-18 23:20:59.000000000 +0200 +++ new/cacti-spine-1.2.22/util.h 2022-08-14 23:44:27.000000000 +0200 @@ -84,9 +84,6 @@ /* get highres time as double */ extern double get_time_as_double(void); -/* get host polling time */ -extern char *get_host_poll_time(void); - /* function to check to see if program has capability to use raw socket with out uid = 0 */ extern int hasCaps();