--- projects/cms/source/ihost/ihost.c 2002/05/21 15:44:34 1.21 +++ projects/cms/source/ihost/ihost.c 2002/05/21 16:47:12 1.23 @@ -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 @@ -29,11 +30,10 @@ #include "statgrab.h" #include #include -#include #include #include -#define versionNo 0.8 +#define VERSION_NO "0.8" #define RECONFIGURE_RETURN_CODE 2 #define UDP_MAX_PACKET_SIZE 8192 #define PID_FILE "/var/tmp/.ihost.pid" @@ -140,7 +140,7 @@ int ihost_configure(ihost_state_t *ihost_state){ return -1; } - if((ihost_state->my_ip=inet_ntoa(((struct sockaddr_in *)&ip)->sin_addr))==NULL){ + 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 +391,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; @@ -509,7 +510,7 @@ int main(int argc, char **argv){ break; case 'V': - errf("%s version %f",argv[0], versionNo); + errf("%s version %s",argv[0], VERSION_NO); break; default: @@ -578,7 +579,7 @@ int main(int argc, char **argv){ if((f=fopen(PID_FILE,"w")) == NULL){ logmessage(LOG_WARNING, "Failed to write PID file"); }else{ - if((fprintf(f,"%d",(int)pid)) != sizeof(pid)){ + if((fprintf(f,"%d",(int)pid)) > 0 ){ logmessage(LOG_WARNING, "Failed to write PID file"); } if((fclose(f))!=0){ @@ -614,7 +615,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)");