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.27 by tdb, Wed May 29 23:03:53 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 17 | Line 18
18   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19   */
20  
21 + #ifdef HAVE_CONFIG_H
22 + #include "config.h"
23 + #endif
24 +
25   #include <stdio.h>
26   #include <stdlib.h>
27   #include <sys/types.h>
# Line 29 | Line 34
34   #include "statgrab.h"
35   #include <time.h>
36   #include <sys/socket.h>
32 #include <netinet/in.h>
37   #include <arpa/inet.h>
38   #include <syslog.h>
39  
36 #define versionNo 0.8
40   #define RECONFIGURE_RETURN_CODE 2
38 #define UDP_MAX_PACKET_SIZE 8192
39 #define PID_FILE "/var/tmp/.ihost.pid"
41  
42   #define logmessage(level, ...) do { cur_level = level; errf(__VA_ARGS__); } while (0)
43  
# Line 139 | Line 140 | int ihost_configure(ihost_state_t *ihost_state){
140                  logmessage(LOG_ERR, "sa family is wrong type");
141                  return -1;
142          }
143 <        
144 <        if((ihost_state->my_ip=inet_ntoa(((struct sockaddr_in *)&ip)->sin_addr))==NULL){
143 >
144 >        if(ihost_state->my_ip!=NULL) free(ihost_state->my_ip);  
145 >        if((ihost_state->my_ip=strdup(inet_ntoa(((struct sockaddr_in *)&ip)->sin_addr)))==NULL){
146                  logmessage(LOG_ERR, "Failed to get IP (%m)");
147                  return -1;
148          }      
# Line 391 | Line 393 | char *stat_grab(ihost_state_t *ihost_state, int counte
393                  xml_size+=strlen(stats[x]);
394          }
395  
396 <        xml_data=malloc(xml_size);
396 >        xml_data=malloc(xml_size+1);
397          xml_data=strcpy(xml_data, stats[0]);
398 <        
398 >        free(stats[0]);
399          for(x=1;x<NUM_STATS;x++){
400                  strcat(xml_data, stats[x]);
401 +                free(stats[x]);
402          }
403  
404          xml_data_p=xml_data;
# Line 423 | Line 426 | int send_stats(ihost_state_t *ihost_state, char *data_
426                  logmessage(LOG_ERR, "Failed to resolve address %s (%m)", ihost_state->server_fqdn);
427                  return -1;
428          }
429 <        logmessage(LOG_DEBUG,"Creating UDP connection to %s on %d",ihost_state->server_fqdn, ihost_state->server_udp_port);
429 >        logmessage(LOG_DEBUG,"Creating UDP socket to %s on %d",ihost_state->server_fqdn, ihost_state->server_udp_port);
430          if((sd=socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0){
431                  logmessage(LOG_ERR, "failed to create UDP socket (%m)");
432                  return -1;
# Line 484 | Line 487 | int main(int argc, char **argv){
487          ihost_state.last_modified=NULL;
488          ihost_state.files_list=NULL;
489          ihost_state.key=NULL;
490 +        ihost_state.my_ip=NULL;
491  
492          errf_set_progname(argv[0]);
493          
# Line 509 | Line 513 | int main(int argc, char **argv){
513                                  break;
514  
515                          case 'V':
516 <                                errf("%s version %f",argv[0], versionNo);
516 >                                errf("%s version %s",argv[0], VERSION);
517                                  break;
518  
519                          default:
# Line 576 | Line 580 | int main(int argc, char **argv){
580          logmessage(LOG_DEBUG,"Writing PID FILE");
581          pid=getpid();
582          if((f=fopen(PID_FILE,"w")) == NULL){
583 <                logmessage(LOG_WARNING, "Failed to write PID file");
583 >                logmessage(LOG_WARNING, "Failed to write PID file (%m)");
584          }else{
585 <                if((fprintf(f,"%d",(int)pid)) != sizeof(pid)){
586 <                        logmessage(LOG_WARNING, "Failed to write PID file");
585 >                if((fprintf(f,"%d",(int)pid)) <= 0 ){
586 >                        logmessage(LOG_WARNING, "Failed to write PID file (%m)");
587                  }
588                  if((fclose(f))!=0){
589                          logmessage(LOG_ERR, "failed to close PID file");
# Line 614 | Line 618 | int main(int argc, char **argv){
618  
619                  if(cur_time>=udp_time){
620                          logmessage(LOG_DEBUG,"Sending udp data");
621 <
621 >                        /* Work out how long it takes to get the stats for next time round
622 >                           so the sleep time can be adjusted accordingly */
623                          stat_grab_time=time(NULL);
624                          if((xml_stats=stat_grab(&ihost_state, counter++)) == NULL){
625                                  logmessage(LOG_ERR,"Failed to get stats (%m)");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines