29 |
|
#include "statgrab.h" |
30 |
|
#include <time.h> |
31 |
|
#include <sys/socket.h> |
32 |
– |
#include <netinet/in.h> |
32 |
|
#include <arpa/inet.h> |
33 |
|
#include <syslog.h> |
34 |
|
|
35 |
< |
#define versionNo 0.8 |
35 |
> |
#define VERSION_NO "0.8" |
36 |
|
#define RECONFIGURE_RETURN_CODE 2 |
37 |
|
#define UDP_MAX_PACKET_SIZE 8192 |
38 |
|
#define PID_FILE "/var/tmp/.ihost.pid" |
139 |
|
return -1; |
140 |
|
} |
141 |
|
|
142 |
< |
if((ihost_state->my_ip=inet_ntoa(((struct sockaddr_in *)&ip)->sin_addr))==NULL){ |
142 |
> |
if((ihost_state->my_ip=strdup(inet_ntoa(((struct sockaddr_in *)&ip)->sin_addr)))==NULL){ |
143 |
|
logmessage(LOG_ERR, "Failed to get IP (%m)"); |
144 |
|
return -1; |
145 |
|
} |
390 |
|
xml_size+=strlen(stats[x]); |
391 |
|
} |
392 |
|
|
393 |
< |
xml_data=malloc(xml_size); |
393 |
> |
xml_data=malloc(xml_size+1); |
394 |
|
xml_data=strcpy(xml_data, stats[0]); |
395 |
< |
|
395 |
> |
free(stats[0]); |
396 |
|
for(x=1;x<NUM_STATS;x++){ |
397 |
|
strcat(xml_data, stats[x]); |
398 |
+ |
free(stats[x]); |
399 |
|
} |
400 |
|
|
401 |
|
xml_data_p=xml_data; |
423 |
|
logmessage(LOG_ERR, "Failed to resolve address %s (%m)", ihost_state->server_fqdn); |
424 |
|
return -1; |
425 |
|
} |
426 |
< |
logmessage(LOG_DEBUG,"Creating UDP connection to %s on %d",ihost_state->server_fqdn, ihost_state->server_udp_port); |
426 |
> |
logmessage(LOG_DEBUG,"Creating UDP socket to %s on %d",ihost_state->server_fqdn, ihost_state->server_udp_port); |
427 |
|
if((sd=socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0){ |
428 |
|
logmessage(LOG_ERR, "failed to create UDP socket (%m)"); |
429 |
|
return -1; |
509 |
|
break; |
510 |
|
|
511 |
|
case 'V': |
512 |
< |
errf("%s version %f",argv[0], versionNo); |
512 |
> |
errf("%s version %s",argv[0], VERSION_NO); |
513 |
|
break; |
514 |
|
|
515 |
|
default: |
578 |
|
if((f=fopen(PID_FILE,"w")) == NULL){ |
579 |
|
logmessage(LOG_WARNING, "Failed to write PID file"); |
580 |
|
}else{ |
581 |
< |
if((fprintf(f,"%d",(int)pid)) != sizeof(pid)){ |
581 |
> |
if((fprintf(f,"%d",(int)pid)) > 0 ){ |
582 |
|
logmessage(LOG_WARNING, "Failed to write PID file"); |
583 |
|
} |
584 |
|
if((fclose(f))!=0){ |
614 |
|
|
615 |
|
if(cur_time>=udp_time){ |
616 |
|
logmessage(LOG_DEBUG,"Sending udp data"); |
617 |
< |
|
617 |
> |
/* Work out how long it takes to get the stats for next time round |
618 |
> |
so the sleep time can be adjusted accordingly */ |
619 |
|
stat_grab_time=time(NULL); |
620 |
|
if((xml_stats=stat_grab(&ihost_state, counter++)) == NULL){ |
621 |
|
logmessage(LOG_ERR,"Failed to get stats (%m)"); |