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