## bin/load/loader.c

/* [<][>][^][v][top][bottom][index][help] */

## FUNCTIONS

This source file includes following functions.

1. stop_updates
2. main

       1 #include <sys/types.h>
       2 #include <fcntl.h>
       3 #include <signal.h>
       4
       5 #include <ud.h>
       6 #include <ud_int.h>
       7 #include <constants.h>
       8 #include <properties.h>
       9
      10
      11
      12
      13 void stop_updates()
         /* [<][>][^][v][top][bottom][index][help] */
      14 {
      15  char print_buf[STR_M];
      16
      17  fprintf(stderr, "Updates interrupted..\n");
      18  sprintf(print_buf, "%d", 0);
      19  CO_set_const("UD.do_update", print_buf);
      20  return;
      21 }
      22
      23
      24
      25
      26 /***********************************************
      27 ******* MAIN **********************************
      28 ***********************************************/
      29
      30
      31 int main(int argc, char** argv) {
         /* [<][>][^][v][top][bottom][index][help] */
      32   FILE *file = NULL;
      33   FILE *logfile;
      34   char *logname="log.XXXX";
      35 int c;
      36 extern int optind;
      37 extern char *optarg;
      38 int errflg = 0;
      39 int dummy_allowed;
      40 int start_object;
      41 int num_ok, num_failed;
      42 char db_host[STR_M];
      43 long num_skip=0;
      44 struct _nrtm *nrtm=NULL;
      45 UD_stream_t ud_stream;
      46 Log_t log;
      47 int current_serial=-1;
      48 int load_pass=0;
      49 int delay=1;
      50 char *prop_file_name=NULL;
      51 char *logfilename=NULL;
      52 int do_update;
      53
      54 struct sigaction sig;
      55
      56   num_ok=0; num_failed=0;
      57   dummy_allowed=0;
      58
      59 //  strcpy(db_host, "rowan.ripe.net");
      60
      61   start_object = 1;
      62
      63         while ((c = getopt(argc, argv, "n:M:L:p:?")) != EOF)
      64                 switch (c) {
      65                 case 'n':
      66                         num_skip=atol(optarg);
      67                         break;
      68                 case 'p':
      69                         prop_file_name = optarg;
      70                         break;
      71                 case 'L':
      72                         load_pass=atoi(optarg);
      73                         dummy_allowed=1;
      74                         break;
      75                 case '?':
      76                 default :
      77                         errflg++;
      78                         break;
      79                 }
      80                 if (errflg) {
      81                         fprintf(stderr,"usage: standalone [-L pass#] [-n num_skip] [-p properties] file\n");
      82                         exit (2);
      83                 }
      84
      85
      86 sig.sa_handler=stop_updates;
      87 sigemptyset(&sig.sa_mask);
      88 sig.sa_flags=SA_RESTART;
      89 sigaction(SIGINT, &sig, NULL);
      90 sigaction(SIGTERM, &sig, NULL);
      91
      92   /* 2. Load properties object from prop_file. */
      93   fprintf(stderr,"Properties:\n");
      94   if(prop_file_name==NULL)prop_file_name=".properties";
      95   PR_load(prop_file_name);
      96   fprintf(stderr,"%s\n", PR_to_string() );
      97
      98   /* 3. Set the constants. */
      99   fprintf(stderr,"Constants:\n");
     100   CO_set();
     101   fprintf(stderr,"%s\n", CO_to_string() );
     102
     103
     104 /* set mode of operation: unprotected (dummy allowed), updates, standalone */
     105    ud_stream.ud_mode=7;
     106
     107 /* get error log facility */
     108   logfilename=CO_get_nrtm_logfile();
     109
     110
     111 /* Connect to the database */
     112   fprintf(stderr, "D: Making SQL connection to %s@%s ...", CO_get_database(), CO_get_host());
     113
     114   ud_stream.db_connection=SQ_get_connection2();
     115
     116   if(! ud_stream.db_connection) {
     117    fprintf(stderr, "D: ERROR: no SQL connection\n");
     118     return;
     119   }
     120
     121   fprintf(stderr, "OK\n");
     122
     123
     124
     125  ud_stream.nrtm=NULL;
     126
     127  ud_stream.log.logfile = fopen(logfilename, "a+");
     128  ud_stream.log.num_ok=0;
     129  ud_stream.log.num_failed=0;
     130
     131
     132  if(optind<argc) file=fopen(argv[optind], "r"); else file=stdin;
     133
     134  if (file==NULL) {      fprintf(stderr, "Cannot open data stream. Exiting..\n");
     135                         exit(1); }
     136
     137
     138   ud_stream.stream=file;
     139   ud_stream.num_skip=num_skip;
     140   ud_stream.load_pass=load_pass;
     141
     142 /* Start to process the stream */
     143
     144 fprintf(stderr, "starting processing stream\n");
     145   num_ok=UD_process_stream(&ud_stream);
     146 fprintf(stderr, "processing stream finished\n");
     147 fprintf(stderr, "%d objects processed\n", num_ok);
     148
     149 return(0);
     150
     151 } /* main() */
     152
     153
     154
     155

/* [<][>][^][v][top][bottom][index][help] */