bin/rip/whois_rip.c
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- error_init
- install_signal_handler
- main
1 /***************************************
2 $Revision: 1.33 $
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 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 /* now block the delivery of these signals in other threads */
106 /* this will be inherited by other threads */
107 sigemptyset(&sset);
108 sigaddset(&sset, SIGTERM);
109 sigaddset(&sset, SIGINT);
110 sigaddset(&sset, SIGUSR1);
111 pthread_sigmask(SIG_BLOCK, &sset, NULL);
112
113 }
114
115
116 int main(int argc, char** argv) {
/* [<][>][^][v][top][bottom][index][help] */
117 extern char *optarg;
118 char *prop_file_name;
119 char *pid_file_name;
120 char *result;
121 int c, ret, errflg=0;
122 /* Initialize GLib library to be thread-safe */
123 g_thread_init(NULL);
124 /* parse command line options */
125 prop_file_name = NULL;
126 pid_file_name = NULL;
127 if(argc<5) errflg++;
128
129 while ((c = getopt(argc, argv, "c:p:?")) != EOF)
130 switch (c) {
131 case 'c':
132 prop_file_name = g_strdup(optarg);
133 break;
134 case 'p':
135 pid_file_name = g_strdup(optarg);
136 break;
137 case '?':
138 default :
139 errflg++;
140 }
141 if (errflg || (prop_file_name == NULL) || (pid_file_name == NULL)) {
142 fprintf(stderr,"usage: %s -c config -p pid_file\n", argv[0]);
143 exit (2);
144 }
145
146 install_signal_handler();
147
148 /* Create signal handling thread and block signals for others */
149 /* printf("Starting the signal handler\n");*/
150 TH_create((void *(*)(void *))SV_signal_thread, NULL);
151
152
153 /* Set the constants. */
154 /* fprintf(stderr,"Constants:\n"); */
155 result=CO_set();
156 UT_free(result);
157 fprintf(stderr,"Configuration [%s]:\n", prop_file_name);
158 ca_init(prop_file_name);
159
160 /* Initialize error handling */
161 error_init(argc, argv);
162
163 /* Start the server */
164 ret = SV_start(pid_file_name);
165
166
167 if(ret != 0) return(1); else return(0);
168
169 } /* main() */
170