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.27 $
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 char *prop_file_name;
126 char *result;
127
128 /* Initialize GLib library to be thread-safe */
129 g_thread_init(NULL);
130
131
132 install_signal_handler();
133
134 /* Create signal handling thread and block signals for others */
135 /* printf("Starting the signal handler\n");*/
136 TH_create((void *(*)(void *))SV_signal_thread, NULL);
137
138
139 /* 1. Get the config file name from argv[1] */
140 if (argc == 2) {
141 prop_file_name = (char *)calloc(1, strlen(argv[1])+1 );
142 strcpy(prop_file_name,argv[1]);
143 } else {
144 die;
145 }
146
147 /* 3. Set the constants. */
148 /* fprintf(stderr,"Constants:\n"); */
149 result=CO_set();
150 free(result);
151 fprintf(stderr,"Configuration [%s]:\n", prop_file_name);
152 ca_init(prop_file_name);
153
154 /* Initialize error handling */
155 error_init(argc, argv);
156
157 /* 4. Start the server */
158 SV_start();
159
160 return(0);
161
162 } /* main() */
163