373 |
|
char *stats[NUM_STATS]; |
374 |
|
char *xml_data=NULL; |
375 |
|
char *xml_data_p; |
376 |
+ |
int xml_size=0; |
377 |
|
int x=0; |
378 |
|
|
379 |
|
logmessage(LOG_DEBUG,"get_cpu_stats"); |
394 |
|
stats[7]=get_swap_stats(); |
395 |
|
logmessage(LOG_DEBUG,"get_user_stats"); |
396 |
|
stats[8]=get_user_stats(); |
397 |
+ |
|
398 |
|
|
399 |
< |
for(;x<NUM_STATS;x++){ |
399 |
> |
for(x=0;x<NUM_STATS;x++){ |
400 |
|
if(stats[x]==NULL){ |
401 |
|
logmessage(LOG_ERR,"Function returned NULL"); |
402 |
|
return NULL; |
403 |
|
} |
404 |
< |
if(xml_data==NULL){ |
403 |
< |
if((xml_data=strf("%s", stats[x])) == NULL){ |
404 |
< |
logmessage(LOG_ERR, "str failed (%m)"); |
405 |
< |
return NULL; |
406 |
< |
} |
407 |
< |
}else{ |
408 |
< |
xml_data_p=xml_data; |
409 |
< |
if((xml_data=strf("%s%s", xml_data, stats[x])) == NULL){ |
410 |
< |
logmessage(LOG_ERR, "str failed (%m)"); |
411 |
< |
return NULL; |
412 |
< |
} |
413 |
< |
free(xml_data_p); |
414 |
< |
} |
415 |
< |
free(stats[x]); |
404 |
> |
xml_size+=strlen(stats[x]); |
405 |
|
} |
406 |
+ |
|
407 |
+ |
xml_data=malloc(xml_size); |
408 |
+ |
xml_data=strcpy(xml_data, stats[0]); |
409 |
+ |
|
410 |
+ |
for(x=1;x<NUM_STATS;x++){ |
411 |
+ |
strcat(xml_data, stats[x]); |
412 |
+ |
} |
413 |
+ |
|
414 |
|
xml_data_p=xml_data; |
415 |
|
xml_data=strf("<packet seq_no=\"%d\" machine_name=\"%s\" date=\"%ld\" type=\"data\" ip=\"%s\" key=\"%s\">%s</packet>", counter, ihost_state->my_fqdn, time(NULL), ihost_state->my_ip, ihost_state->key, xml_data); |
416 |
|
free(xml_data_p); |