## 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.35 $
       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, 1999, 2000, 2001, 2002  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 "rip.h"
      42 #include <signal.h>
      43 #include <unistd.h>
      44
      45 void error_init(int argc, char ** argv) {
         /* [<][>][^][v][top][bottom][index][help] */
      46   char *slash;
      47   char progname[32];
      48
      49   slash = strrchr(argv[0],'/');
      50   strncpy(progname, (slash != NULL) ? slash+1 : argv[0], 31);
      51   progname[31]=0;
      52
      53
      54   ER_init(progname, 1);
      55
      56 #if 0
      57   /* add one more definition */
      58   {
      59     char *err_msg = NULL;
      60     char *buf =
      61       "CREATE test { FORMAT SEVCHAR|FACSYMB|TEXTLONG|DATETIME SOCK 2 }"
      62       "( FAC rp ASP RP_SRCH_GEN|RP_SRCH_DET|RP_LOAD_GEN SEV d-f ) "
      63       "( FAC QI|SQ ASP SQ_QRYTIME | QI_COLL_GEN SEV d-f )"
      64       "( FAC PW ASP PW_I_QRYLOG SEV I-f )"
      65       "( FAC ALL SEV E- )"
      66       /*      "( FAC SV  ASP SV_PORT  SEV d )" */
      67       ;
      68
      69     int parsres = ER_parse_spec(buf, &err_msg);
      70
      71     if( parsres != 0 ) { /* print only on failure */
      72       puts(err_msg);
      73     }
      74
      75     wr_free(err_msg);
      76
      77     dieif( parsres != 0 );
      78   }
      79 #endif
      80
      81 } /* error_init() */
      82
      83
      84 void install_signal_handler()
         /* [<][>][^][v][top][bottom][index][help] */
      85 {
      86  struct sigaction sig;
      87  sigset_t sset;
      88
      89    memset(&sig, 0, sizeof(struct sigaction));
      90    sigemptyset(&sset);
      91
      92    sig.sa_flags = 0;
      93    sig.sa_handler = SIG_DFL;
      94
      95    /* change disposition for the signals to handler */
      96    /* this is to avoid signal non delivery in case signal is ignored by parent */
      97
      98    /* SIGUSR1 will switch the updates on and off */
      99    sigaction(SIGUSR1, &sig, NULL);
     100
     101    /* SIGINT and SIGTERM stop all servers by setting do_server to 0 */
     102    sigaction(SIGINT, &sig, NULL);
     103    sigaction(SIGTERM, &sig, NULL);
     104
     105    /* SIGPIPE occurs at uncomfortable times on TCP sockets, so we ignore it.
     106       In such a case we still get a -1 from the offending I/O operation, and
     107       the errno of EPIPE. */
     108    sig.sa_handler = SIG_IGN;
     109    sigaction(SIGPIPE, &sig, NULL);
     110
     111    /* now block the delivery of these signals in other threads */
     112    /* this will be inherited by other threads */
     113    sigemptyset(&sset);
     114    sigaddset(&sset, SIGTERM);
     115    sigaddset(&sset, SIGINT);
     116    sigaddset(&sset, SIGUSR1);
     117    sigaddset(&sset, SIGPIPE);
     118    pthread_sigmask(SIG_BLOCK, &sset, NULL);
     119
     120 }
     121
     122
     123 int main(int argc, char** argv) {
         /* [<][>][^][v][top][bottom][index][help] */
     124   extern char *optarg;
     125   char *prop_file_name;
     126   char *pid_file_name;
     127   char *result;
     128   int c, ret, errflg=0;
     129 /* Initialize GLib library to be thread-safe */
     130    g_thread_init(NULL);
     131   /* parse command line options */
     132   prop_file_name = NULL;
     133   pid_file_name = NULL;
     134   if(argc<5) errflg++;
     135
     136      while ((c = getopt(argc, argv, "c:p:?")) != EOF)
     137      switch (c) {
     138       case 'c':
     139         prop_file_name = g_strdup(optarg);
     140         break;
     141       case 'p':
     142         pid_file_name = g_strdup(optarg);
     143         break;
     144       case '?':
     145       default :
     146         errflg++;
     147      }
     148      if (errflg || (prop_file_name == NULL) || (pid_file_name == NULL)) {
     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   UT_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] */