| 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> | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 37 | 
   | 
 #include <arpa/inet.h> | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 38 | 
   | 
 #include <syslog.h> | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 39 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 | 36 | 
 – | 
 #define VERSION_NO "1.0rc1" | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 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 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 140 | 
   | 
                 logmessage(LOG_ERR, "sa family is wrong type"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 141 | 
   | 
                 return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 142 | 
   | 
         } | 
 
 
 
 
 
 
 
 
 
 
 
 | 143 | 
 < | 
          | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 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; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 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 | 
   | 
          | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 513 | 
   | 
                                 break; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 514 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 515 | 
   | 
                         case 'V': | 
 
 
 
 
 
 
 
 
 
 
 
 | 516 | 
 < | 
                                 errf("%s version %s",argv[0], VERSION_NO); | 
 
 
 
 
 
 
 
 
 
 | 516 | 
 > | 
                                 errf("%s version %s",argv[0], VERSION); | 
 
 
 
 
 
 
 
 
 
 
 
 | 517 | 
   | 
                                 break; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 518 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 519 | 
   | 
                         default: | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 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)) > 0 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 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"); |