--- projects/cms/source/ihost/ihost.c 2002/05/21 15:44:34 1.21 +++ projects/cms/source/ihost/ihost.c 2002/05/29 23:03:53 1.27 @@ -1,5 +1,6 @@ /* * i-scream central monitoring system + * http://www.i-scream.org.uk * Copyright (C) 2000-2002 i-scream * * This program is free software; you can redistribute it and/or @@ -17,6 +18,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -29,14 +34,10 @@ #include "statgrab.h" #include #include -#include #include #include -#define versionNo 0.8 #define RECONFIGURE_RETURN_CODE 2 -#define UDP_MAX_PACKET_SIZE 8192 -#define PID_FILE "/var/tmp/.ihost.pid" #define logmessage(level, ...) do { cur_level = level; errf(__VA_ARGS__); } while (0) @@ -139,8 +140,9 @@ int ihost_configure(ihost_state_t *ihost_state){ logmessage(LOG_ERR, "sa family is wrong type"); return -1; } - - if((ihost_state->my_ip=inet_ntoa(((struct sockaddr_in *)&ip)->sin_addr))==NULL){ + + if(ihost_state->my_ip!=NULL) free(ihost_state->my_ip); + if((ihost_state->my_ip=strdup(inet_ntoa(((struct sockaddr_in *)&ip)->sin_addr)))==NULL){ logmessage(LOG_ERR, "Failed to get IP (%m)"); return -1; } @@ -391,11 +393,12 @@ char *stat_grab(ihost_state_t *ihost_state, int counte xml_size+=strlen(stats[x]); } - xml_data=malloc(xml_size); + xml_data=malloc(xml_size+1); xml_data=strcpy(xml_data, stats[0]); - + free(stats[0]); for(x=1;xserver_fqdn); return -1; } - logmessage(LOG_DEBUG,"Creating UDP connection to %s on %d",ihost_state->server_fqdn, ihost_state->server_udp_port); + logmessage(LOG_DEBUG,"Creating UDP socket to %s on %d",ihost_state->server_fqdn, ihost_state->server_udp_port); if((sd=socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0){ logmessage(LOG_ERR, "failed to create UDP socket (%m)"); return -1; @@ -484,6 +487,7 @@ int main(int argc, char **argv){ ihost_state.last_modified=NULL; ihost_state.files_list=NULL; ihost_state.key=NULL; + ihost_state.my_ip=NULL; errf_set_progname(argv[0]); @@ -509,7 +513,7 @@ int main(int argc, char **argv){ break; case 'V': - errf("%s version %f",argv[0], versionNo); + errf("%s version %s",argv[0], VERSION); break; default: @@ -576,10 +580,10 @@ int main(int argc, char **argv){ logmessage(LOG_DEBUG,"Writing PID FILE"); pid=getpid(); if((f=fopen(PID_FILE,"w")) == NULL){ - logmessage(LOG_WARNING, "Failed to write PID file"); + logmessage(LOG_WARNING, "Failed to write PID file (%m)"); }else{ - if((fprintf(f,"%d",(int)pid)) != sizeof(pid)){ - logmessage(LOG_WARNING, "Failed to write PID file"); + if((fprintf(f,"%d",(int)pid)) <= 0 ){ + logmessage(LOG_WARNING, "Failed to write PID file (%m)"); } if((fclose(f))!=0){ logmessage(LOG_ERR, "failed to close PID file"); @@ -614,7 +618,8 @@ int main(int argc, char **argv){ if(cur_time>=udp_time){ logmessage(LOG_DEBUG,"Sending udp data"); - + /* Work out how long it takes to get the stats for next time round + so the sleep time can be adjusted accordingly */ stat_grab_time=time(NULL); if((xml_stats=stat_grab(&ihost_state, counter++)) == NULL){ logmessage(LOG_ERR,"Failed to get stats (%m)");