ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/ihost/ihost.c
(Generate patch)

Comparing projects/cms/source/ihost/ihost.c (file contents):
Revision 1.21 by pajs, Tue May 21 15:44:34 2002 UTC vs.
Revision 1.25 by pajs, Wed May 22 09:01:01 2002 UTC

# Line 1 | Line 1
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
# Line 29 | Line 30
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 "1.0rc1"
37   #define RECONFIGURE_RETURN_CODE 2
38   #define UDP_MAX_PACKET_SIZE 8192
39   #define PID_FILE "/var/tmp/.ihost.pid"
# Line 139 | Line 139 | int ihost_configure(ihost_state_t *ihost_state){
139                  logmessage(LOG_ERR, "sa family is wrong type");
140                  return -1;
141          }
142 <        
143 <        if((ihost_state->my_ip=inet_ntoa(((struct sockaddr_in *)&ip)->sin_addr))==NULL){
142 >
143 >        if(ihost_state->my_ip!=NULL) free(ihost_state->my_ip);  
144 >        if((ihost_state->my_ip=strdup(inet_ntoa(((struct sockaddr_in *)&ip)->sin_addr)))==NULL){
145                  logmessage(LOG_ERR, "Failed to get IP (%m)");
146                  return -1;
147          }      
# Line 391 | Line 392 | char *stat_grab(ihost_state_t *ihost_state, int counte
392                  xml_size+=strlen(stats[x]);
393          }
394  
395 <        xml_data=malloc(xml_size);
395 >        xml_data=malloc(xml_size+1);
396          xml_data=strcpy(xml_data, stats[0]);
397 <        
397 >        free(stats[0]);
398          for(x=1;x<NUM_STATS;x++){
399                  strcat(xml_data, stats[x]);
400 +                free(stats[x]);
401          }
402  
403          xml_data_p=xml_data;
# Line 423 | Line 425 | int send_stats(ihost_state_t *ihost_state, char *data_
425                  logmessage(LOG_ERR, "Failed to resolve address %s (%m)", ihost_state->server_fqdn);
426                  return -1;
427          }
428 <        logmessage(LOG_DEBUG,"Creating UDP connection to %s on %d",ihost_state->server_fqdn, ihost_state->server_udp_port);
428 >        logmessage(LOG_DEBUG,"Creating UDP socket to %s on %d",ihost_state->server_fqdn, ihost_state->server_udp_port);
429          if((sd=socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0){
430                  logmessage(LOG_ERR, "failed to create UDP socket (%m)");
431                  return -1;
# Line 484 | Line 486 | int main(int argc, char **argv){
486          ihost_state.last_modified=NULL;
487          ihost_state.files_list=NULL;
488          ihost_state.key=NULL;
489 +        ihost_state.my_ip=NULL;
490  
491          errf_set_progname(argv[0]);
492          
# Line 509 | Line 512 | int main(int argc, char **argv){
512                                  break;
513  
514                          case 'V':
515 <                                errf("%s version %f",argv[0], versionNo);
515 >                                errf("%s version %s",argv[0], VERSION_NO);
516                                  break;
517  
518                          default:
# Line 576 | Line 579 | int main(int argc, char **argv){
579          logmessage(LOG_DEBUG,"Writing PID FILE");
580          pid=getpid();
581          if((f=fopen(PID_FILE,"w")) == NULL){
582 <                logmessage(LOG_WARNING, "Failed to write PID file");
582 >                logmessage(LOG_WARNING, "Failed to write PID file (%m)");
583          }else{
584 <                if((fprintf(f,"%d",(int)pid)) != sizeof(pid)){
585 <                        logmessage(LOG_WARNING, "Failed to write PID file");
584 >                if((fprintf(f,"%d",(int)pid)) <= 0 ){
585 >                        logmessage(LOG_WARNING, "Failed to write PID file (%m)");
586                  }
587                  if((fclose(f))!=0){
588                          logmessage(LOG_ERR, "failed to close PID file");
# Line 614 | Line 617 | int main(int argc, char **argv){
617  
618                  if(cur_time>=udp_time){
619                          logmessage(LOG_DEBUG,"Sending udp data");
620 <
620 >                        /* Work out how long it takes to get the stats for next time round
621 >                           so the sleep time can be adjusted accordingly */
622                          stat_grab_time=time(NULL);
623                          if((xml_stats=stat_grab(&ihost_state, counter++)) == NULL){
624                                  logmessage(LOG_ERR,"Failed to get stats (%m)");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines