bin/rip/whois_rip.c

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

FUNCTIONS

This source file includes following functions.
  1. error_init
  2. install_signal_handler
  3. main

   1 /***************************************
   2   $Revision: 1.30 $
   3 
   4   Example code: main server code.
   5 
   6   Status: NOT REVUED, TESTED
   7 
   8   Author:       Chris Ottrey + pretty much everybody else involved :-)
   9 
  10   +html+ <DL COMPACT>
  11   +html+ <DT>Online References:
  12   +html+ <DD><UL>
  13   +html+ </UL>
  14   +html+ </DL>
  15  
  16   ******************/ /******************
  17   Modification History:
  18         ottrey (09/03/1999) Created.
  19   ******************/ /******************
  20   Copyright (c) 1993, 1994, 1995, 1996, 1997  The TERENA Association
  21   Copyright (c) 1998                              RIPE NCC
  22  
  23   All Rights Reserved
  24   
  25   Permission to use, copy, modify, and distribute this software and its
  26   documentation for any purpose and without fee is hereby granted,
  27   provided that the above copyright notice appear in all copies and that
  28   both that copyright notice and this permission notice appear in
  29   supporting documentation, and that the name of the author not be
  30   used in advertising or publicity pertaining to distribution of the
  31   software without specific, written prior permission.
  32   
  33   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  34   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
  35   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  36   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  37   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  38   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  39   ***************************************/
  40 
  41 #include <signal.h>
  42 #include "erroutines.h"
  43 #include "constants.h"
  44 #include "properties.h"
  45 #include "server.h"
  46 #include "bitmask.h"
  47 #include "thread.h"
  48 #include "memwrap.h"
  49 
  50 #include "ca_configFns.h"
  51 #include "ca_macros.h"
  52 #include "ca_srcAttribs.h"
  53 
  54 #include "sk.h"
  55 
  56 void error_init(int argc, char ** argv) {
     /* [<][>][^][v][top][bottom][index][help] */
  57   char *slash;     
  58   char progname[32];
  59   
  60   slash = strrchr(argv[0],'/');                            
  61   strncpy(progname, (slash != NULL) ? slash+1 : argv[0], 31);
  62   progname[31]=0;
  63   
  64 
  65   ER_init(progname, 1);
  66 
  67 #if 0
  68   /* add one more definition */
  69   {
  70     char *err_msg = NULL;
  71     char *buf = 
  72       "CREATE test { FORMAT SEVCHAR|FACSYMB|TEXTLONG|DATETIME SOCK 2 }"
  73       "( FAC rp ASP RP_SRCH_GEN|RP_SRCH_DET|RP_LOAD_GEN SEV d-f ) "
  74       "( FAC QI|SQ ASP SQ_QRYTIME | QI_COLL_GEN SEV d-f )"  
  75       "( FAC PW ASP PW_I_QRYLOG SEV I-f )"
  76       "( FAC ALL SEV E- )"
  77       /*      "( FAC SV  ASP SV_PORT  SEV d )" */
  78       ;
  79 
  80     int parsres = ER_parse_spec(buf, &err_msg);
  81 
  82     if( parsres != 0 ) { /* print only on failure */
  83       puts(err_msg);
  84     }
  85     
  86     wr_free(err_msg);
  87     
  88     dieif( parsres != 0 );
  89   }
  90 #endif
  91 
  92 } /* error_init() */
  93 
  94 
  95 void install_signal_handler()
     /* [<][>][^][v][top][bottom][index][help] */
  96 {
  97  struct sigaction sig;
  98  sigset_t sset;
  99  
 100    sig.sa_flags = 0;
 101    sig.sa_handler = SIG_DFL;
 102 
 103    /* change disposition for the signals to handler */
 104    /* this is to avoid signal non delivery in case signal is ignored by parent */
 105 
 106    /* SIGUSR1 will switch the updates on and off */
 107    sigaction(SIGUSR1, &sig, NULL);
 108    
 109    /* SIGINT and SIGTERM stop all servers by setting do_server to 0 */
 110    sigaction(SIGINT, &sig, NULL);
 111    sigaction(SIGTERM, &sig, NULL);
 112     
 113    /* now block the delivery of these signals in other threads */
 114    /* this will be inherited by other threads */
 115    sigemptyset(&sset);
 116    sigaddset(&sset, SIGTERM);
 117    sigaddset(&sset, SIGINT);
 118    sigaddset(&sset, SIGUSR1); 
 119    pthread_sigmask(SIG_BLOCK, &sset, NULL);
 120         
 121 }
 122 
 123 
 124 int main(int argc, char** argv) {
     /* [<][>][^][v][top][bottom][index][help] */
 125   extern char *optarg;
 126   char *prop_file_name;
 127   char *pid_file_name;                       
 128   char *result;
 129   int c, ret, errflg=0;
 130 /* Initialize GLib library to be thread-safe */
 131    g_thread_init(NULL); 
 132   /* parse command line options */     
 133   if(argc<5) errflg++;
 134 
 135      while ((c = getopt(argc, argv, "c:p:?")) != EOF)
 136      switch (c) {
 137       case 'c':
 138         prop_file_name = g_strdup(optarg);
 139         break;  
 140       case 'p':
 141         pid_file_name = g_strdup(optarg);
 142         break;
 143       case '?':
 144       default :
 145         errflg++;
 146         break;
 147      }
 148      if (errflg) {
 149         fprintf(stderr,"usage: %s -c config -p pid_file\n", argv[0]);
 150         exit (2);
 151      }
 152 
 153    install_signal_handler();
 154 
 155 /* Create signal handling thread and block signals for others */
 156    /*   printf("Starting the signal handler\n");*/
 157    TH_create((void *(*)(void *))SV_signal_thread, NULL);
 158      
 159   
 160  /*  Set the constants. */
 161   /* fprintf(stderr,"Constants:\n");  */
 162   result=CO_set(); 
 163   free(result);
 164   fprintf(stderr,"Configuration [%s]:\n", prop_file_name);
 165   ca_init(prop_file_name);
 166 
 167   /* Initialize error handling */
 168   error_init(argc, argv);
 169 
 170   /*  Start the server */
 171   ret = SV_start(pid_file_name);
 172   
 173   
 174   if(ret != 0) return(1); else return(0);
 175 
 176 } /* main() */
 177 

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