bin/load/loader.c

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

FUNCTIONS

This source file includes following functions.
  1. stop_updates
  2. error_init
  3. 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 #include "ca_configFns.h"
  12 #include "ca_dictSyms.h"
  13 #include "ca_macros.h"
  14 #include "ca_srcAttribs.h"
  15 
  16 
  17 
  18 
  19 void stop_updates()
     /* [<][>][^][v][top][bottom][index][help] */
  20 {
  21  char print_buf[STR_M];
  22  
  23  fprintf(stderr, "Updates interrupted..\n");
  24  sprintf(print_buf, "%d", 0);
  25  CO_set_const("UD.do_update", print_buf);
  26  return;
  27 }
  28                       
  29 
  30 void error_init(int argc, char ** argv) {
     /* [<][>][^][v][top][bottom][index][help] */
  31   char *slash;     
  32   char progname[32];
  33   
  34   slash = strrchr(argv[0],'/');                            
  35   strncpy(progname, (slash != NULL) ? slash+1 : argv[0], 31);
  36   progname[31]=0;
  37   
  38   /* Initialize error module but do not process ER_DEF definitions from the config */
  39   ER_init(progname, 0);
  40 
  41  /* ripupdlog: logs all update transactions */
  42  /* add one more definition */
  43   {
  44     char *err_msg = NULL;
  45     char *buf = 
  46       "CREATE err_log { FORMAT SEVCHAR|FACSYMB|TEXTLONG|DATETIME SOCK 2 }"
  47       "( FAC ALL SEV E- )"
  48       "( FAC UD ASP UD_UPDLOG SEV I )"
  49       ;
  50 
  51     int parsres = ER_parse_spec(buf, &err_msg);
  52 
  53     if( parsres != 0 ) { /* print only on failure */
  54       puts(err_msg);
  55     }
  56     
  57     wr_free(err_msg);
  58     
  59     dieif( parsres != 0 );
  60   }
  61 
  62 
  63 } /* error_init() */
  64 
  65 
  66 /***********************************************
  67 ******* MAIN **********************************
  68 ***********************************************/
  69 
  70 
  71 int main(int argc, char** argv) {
     /* [<][>][^][v][top][bottom][index][help] */
  72 int c;
  73 int fd;
  74 extern int optind;
  75 extern char *optarg;
  76 int errflg = 0;
  77 int dummy_allowed;
  78 int start_object;
  79 int num_ok, num_failed;
  80 long num_skip=0;
  81 struct _nrtm *nrtm=NULL;
  82 UD_stream_t ud_stream;
  83 Log_t log;
  84 int current_serial=-1;
  85 int load_pass=0;
  86 int delay=1;
  87 char *prop_file_name=NULL;
  88 int do_update;
  89 char *source_name = "RIPE";
  90 ca_dbSource_t *source_hdl;
  91 char *db_host, *db_name, *db_user, *db_passwd;
  92 int db_port;
  93 char *co_result;
  94 
  95 
  96 struct sigaction sig;
  97   
  98   num_ok=0; num_failed=0;
  99   dummy_allowed=0;
 100   
 101   start_object = 1;
 102 
 103         while ((c = getopt(argc, argv, "n:M:L:p:s:?")) != EOF)
 104                 switch (c) {
 105                 case 'n':
 106                         num_skip=atol(optarg);
 107                         break;  
 108                 case 'p':
 109                         prop_file_name = optarg;
 110                         break;
 111                 case 'L':
 112                         load_pass=atoi(optarg);
 113                         dummy_allowed=1;
 114                         break;
 115                 case 's':
 116                         source_name=optarg;
 117                         break;
 118                 case '?':
 119                 default :
 120                         errflg++;
 121                         break;
 122                 }
 123                 if (errflg) {
 124                         fprintf(stderr,"usage: standalone [-L pass#] [-n num_skip] [-p properties] file\n");
 125                         exit (2);
 126                 }
 127 
 128 
 129 sig.sa_handler=stop_updates;
 130 sigemptyset(&sig.sa_mask);
 131 sig.sa_flags=SA_RESTART;
 132 sigaction(SIGINT, &sig, NULL);
 133 sigaction(SIGTERM, &sig, NULL);
 134  
 135   co_result = CO_set();
 136   free(co_result);
 137   
 138   /* 3a. Populate dictionary and load config */
 139   ca_init(prop_file_name);
 140 
 141   /* 4. initalise error system */
 142   error_init(argc, argv);
 143   
 144   /* Zero the structure */
 145    memset(&ud_stream, 0, sizeof(ud_stream));
 146 
 147   /* set mode of operation: unprotected (dummy allowed), updates, standalone */
 148    ud_stream.ud_mode= (B_DUMMY | B_UPDATE | B_STANDALONE );
 149   
 150    /* get the source handle */
 151    source_hdl = ca_get_SourceHandleByName(source_name);
 152    
 153 /* Connect to the database */
 154    db_host = ca_get_srcdbmachine(source_hdl);
 155    db_port = ca_get_srcdbport(source_hdl);
 156    db_name = ca_get_srcdbname(source_hdl);
 157    db_user = ca_get_srcdbuser(source_hdl);
 158    db_passwd = ca_get_srcdbpassword(source_hdl);
 159  
 160   fprintf(stderr, "D: Making SQL connection to %s@%s ...", db_name, db_host);
 161 
 162 /*  ud_stream.db_connection=SQ_get_connection2(); */
 163   ud_stream.db_connection=SQ_get_connection(db_host, db_port, db_name, db_user, db_passwd);
 164      
 165  
 166   if(! ud_stream.db_connection) {
 167    fprintf(stderr, "D: ERROR: no SQL connection\n");
 168     return;
 169   }
 170         
 171   fprintf(stderr, "OK\n");
 172 
 173                             
 174                                                                                                             
 175  ud_stream.nrtm=NULL;
 176                                             
 177  ud_stream.log.num_ok=0;
 178  ud_stream.log.num_failed=0;
 179 
 180   free(db_host);
 181   free(db_name);
 182   free(db_user);
 183   free(db_passwd);
 184 
 185 
 186  if(optind<argc) fd=open(argv[optind],O_RDONLY, 0666); else fd=0;
 187 
 188  if (fd==-1) {  fprintf(stderr, "Cannot open data stream. Exiting..\n");
 189                         exit(1); }
 190 
 191 
 192   ud_stream.condat.sock = fd;
 193   ud_stream.num_skip=num_skip;
 194   ud_stream.load_pass=load_pass;
 195 
 196 /* Start to process the stream */
 197 
 198 fprintf(stderr, "starting processing stream\n");
 199   num_ok=UD_process_stream(&ud_stream);
 200 fprintf(stderr, "processing stream finished\n");
 201 fprintf(stderr, "%d objects processed\n", num_ok);
 202 
 203 return(0);
 204 
 205 } /* main() */
 206 
 207 
 208 
 209 

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