Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ DEFINE_SPINE_LOCK(php_proc_14)
DEFINE_SPINE_LOCK(thdet)
DEFINE_SPINE_LOCK(host_time)

void init_mutexes() {
void init_mutexes(void) {
pthread_once((pthread_once_t*) get_attr(LOCK_SNMP_O), init_snmp_lock);
pthread_once((pthread_once_t*) get_attr(LOCK_SETEUID_O), init_seteuid_lock);
pthread_once((pthread_once_t*) get_attr(LOCK_GHBN_O), init_ghbn_lock);
Expand All @@ -97,7 +97,7 @@ void init_mutexes() {
pthread_once((pthread_once_t*) get_attr(LOCK_HOST_TIME_O), init_host_time_lock);
}

const char* get_name(int lock) {
static const char *get_name(int lock) {
switch (lock) {
case LOCK_SNMP: return "snmp";
case LOCK_SETEUID: return "seteuid";
Expand Down
20 changes: 16 additions & 4 deletions nft_popen.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ int nft_popen(const char * command, const char * type) {
int pdes[2];
int fd, pid, twoway;
char *argv[4];
char *command_copy;
char shell_cmd[] = "sh";
char shell_flag[] = "-c";
int cancel_state;
extern char **environ;
int retry_count = 0;
Expand Down Expand Up @@ -159,9 +162,17 @@ int nft_popen(const char * command, const char * type) {
return -1;
}

argv[0] = "sh";
argv[1] = "-c";
argv[2] = (char *)command;
if ((command_copy = strdup(command)) == NULL) {
(void)close(pdes[0]);
(void)close(pdes[1]);
free(cur);
pthread_setcancelstate(cancel_state, NULL);
return -1;
}

argv[0] = shell_cmd;
argv[1] = shell_flag;
argv[2] = command_copy;
argv[3] = NULL;

/* Lock the list mutex prior to forking, to ensure that
Expand Down Expand Up @@ -203,6 +214,7 @@ int nft_popen(const char * command, const char * type) {
(void)close(pdes[0]);
(void)close(pdes[1]);
pthread_mutex_unlock(&ListMutex);
free(command_copy);
pthread_setcancelstate(cancel_state, NULL);

return -1;
Expand Down Expand Up @@ -269,6 +281,7 @@ int nft_popen(const char * command, const char * type) {

/* Unlock the mutex, and restore caller's cancellation state. */
pthread_mutex_unlock(&ListMutex);
free(command_copy);
pthread_setcancelstate(cancel_state, NULL);

return fd;
Expand Down Expand Up @@ -398,4 +411,3 @@ close_cleanup(void * arg)

free(cur);
}

23 changes: 13 additions & 10 deletions php.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,12 @@ int php_init(int php_process) {
int php2cacti_pdes[2];
pid_t pid;
char poller_id[TINY_BUFSIZE];
char mode[TINY_BUFSIZE];
char *argv[7];
char arg_q[] = "-q";
char arg_spine[] = "spine";
char arg_environ_spine[] = "--environ=spine";
char arg_mode_online[] = "--mode=online";
char arg_mode_offline[] = "--mode=offline";
int cancel_state;
char *result_string = 0;
int num_processes;
Expand Down Expand Up @@ -341,34 +345,33 @@ int php_init(int php_process) {
/* establish arguments for script server execution */
if (set.cacti_version <= 1222) {
argv[0] = set.path_php;
argv[1] = "-q";
argv[1] = arg_q;
argv[2] = set.path_php_server;
argv[3] = "spine";
argv[3] = arg_spine;
snprintf(poller_id, TINY_BUFSIZE, "%d", set.poller_id);
argv[4] = poller_id;
argv[5] = NULL;
} else if (set.poller_id > 1) {
argv[0] = set.path_php;
argv[1] = "-q";
argv[1] = arg_q;
argv[2] = set.path_php_server;
argv[3] = "--environ=spine";
argv[3] = arg_environ_spine;

snprintf(poller_id, TINY_BUFSIZE, "--poller=%d", set.poller_id);
argv[4] = poller_id;

if (set.mode == REMOTE_ONLINE) {
snprintf(mode, TINY_BUFSIZE, "--mode=online");
argv[5] = arg_mode_online;
} else {
snprintf(mode, TINY_BUFSIZE, "--mode=offline");
argv[5] = arg_mode_offline;
}
argv[5] = mode;

argv[6] = NULL;
} else {
argv[0] = set.path_php;
argv[1] = "-q";
argv[1] = arg_q;
argv[2] = set.path_php_server;
argv[3] = "--environ=spine";
argv[3] = arg_environ_spine;
snprintf(poller_id, TINY_BUFSIZE, "--poller=%d", set.poller_id);
argv[4] = poller_id;

Expand Down
20 changes: 10 additions & 10 deletions ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
int ping_host(host_t *host, ping_t *ping) {
int ping_result;
int snmp_result;
double start_time;
double end_time;
double snmp_start_time;
double snmp_end_time;

/* snmp pinging has been selected at a minimum */
ping_result = 0;
Expand Down Expand Up @@ -104,21 +104,21 @@ int ping_host(host_t *host, ping_t *ping) {
snmp_result = HOST_UP;
if ((host->availability_method != AVAIL_SNMP_OR_PING) &&
((strlen(host->snmp_community) > 0) || (host->snmp_version >= 3))) {
start_time = get_time_as_double();
snmp_start_time = get_time_as_double();
snmp_result = ping_snmp(host, ping);
end_time = get_time_as_double();
snmp_end_time = get_time_as_double();

if (snmp_result == HOST_UP) {
if (is_debug_device(host->id)) {
SPINE_LOG(("Device[%i] INFO: SNMP Device Alive, Time:%.4f ms", host->id, end_time - start_time));
SPINE_LOG(("Device[%i] INFO: SNMP Device Alive, Time:%.4f ms", host->id, snmp_end_time - snmp_start_time));
} else {
SPINE_LOG_MEDIUM(("Device[%i] INFO: SNMP Device Alive, Time:%.4f ms", host->id, end_time - start_time));
SPINE_LOG_MEDIUM(("Device[%i] INFO: SNMP Device Alive, Time:%.4f ms", host->id, snmp_end_time - snmp_start_time));
}
} else {
if (is_debug_device(host->id)) {
SPINE_LOG(("Device[%i] INFO: SNMP Device Down, Time:%.4f ms", host->id, end_time - start_time));
SPINE_LOG(("Device[%i] INFO: SNMP Device Down, Time:%.4f ms", host->id, snmp_end_time - snmp_start_time));
} else {
SPINE_LOG_MEDIUM(("Device[%i] INFO: SNMP Device Down, Time:%.4f ms", host->id, end_time - start_time));
SPINE_LOG_MEDIUM(("Device[%i] INFO: SNMP Device Down, Time:%.4f ms", host->id, snmp_end_time - snmp_start_time));
}
}
}
Expand Down Expand Up @@ -268,7 +268,7 @@ int ping_icmp(host_t *host, ping_t *ping) {
struct sockaddr_in fromname;
char socket_reply[BUFSIZE];
int retry_count;
char *cacti_msg = "cacti-monitoring-system\0";
const char *cacti_msg = "cacti-monitoring-system\0";
int packet_len;
socklen_t fromlen;
ssize_t return_code;
Expand Down Expand Up @@ -990,7 +990,7 @@ name_t *get_namebyhost(char *hostname, name_t *name) {
}

memset(stack, '\0', strlen(hostname)+1);
strncopy(stack, hostname, strlen(stack));
strncopy(stack, hostname, strlen(hostname));
token = strtok(stack, ":");

if (token == NULL) {
Expand Down
13 changes: 5 additions & 8 deletions poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void child_cleanup(void *arg) {
}

void child_cleanup_thread(void *arg) {
UNUSED_PARAMETER(arg);
sem_post(&available_threads);

int a_threads_value;
Expand All @@ -52,6 +53,7 @@ void child_cleanup_thread(void *arg) {
}

void child_cleanup_script(void *arg) {
UNUSED_PARAMETER(arg);
sem_post(&available_scripts);

int a_scripts_value;
Expand Down Expand Up @@ -173,7 +175,6 @@ void poll_host(int device_counter, int host_id, int host_thread, int host_thread
int j = 0;
int k = 0;
int num_oids = 0;
int snmp_poller_items = 0;
size_t out_buffer;
int php_process;

Expand Down Expand Up @@ -1315,10 +1316,6 @@ void poll_host(int device_counter, int host_id, int host_thread, int host_thread

SET_UNDEFINED(poller_items[i].result);

if (poller_items[i].action == POLLER_ACTION_SNMP) {
snmp_poller_items++;
}

i++;
}

Expand Down Expand Up @@ -2208,7 +2205,7 @@ int validate_result(char *result) {
return FALSE;
}

/*! \fn char *exec_poll(host_t *current_host, char *command, int id, char *type)
/*! \fn char *exec_poll(host_t *current_host, char *command, int id, const char *type)
* \brief polls a host using a script
* \param current_host a pointer to the current host structure
* \param command the command to be executed
Expand All @@ -2220,7 +2217,7 @@ int validate_result(char *result) {
* \return a pointer to a character buffer containing the result.
*
*/
char *exec_poll(host_t *current_host, char *command, int id, char *type) {
char *exec_poll(host_t *current_host, char *command, int id, const char *type) {
int cmd_fd;
int pid;

Expand Down Expand Up @@ -2325,7 +2322,7 @@ char *exec_poll(host_t *current_host, char *command, int id, char *type) {
SPINE_LOG_DEBUG(("DEBUG: Device[%i] DEBUG: The POPEN returned the following File Descriptor %i", current_host->id, cmd_fd));
}
#else
cmd_fd = nft_popen((char *)proc_command, "r");
cmd_fd = nft_popen(proc_command, "r");
if (is_debug_device(current_host->id)) {
SPINE_LOG(("DEBUG: Device[%i] DEBUG: The NIFTY POPEN returned the following File Descriptor %i", current_host->id, cmd_fd));
} else {
Expand Down
2 changes: 1 addition & 1 deletion poller.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern void child_cleanup(void *arg);
extern void child_cleanup_thread(void *arg);
extern void child_cleanup_script(void *arg);
extern void poll_host(int device_counter, int host_id, int host_thread, int host_threads, int host_data_ids, char *host_time, int *host_errors, double host_time_double);
extern char *exec_poll(host_t *current_host, char *command, int id, char *type);
extern char *exec_poll(host_t *current_host, char *command, int id, const char *type);
extern void get_system_information(host_t *host, MYSQL *mysql, int system);
extern int is_multipart_output(char *result);
extern int validate_result(char *result);
Expand Down
14 changes: 8 additions & 6 deletions snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ void snmp_host_cleanup(void *snmp_session) {
}
}

/*! \fn char *snmp_get_base(host_t *current_host, char *snmp_oid, bool should_fail)
/*! \fn char *snmp_get_base(host_t *current_host, const char *snmp_oid, bool should_fail)
* \brief performs a single snmp_get for a specific snmp OID
*
* This function will poll a specific snmp OID for a host. The host snmp
Expand All @@ -418,7 +418,7 @@ void snmp_host_cleanup(void *snmp_session) {
* unsuccessful.
*
*/
char *snmp_get_base(host_t *current_host, char *snmp_oid, bool should_fail) {
char *snmp_get_base(host_t *current_host, const char *snmp_oid, bool should_fail) {
struct snmp_pdu *pdu = NULL;
struct snmp_pdu *response = NULL;
struct variable_list *vars = NULL;
Expand Down Expand Up @@ -657,11 +657,11 @@ char *snmp_get_base(host_t *current_host, char *snmp_oid, bool should_fail) {
return result_string;
}

char *snmp_get(host_t *current_host, char *snmp_oid) {
char *snmp_get(host_t *current_host, const char *snmp_oid) {
return snmp_get_base(current_host, snmp_oid, true);
}

/*! \fn char *snmp_getnext(host_t *current_host, char *snmp_oid)
/*! \fn char *snmp_getnext(host_t *current_host, const char *snmp_oid)
* \brief performs a single snmp_getnext for a specific snmp OID
*
* This function will poll a specific snmp OID for a host. The host snmp
Expand All @@ -671,7 +671,7 @@ char *snmp_get(host_t *current_host, char *snmp_oid) {
* unsuccessful.
*
*/
char *snmp_getnext(host_t *current_host, char *snmp_oid) {
char *snmp_getnext(host_t *current_host, const char *snmp_oid) {
struct snmp_pdu *pdu = NULL;
struct snmp_pdu *response = NULL;
struct variable_list *vars = NULL;
Expand Down Expand Up @@ -844,7 +844,7 @@ char *snmp_getnext(host_t *current_host, char *snmp_oid) {
* \return returns count of table entries
*
*/
int snmp_count(host_t *current_host, char *snmp_oid) {
int snmp_count(host_t *current_host, const char *snmp_oid) {
struct snmp_pdu *pdu = NULL;
struct snmp_pdu *response = NULL;
struct variable_list *vars = NULL;
Expand Down Expand Up @@ -957,6 +957,8 @@ int snmp_count(host_t *current_host, char *snmp_oid) {
void snmp_snprint_value(char *obuf, size_t buf_len, const oid *objid, size_t objidlen, struct variable_list *variable) {
u_char *buf = NULL;
size_t out_len = 0;
UNUSED_PARAMETER(objid);
UNUSED_PARAMETER(objidlen);

if (buf_len > 0) {
if ((buf = (u_char *) calloc(buf_len, 1)) != 0) {
Expand Down
8 changes: 4 additions & 4 deletions snmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ extern void snmp_spine_init(void);
extern void snmp_spine_close(void);
extern void *snmp_host_init(int host_id, char *hostname, int snmp_version, char *snmp_community, char *snmp_username, char *snmp_password, char *snmp_auth_protocol, char *snmp_priv_passphrase, char *snmp_priv_protocol, char *snmp_context, char *snmp_engine_id, int snmp_port, int snmp_timeout);
extern void snmp_host_cleanup(void *snmp_session);
extern char *snmp_get_base(host_t *current_host, char *snmp_oid, bool should_fail);
extern char *snmp_get(host_t *current_host, char *snmp_oid);
extern char *snmp_getnext(host_t *current_host, char *snmp_oid);
extern int snmp_count(host_t *current_host, char *snmp_oid);
extern char *snmp_get_base(host_t *current_host, const char *snmp_oid, bool should_fail);
extern char *snmp_get(host_t *current_host, const char *snmp_oid);
extern char *snmp_getnext(host_t *current_host, const char *snmp_oid);
extern int snmp_count(host_t *current_host, const char *snmp_oid);
extern void snmp_get_multi(host_t *current_host, target_t *poller_items, snmp_oids_t *snmp_oids, int num_oids);
extern void snmp_snprint_value(char *obuf, size_t buf_len, const oid *objid, size_t objidlen, struct variable_list *variable);
12 changes: 6 additions & 6 deletions spine.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ poller_thread_t** details = NULL;

static char *getarg(char *opt, char ***pargv);
static void display_help(int only_version);
void poller_push_data_to_main();
void poller_push_data_to_main(void);

#ifdef HAVE_LCAP
/* This patch is adapted (copied) patch for ntpd from Jarno Huuskonen and
Expand Down Expand Up @@ -519,15 +519,15 @@ int main(int argc, char *argv[]) {

/* tokenize the debug devices */
if (strlen(set.selective_device_debug)) {
int i = 0;
int debug_idx = 0;
char *token;
SPINE_LOG_DEBUG(("DEBUG: Selective Debug Devices %s", set.selective_device_debug));
token = strtok(set.selective_device_debug, ",");
while(token && i < MAX_DEBUG_DEVICES - 1) {
debug_devices[i] = atoi(token);
debug_devices[i+1] = '\0';
while(token && debug_idx < MAX_DEBUG_DEVICES - 1) {
debug_devices[debug_idx] = atoi(token);
debug_devices[debug_idx+1] = '\0';
token = strtok(NULL, ",");
i++;
debug_idx++;
}
} else {
debug_devices[0] = '\0';
Expand Down
6 changes: 3 additions & 3 deletions sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int db_insert(MYSQL *mysql, int type, const char *query) {
}
}

int db_reconnect(MYSQL *mysql, int type, int error, char *function) {
int db_reconnect(MYSQL *mysql, int type, int error, const char *function) {
unsigned long mysql_thread = 0;
char query[100];

Expand Down Expand Up @@ -616,7 +616,7 @@ int db_column_exists(MYSQL *mysql, int type, const char *table, const char *colu
/* show the sql query */
SPINE_LOG_DEVDBG(("DEVDBG: db_column_exists('%s','%s'): %s", table, column, query_frag));

result = db_query(mysql, LOCAL, query_frag);
result = db_query(mysql, type, query_frag);
if (mysql_num_rows(result)) {
exists = TRUE;
} else {
Expand All @@ -625,4 +625,4 @@ int db_column_exists(MYSQL *mysql, int type, const char *table, const char *colu

db_free_result(result);
return exists;
}
}
3 changes: 1 addition & 2 deletions sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern void db_create_connection_pool(int type);
extern void db_close_connection_pool(int type);
extern pool_t *db_get_connection(int type);
extern void db_release_connection(int type, int id);
extern int db_reconnect(MYSQL *mysql, int type, int error, char *location);
extern int db_reconnect(MYSQL *mysql, int type, int error, const char *location);
extern int db_column_exists(MYSQL *mysql, int type, const char *table, const char *column);

extern int append_hostrange(char *obuf, const char *colname);
Expand All @@ -53,4 +53,3 @@ extern int append_hostrange(char *obuf, const char *colname);
die("FATAL: MySQL options unable to set %s option", desc);\
}\
}\

Loading
Loading