1 diff -ruBbd cacti-spine-0.8.7g.old/ChangeLog cacti-spine-0.8.7g/ChangeLog
2 --- cacti-spine-0.8.7g.old/ChangeLog 2010-07-09 19:25:56.000000000 -0400
3 +++ cacti-spine-0.8.7g/ChangeLog 2010-08-31 20:21:22.000000000 -0400
5 The Cacti Group | spine
8 +-bug#0001669: Problems with getting data from script using SPINE on Windows Server 2003 x32
9 +-bug#0001829: Wrong string numerical value got from Spine SNMP poller
10 +-bug: Net-snmp API issues cause spine crashes with some SNMP agents
11 +-bug: Host list not properly initialized
12 +-bug: Mutex locking issues cause deadlocks in Windows
13 +-bug: Escape windows type back slashes in scripts
16 -feature: Multi threaded host polling
18 diff -ruBbd cacti-spine-0.8.7g.old/poller.c cacti-spine-0.8.7g/poller.c
19 --- cacti-spine-0.8.7g.old/poller.c 2010-07-09 17:39:53.000000000 -0400
20 +++ cacti-spine-0.8.7g/poller.c 2010-08-31 20:18:58.000000000 -0400
22 host_data_ids = poller_details.host_data_ids;
23 snprintf(host_time, SMALL_BUFSIZE, "%s", poller_details.host_time);
25 - thread_mutex_unlock(LOCK_THREAD);
29 + thread_ready = TRUE;
31 SPINE_LOG_DEBUG(("DEBUG: In Poller, About to Start Polling of Host"));
33 poll_host(host_id, host_thread, last_host_thread, host_data_ids, host_time);
35 - thread_mutex_lock(LOCK_THREAD);
38 + if (thread_mutex_trylock(LOCK_THREAD) == 0) {
40 + thread_mutex_unlock(LOCK_THREAD);
42 - SPINE_LOG_DEBUG(("DEBUG: The Value of Active Threads is %i" ,active_threads));
46 - thread_mutex_unlock(LOCK_THREAD);
50 + SPINE_LOG_DEBUG(("DEBUG: The Value of Active Threads is %i" ,active_threads));
55 poll_result = exec_poll(host, poller_items[i].arg1);
57 /* process the result */
58 - if ((is_numeric(poll_result)) || (is_multipart_output(poll_result))) {
59 + if ((is_numeric(poll_result)) || (is_multipart_output(trim(poll_result)))) {
60 snprintf(poller_items[i].result, RESULTS_BUFFER, "%s", poll_result);
61 }else if (is_hexadecimal(snmp_oids[j].result, TRUE)) {
62 snprintf(poller_items[i].result, RESULTS_BUFFER, "%lld", hex2dec(poll_result));
64 poll_result = php_cmd(poller_items[i].arg1, php_process);
66 /* process the output */
67 - if ((is_numeric(poll_result)) || (is_multipart_output(poll_result))) {
68 + if ((is_numeric(poll_result)) || (is_multipart_output(trim(poll_result)))) {
69 snprintf(poller_items[i].result, RESULTS_BUFFER, "%s", poll_result);
70 }else if (is_hexadecimal(snmp_oids[j].result, TRUE)) {
71 snprintf(poller_items[i].result, RESULTS_BUFFER, "%lld", hex2dec(poll_result));
73 if (is_numeric(result)) {
76 - if (is_multipart_output(result)) {
77 + if (is_multipart_output(trim(result))) {
83 /* compensate for back slashes in arguments */
84 #if defined(__CYGWIN__)
85 - proc_command = add_slashes(command, 2);
86 + proc_command = add_slashes(command);
88 proc_command = command;
93 /* wait x seonds for pipe response */
94 - switch (select(cmd_fd+1, &fds, NULL, NULL, &timeout)) {
95 + switch (select(FD_SETSIZE, &fds, NULL, NULL, &timeout)) {
99 @@ -1381,11 +1386,13 @@
103 + #ifdef USING_TPOPEN
104 SPINE_LOG(("Host[%i] ERROR: The POPEN timed out", current_host->id));
106 - #ifdef USING_TPOPEN
109 + SPINE_LOG(("Host[%i] ERROR: The NIFTY POPEN timed out", current_host->id));
111 pid = nft_pchild(cmd_fd);
114 diff -ruBbd cacti-spine-0.8.7g.old/snmp.c cacti-spine-0.8.7g/snmp.c
115 --- cacti-spine-0.8.7g.old/snmp.c 2010-07-09 17:39:53.000000000 -0400
116 +++ cacti-spine-0.8.7g/snmp.c 2010-08-31 20:18:58.000000000 -0400
120 if ((buf = (u_char *) calloc(buf_len, 1)) != 0) {
121 - if (sprint_realloc_value(&buf, &buf_len, &out_len, 1,
122 - objid, objidlen, variable)) {
123 + sprint_realloc_by_type(&buf, &buf_len, &out_len, 1, variable, NULL, NULL, NULL);
124 snprintf(obuf, buf_len, "%s", buf);
126 - snprintf(obuf, buf_len, "%s [TRUNCATED]", buf);
136 + char temp_result[RESULTS_BUFFER];
139 oid name[MAX_OID_LEN];
140 @@ -570,11 +567,13 @@
141 for(i = 0; i < num_oids && vars; i++) {
142 if (!IS_UNDEFINED(snmp_oids[i].result)) {
144 - snmp_snprint_value(snmp_oids[i].result, RESULTS_BUFFER, vars->name, vars->name_length, vars);
145 + snmp_snprint_value(temp_result, RESULTS_BUFFER, vars->name, vars->name_length, vars);
147 - sprint_value(snmp_oids[i].result, vars->name, vars->name_length, vars);
148 + sprint_value(temp_result, vars->name, vars->name_length, vars);
151 + snprintf(snmp_oids[i].result, RESULTS_BUFFER, "%s", trim(temp_result));
153 vars = vars->next_variable;
156 diff -ruBbd cacti-spine-0.8.7g.old/spine.c cacti-spine-0.8.7g/spine.c
157 --- cacti-spine-0.8.7g.old/spine.c 2010-07-09 17:39:53.000000000 -0400
158 +++ cacti-spine-0.8.7g/spine.c 2010-08-31 20:18:58.000000000 -0400
161 int active_threads = 0;
162 int active_scripts = 0;
163 +int thread_ready = FALSE;
166 php_t *php_processes = 0;
168 int poller_counter = 0;
169 int last_active_threads = 0;
170 int valid_conf_file = FALSE;
171 - long int EXTERNAL_THREAD_SLEEP = 5000;
172 + long int EXTERNAL_THREAD_SLEEP = 50;
173 long int internal_thread_sleep;
174 char querybuf[BIG_BUFSIZE], *qp = querybuf;
175 char *host_time = NULL;
178 /* we attempt to support scripts better in cygwin */
179 #if defined(__CYGWIN__)
180 + setenv("CYGWIN", "nodosfilewarning", 1);
181 if (file_exists("./sh.exe")) {
183 printf("NOTE: The Shell Command Exists in the current directory\n");
186 else if (STRMATCH(arg, "-H") ||
187 STRIMATCH(arg, "--hostlist")) {
188 - snprintf(set.host_id_list, BIG_BUFSIZE, getarg(opt, &argv));
189 + snprintf(set.host_id_list, BIG_BUFSIZE, "%s", getarg(opt, &argv));
192 else if (STRMATCH(arg, "-h") ||
194 poller_details->host_data_ids = itemsPT;
195 poller_details->host_time = host_time;
197 + /* this variable tells us that the child had loaded the poller
198 + * poller_details structure and we can move on to the next thread
200 + thread_ready = FALSE;
202 /* create child process */
203 thread_status = pthread_create(&threads[device_counter], &attr, child, poller_details);
209 + /* wait for the child to read and process the structure */
210 + while (!thread_ready) {
211 + usleep(internal_thread_sleep);
214 SPINE_LOG_DEBUG(("DEBUG: The Value of Active Threads is %i", active_threads));
218 SPINE_LOG(("ERROR: The System Lacked the Resources to Create a Thread"));
221 - SPINE_LOG(("ERROR: The Thread or Attribute Was Invalid"));
222 + SPINE_LOG(("ERROR: The Thread or Attribute were Invalid"));
225 SPINE_LOG(("ERROR: The Thread Attribute is Not Initialized"));
230 + thread_mutex_unlock(LOCK_THREAD);
232 /* get current time and exit program if time limit exceeded */
233 if (poller_counter >= 20) {
234 current_time = get_time_as_double();
235 diff -ruBbd cacti-spine-0.8.7g.old/spine.h cacti-spine-0.8.7g/spine.h
236 --- cacti-spine-0.8.7g.old/spine.h 2010-07-09 17:39:53.000000000 -0400
237 +++ cacti-spine-0.8.7g/spine.h 2010-08-31 20:18:58.000000000 -0400
239 extern char start_datetime[20];
240 extern char config_paths[CONFIG_PATHS][BUFSIZE];
241 extern int active_threads;
242 +extern int thread_ready;
244 #endif /* not _SPINE_H_ */
245 diff -ruBbd cacti-spine-0.8.7g.old/util.c cacti-spine-0.8.7g/util.c
246 --- cacti-spine-0.8.7g.old/util.c 2010-07-09 17:39:53.000000000 -0400
247 +++ cacti-spine-0.8.7g/util.c 2010-08-31 20:18:58.000000000 -0400
249 /* empty string is not all digits */
250 if ( *string == '\0' ) return FALSE;
252 - while ( isdigit(*string) )
253 + while ( isdigit((int)*string) )
256 return *string == '\0';
259 int is_ipaddress(const char *string) {
261 - if ((isdigit(*string)) ||
262 + if ((isdigit((int)*string)) ||
270 - if (isdigit(string[i])) {
271 + if (isdigit((int)string[i])) {
275 @@ -898,17 +898,15 @@
279 -/*! \fn char *add_slashes(char *string, int arguments_2_strip)
280 - * \brief change all backslashes to forward slashes for the first n arguements.
281 +/*! \fn char *add_slashes(char *string)
282 + * \brief add escaping to back slashes on for Windows type commands.
283 * \param string the string to replace slashes
284 - * \param arguments_2_strip the number of space delimited arguments to reverse
286 * \return a pointer to the modified string. Variable must be freed by parent.
289 -char *add_slashes(char *string, int arguments_2_strip) {
290 +char *add_slashes(char *string) {
297 return_str[0] = '\0';
299 length = strlen(string);
302 - new_position = position;
305 /* simply return on blank string */
308 while (position < length) {
309 /* backslash detected, change to forward slash */
310 if (string[position] == '\\') {
311 - /* only add slashes for first x arguments */
312 - if (space_count < arguments_2_strip) {
313 - return_str[new_position] = '/';
315 - return_str[new_position] = string[position];
317 - /* end of argument detected */
318 - }else if (string[position] == ' ') {
319 - return_str[new_position] = ' ';
321 - /* normal character detected */
322 + return_str[new_position] = '\\';
324 + return_str[new_position] = '\\';
326 return_str[new_position] = string[position];
328 @@ -1248,7 +1237,7 @@
331 if (geteuid() != 0) {
332 - SPINE_LOG_DEBUG(("WARNING: Spine NOT running asroot. This is require if using ICMP. Please run \"chmod +s;chown root:root spine\" to resolve."));
333 + SPINE_LOG_DEBUG(("WARNING: Spine NOT running asroot. This is required if using ICMP. Please run \"chmod +s;chown root:root spine\" to resolve."));
334 set.icmp_avail = FALSE;
336 SPINE_LOG_DEBUG(("DEBUG: Spine is running asroot."));
337 diff -ruBbd cacti-spine-0.8.7g.old/util.h cacti-spine-0.8.7g/util.h
338 --- cacti-spine-0.8.7g.old/util.h 2010-07-09 17:39:53.000000000 -0400
339 +++ cacti-spine-0.8.7g/util.h 2010-08-31 20:18:58.000000000 -0400
341 extern int is_hexadecimal(const char * str, const short ignore_space);
343 /* string and file functions */
344 -extern char *add_slashes(char *string, int arguments_2_strip);
345 +extern char *add_slashes(char *string);
346 extern int file_exists(const char *filename);
347 extern char *strip_alpha(char *string);
348 extern char *strncopy(char *dst, const char *src, size_t n);