36 |
|
#define versionNo 0.8 |
37 |
|
#define RECONFIGURE_RETURN_CODE 2 |
38 |
|
#define UDP_MAX_PACKET_SIZE 8192 |
39 |
+ |
#define PID_FILE "/var/tmp/.ihost.pid" |
40 |
|
|
41 |
|
#define logmessage(level, ...) do { cur_level = level; errf(__VA_ARGS__); } while (0) |
42 |
|
|
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){ |
402 |
< |
if((xml_data=strf("%s", stats[x])) == NULL){ |
403 |
< |
logmessage(LOG_ERR, "str failed (%m)"); |
404 |
< |
return NULL; |
405 |
< |
} |
406 |
< |
}else{ |
407 |
< |
xml_data_p=xml_data; |
408 |
< |
if((xml_data=strf("%s%s", xml_data, stats[x])) == NULL){ |
409 |
< |
logmessage(LOG_ERR, "str failed (%m)"); |
410 |
< |
return NULL; |
411 |
< |
} |
412 |
< |
free(xml_data_p); |
413 |
< |
} |
414 |
< |
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); |
483 |
|
extern int syslog_logging; |
484 |
|
extern int log_level; |
485 |
|
extern int cur_level; |
486 |
+ |
FILE *f; |
487 |
|
|
488 |
|
log_level=1; |
489 |
|
cur_level=1; |
584 |
|
/* Print out everything its doing */ |
585 |
|
log_level=LOG_DEBUG; |
586 |
|
break; |
587 |
+ |
} |
588 |
+ |
|
589 |
+ |
logmessage(LOG_DEBUG,"Writing PID FILE"); |
590 |
+ |
pid=getpid(); |
591 |
+ |
if((f=fopen(PID_FILE,"w")) == NULL){ |
592 |
+ |
logmessage(LOG_WARNING, "Failed to write PID file"); |
593 |
+ |
}else{ |
594 |
+ |
if((fprintf(f,"%d",(int)pid)) != sizeof(pid)){ |
595 |
+ |
logmessage(LOG_WARNING, "Failed to write PID file"); |
596 |
+ |
} |
597 |
+ |
if((fclose(f))!=0){ |
598 |
+ |
logmessage(LOG_ERR, "failed to close PID file"); |
599 |
+ |
exit(1); |
600 |
+ |
} |
601 |
|
} |
602 |
|
|
603 |
|
if(ihost_configure(&ihost_state)!=0){ |