]>
Commit | Line | Data |
---|---|---|
a60f27b1 JS |
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 | |
4 | @@ -1,5 +1,13 @@ | |
5 | The Cacti Group | spine | |
6 | ||
7 | +Patched 0.8.7g | |
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 | |
14 | + | |
15 | 0.8.7g | |
16 | -feature: Multi threaded host polling | |
17 | ||
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 | |
21 | @@ -57,21 +57,26 @@ | |
22 | host_data_ids = poller_details.host_data_ids; | |
23 | snprintf(host_time, SMALL_BUFSIZE, "%s", poller_details.host_time); | |
24 | ||
25 | - thread_mutex_unlock(LOCK_THREAD); | |
26 | - | |
27 | free(arg); | |
28 | ||
29 | + thread_ready = TRUE; | |
30 | + | |
31 | SPINE_LOG_DEBUG(("DEBUG: In Poller, About to Start Polling of Host")); | |
32 | ||
33 | poll_host(host_id, host_thread, last_host_thread, host_data_ids, host_time); | |
34 | ||
35 | - thread_mutex_lock(LOCK_THREAD); | |
36 | - | |
37 | + while (TRUE) { | |
38 | + if (thread_mutex_trylock(LOCK_THREAD) == 0) { | |
39 | active_threads--; | |
40 | + thread_mutex_unlock(LOCK_THREAD); | |
41 | ||
42 | - SPINE_LOG_DEBUG(("DEBUG: The Value of Active Threads is %i" ,active_threads)); | |
43 | + break; | |
44 | + } | |
45 | ||
46 | - thread_mutex_unlock(LOCK_THREAD); | |
47 | + usleep(100); | |
48 | + } | |
49 | + | |
50 | + SPINE_LOG_DEBUG(("DEBUG: The Value of Active Threads is %i" ,active_threads)); | |
51 | ||
52 | /* end the thread */ | |
53 | pthread_exit(0); | |
54 | @@ -965,7 +970,7 @@ | |
55 | poll_result = exec_poll(host, poller_items[i].arg1); | |
56 | ||
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)); | |
63 | @@ -998,7 +1003,7 @@ | |
64 | poll_result = php_cmd(poller_items[i].arg1, php_process); | |
65 | ||
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)); | |
72 | @@ -1247,7 +1252,7 @@ | |
73 | if (is_numeric(result)) { | |
74 | return TRUE; | |
75 | }else{ | |
76 | - if (is_multipart_output(result)) { | |
77 | + if (is_multipart_output(trim(result))) { | |
78 | return TRUE; | |
79 | }else{ | |
80 | return FALSE; | |
81 | @@ -1290,7 +1295,7 @@ | |
82 | ||
83 | /* compensate for back slashes in arguments */ | |
84 | #if defined(__CYGWIN__) | |
85 | - proc_command = add_slashes(command, 2); | |
86 | + proc_command = add_slashes(command); | |
87 | #else | |
88 | proc_command = command; | |
89 | #endif | |
90 | @@ -1340,7 +1345,7 @@ | |
91 | FD_SET(cmd_fd, &fds); | |
92 | ||
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)) { | |
96 | case -1: | |
97 | switch (errno) { | |
98 | case EBADF: | |
99 | @@ -1381,11 +1386,13 @@ | |
100 | break; | |
101 | } | |
102 | case 0: | |
103 | + #ifdef USING_TPOPEN | |
104 | SPINE_LOG(("Host[%i] ERROR: The POPEN timed out", current_host->id)); | |
105 | ||
106 | - #ifdef USING_TPOPEN | |
107 | close_fd = FALSE; | |
108 | #else | |
109 | + SPINE_LOG(("Host[%i] ERROR: The NIFTY POPEN timed out", current_host->id)); | |
110 | + | |
111 | pid = nft_pchild(cmd_fd); | |
112 | kill(pid, SIGKILL); | |
113 | #endif | |
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 | |
117 | @@ -499,13 +499,9 @@ | |
118 | size_t out_len = 0; | |
119 | ||
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); | |
125 | }else{ | |
126 | - snprintf(obuf, buf_len, "%s [TRUNCATED]", buf); | |
127 | - } | |
128 | - }else{ | |
129 | SET_UNDEFINED(obuf); | |
130 | } | |
131 | ||
132 | @@ -528,6 +524,7 @@ | |
133 | int i; | |
134 | int array_count; | |
135 | int index_count; | |
136 | + char temp_result[RESULTS_BUFFER]; | |
137 | ||
138 | struct nameStruct { | |
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)) { | |
143 | #ifdef USE_NET_SNMP | |
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); | |
146 | #else | |
147 | - sprint_value(snmp_oids[i].result, vars->name, vars->name_length, vars); | |
148 | + sprint_value(temp_result, vars->name, vars->name_length, vars); | |
149 | #endif | |
150 | ||
151 | + snprintf(snmp_oids[i].result, RESULTS_BUFFER, "%s", trim(temp_result)); | |
152 | + | |
153 | vars = vars->next_variable; | |
154 | } | |
155 | } | |
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 | |
159 | @@ -94,6 +94,7 @@ | |
160 | int num_hosts = 0; | |
161 | int active_threads = 0; | |
162 | int active_scripts = 0; | |
163 | +int thread_ready = FALSE; | |
164 | ||
165 | config_t set; | |
166 | php_t *php_processes = 0; | |
167 | @@ -134,7 +135,7 @@ | |
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; | |
176 | @@ -196,6 +197,7 @@ | |
177 | ||
178 | /* we attempt to support scripts better in cygwin */ | |
179 | #if defined(__CYGWIN__) | |
180 | + setenv("CYGWIN", "nodosfilewarning", 1); | |
181 | if (file_exists("./sh.exe")) { | |
182 | set.cygwinshloc = 0; | |
183 | printf("NOTE: The Shell Command Exists in the current directory\n"); | |
184 | @@ -281,7 +283,7 @@ | |
185 | ||
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)); | |
190 | } | |
191 | ||
192 | else if (STRMATCH(arg, "-h") || | |
193 | @@ -584,6 +586,11 @@ | |
194 | poller_details->host_data_ids = itemsPT; | |
195 | poller_details->host_time = host_time; | |
196 | ||
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 | |
199 | + */ | |
200 | + thread_ready = FALSE; | |
201 | + | |
202 | /* create child process */ | |
203 | thread_status = pthread_create(&threads[device_counter], &attr, child, poller_details); | |
204 | ||
205 | @@ -596,6 +603,11 @@ | |
206 | } | |
207 | active_threads++; | |
208 | ||
209 | + /* wait for the child to read and process the structure */ | |
210 | + while (!thread_ready) { | |
211 | + usleep(internal_thread_sleep); | |
212 | + } | |
213 | + | |
214 | SPINE_LOG_DEBUG(("DEBUG: The Value of Active Threads is %i", active_threads)); | |
215 | ||
216 | break; | |
217 | @@ -603,7 +615,7 @@ | |
218 | SPINE_LOG(("ERROR: The System Lacked the Resources to Create a Thread")); | |
219 | break; | |
220 | case EFAULT: | |
221 | - SPINE_LOG(("ERROR: The Thread or Attribute Was Invalid")); | |
222 | + SPINE_LOG(("ERROR: The Thread or Attribute were Invalid")); | |
223 | break; | |
224 | case EINVAL: | |
225 | SPINE_LOG(("ERROR: The Thread Attribute is Not Initialized")); | |
226 | @@ -613,6 +625,8 @@ | |
227 | break; | |
228 | } | |
229 | ||
230 | + thread_mutex_unlock(LOCK_THREAD); | |
231 | + | |
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 | |
238 | @@ -504,5 +504,6 @@ | |
239 | extern char start_datetime[20]; | |
240 | extern char config_paths[CONFIG_PATHS][BUFSIZE]; | |
241 | extern int active_threads; | |
242 | +extern int thread_ready; | |
243 | ||
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 | |
248 | @@ -755,7 +755,7 @@ | |
249 | /* empty string is not all digits */ | |
250 | if ( *string == '\0' ) return FALSE; | |
251 | ||
252 | - while ( isdigit(*string) ) | |
253 | + while ( isdigit((int)*string) ) | |
254 | string++; | |
255 | ||
256 | return *string == '\0'; | |
257 | @@ -773,7 +773,7 @@ | |
258 | */ | |
259 | int is_ipaddress(const char *string) { | |
260 | while (*string) { | |
261 | - if ((isdigit(*string)) || | |
262 | + if ((isdigit((int)*string)) || | |
263 | (*string == '.') || | |
264 | (*string == ':')) { | |
265 | string++; | |
266 | @@ -887,7 +887,7 @@ | |
267 | i = strlen(string); | |
268 | ||
269 | while (i >= 0) { | |
270 | - if (isdigit(string[i])) { | |
271 | + if (isdigit((int)string[i])) { | |
272 | break; | |
273 | }else{ | |
274 | string[i] = '\0'; | |
275 | @@ -898,17 +898,15 @@ | |
276 | return string; | |
277 | } | |
278 | ||
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 | |
285 | * | |
286 | * \return a pointer to the modified string. Variable must be freed by parent. | |
287 | * | |
288 | */ | |
289 | -char *add_slashes(char *string, int arguments_2_strip) { | |
290 | +char *add_slashes(char *string) { | |
291 | int length; | |
292 | - int space_count; | |
293 | int position; | |
294 | int new_position; | |
295 | char *return_str; | |
296 | @@ -919,9 +917,8 @@ | |
297 | return_str[0] = '\0'; | |
298 | ||
299 | length = strlen(string); | |
300 | - space_count = 0; | |
301 | position = 0; | |
302 | - new_position = position; | |
303 | + new_position = 0; | |
304 | ||
305 | /* simply return on blank string */ | |
306 | if (!length) { | |
307 | @@ -931,17 +928,9 @@ | |
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] = '/'; | |
314 | - }else{ | |
315 | - return_str[new_position] = string[position]; | |
316 | - } | |
317 | - /* end of argument detected */ | |
318 | - }else if (string[position] == ' ') { | |
319 | - return_str[new_position] = ' '; | |
320 | - space_count++; | |
321 | - /* normal character detected */ | |
322 | + return_str[new_position] = '\\'; | |
323 | + new_position++; | |
324 | + return_str[new_position] = '\\'; | |
325 | }else{ | |
326 | return_str[new_position] = string[position]; | |
327 | } | |
328 | @@ -1248,7 +1237,7 @@ | |
329 | seteuid(0); | |
330 | ||
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; | |
335 | }else{ | |
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 | |
340 | @@ -54,7 +54,7 @@ | |
341 | extern int is_hexadecimal(const char * str, const short ignore_space); | |
342 | ||
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); |