comparison freeDiameter/main.c @ 16:013ce9851131

Started including TLS code
author Sebastien Decugis <sdecugis@nict.go.jp>
date Fri, 02 Oct 2009 18:57:06 +0900
parents 14cf6daf716d
children ab3c58d88be3
comparison
equal deleted inserted replaced
15:050f4f6f9f2a 16:013ce9851131
35 35
36 #include "fD.h" 36 #include "fD.h"
37 37
38 #include <signal.h> 38 #include <signal.h>
39 #include <getopt.h> 39 #include <getopt.h>
40 #include <locale.h>
41
42 #ifdef GCRY_THREAD_OPTION_PTHREAD_IMPL
43 GCRY_THREAD_OPTION_PTHREAD_IMPL;
44 #endif /* GCRY_THREAD_OPTION_PTHREAD_IMPL */
45
40 46
41 /* forward declarations */ 47 /* forward declarations */
42 static void * sig_hdl(void * arg); 48 static void * sig_hdl(void * arg);
43 static int main_cmdline(int argc, char *argv[]); 49 static int main_cmdline(int argc, char *argv[]);
44 static void main_version(void); 50 static void main_version(void);
59 sigfillset(&sig_all); 65 sigfillset(&sig_all);
60 CHECK_POSIX( pthread_sigmask(SIG_BLOCK, &sig_all, NULL) ); 66 CHECK_POSIX( pthread_sigmask(SIG_BLOCK, &sig_all, NULL) );
61 67
62 /* Initialize the library */ 68 /* Initialize the library */
63 CHECK_FCT( fd_lib_init() ); 69 CHECK_FCT( fd_lib_init() );
70 TRACE_DEBUG(INFO, "libfreeDiameter initialized.");
64 71
65 /* Name this thread */ 72 /* Name this thread */
66 fd_log_threadname("Main"); 73 fd_log_threadname("Main");
67 74
68 /* Initialize the config */ 75 /* Initialize the config */
69 CHECK_FCT( fd_conf_init() ); 76 CHECK_FCT( fd_conf_init() );
70 77
71 /* Parse the command-line */ 78 /* Parse the command-line */
72 CHECK_FCT( main_cmdline(argc, argv) ); 79 CHECK_FCT( main_cmdline(argc, argv) );
80
81 /* Initialize gnutls */
82 CHECK_GNUTLS_DO( gnutls_global_init(), return EINVAL );
83 if ( ! gnutls_check_version(GNUTLS_VERSION) ) {
84 fprintf(stderr, "The GNUTLS library is too old; found '%s', need '" GNUTLS_VERSION "'\n", gnutls_check_version(NULL));
85 return EINVAL;
86 } else {
87 TRACE_DEBUG(INFO, "GNUTLS library '%s' initialized.", gnutls_check_version(NULL));
88 }
73 89
74 /* Allow SIGINT and SIGTERM from this point */ 90 /* Allow SIGINT and SIGTERM from this point */
75 CHECK_POSIX( pthread_create(&sig_th, NULL, sig_hdl, NULL) ); 91 CHECK_POSIX( pthread_create(&sig_th, NULL, sig_hdl, NULL) );
76 92
77 /* Add definitions of the base protocol */ 93 /* Add definitions of the base protocol */
138 TODO("Stop dispatch & routing threads"); 154 TODO("Stop dispatch & routing threads");
139 CHECK_FCT_DO( fd_ext_fini(), /* Cleaup all extensions */ ); 155 CHECK_FCT_DO( fd_ext_fini(), /* Cleaup all extensions */ );
140 TODO("Cleanup queues (dump all remaining messages ?)"); 156 TODO("Cleanup queues (dump all remaining messages ?)");
141 157
142 CHECK_FCT_DO( fd_thr_term(&sig_th), /* continue */ ); 158 CHECK_FCT_DO( fd_thr_term(&sig_th), /* continue */ );
159
160 gnutls_global_deinit();
143 161
144 return ret; 162 return ret;
145 } 163 }
146 164
147 const char * fd_ev_str(int event) 165 const char * fd_ev_str(int event)
165 /* Parse the command-line */ 183 /* Parse the command-line */
166 static int main_cmdline(int argc, char *argv[]) 184 static int main_cmdline(int argc, char *argv[])
167 { 185 {
168 int c; 186 int c;
169 int option_index = 0; 187 int option_index = 0;
188 char * locale;
170 189
171 struct option long_options[] = { 190 struct option long_options[] = {
172 { "help", 0, NULL, 'h' }, 191 { "help", no_argument, NULL, 'h' },
173 { "version", 0, NULL, 'V' }, 192 { "version", no_argument, NULL, 'V' },
174 { "config", 1, NULL, 'c' }, 193 { "config", required_argument, NULL, 'c' },
175 { "debug", 0, NULL, 'd' }, 194 { "debug", no_argument, NULL, 'd' },
176 { "quiet", 0, NULL, 'q' }, 195 { "quiet", no_argument, NULL, 'q' },
177 { NULL, 0, NULL, 0 } 196 { "dbglocale", optional_argument, NULL, 'l' },
197 { NULL, 0, NULL, 0 }
178 }; 198 };
179 199
180 TRACE_ENTRY("%d %p", argc, argv); 200 TRACE_ENTRY("%d %p", argc, argv);
181 201
182 /* Loop on arguments */ 202 /* Loop on arguments */
183 while (1) { 203 while (1) {
184 c = getopt_long (argc, argv, "hVc:dq", long_options, &option_index); 204 c = getopt_long (argc, argv, "hVc:dql:", long_options, &option_index);
185 if (c == -1) 205 if (c == -1)
186 break; /* Exit from the loop. */ 206 break; /* Exit from the loop. */
187 207
188 switch (c) { 208 switch (c) {
189 case 'h': /* Print help and exit. */ 209 case 'h': /* Print help and exit. */
197 case 'c': /* Read configuration from this file instead of the default location.. */ 217 case 'c': /* Read configuration from this file instead of the default location.. */
198 CHECK_PARAMS( optarg ); 218 CHECK_PARAMS( optarg );
199 fd_g_config->cnf_file = optarg; 219 fd_g_config->cnf_file = optarg;
200 break; 220 break;
201 221
222 case 'l': /* Change the locale. */
223 locale = setlocale(LC_ALL, optarg?:"");
224 if (locale) {
225 TRACE_DEBUG(INFO, "Locale set to: %s", optarg ?: locale);
226 } else {
227 TRACE_DEBUG(INFO, "Unable to set locale (%s)", optarg);
228 return EINVAL;
229 }
230 break;
231
202 case 'd': /* Increase verbosity of debug messages. */ 232 case 'd': /* Increase verbosity of debug messages. */
203 fd_g_debug_lvl++; 233 fd_g_debug_lvl++;
204 break; 234 break;
205 235
206 case 'q': /* Decrease verbosity then remove debug messages. */ 236 case 'q': /* Decrease verbosity then remove debug messages. */
207 fd_g_debug_lvl--; 237 fd_g_debug_lvl--;
208 break; 238 break;
209 239
210 case '?': /* Invalid option. */ 240 case '?': /* Invalid option. */
211 /* `getopt_long' already printed an error message. */ 241 /* `getopt_long' already printed an error message. */
212 TRACE_DEBUG(INFO, "getopt_long found an invalid character\n"); 242 TRACE_DEBUG(INFO, "getopt_long found an invalid character");
213 return EINVAL; 243 return EINVAL;
214 244
215 default: /* bug: option not considered. */ 245 default: /* bug: option not considered. */
216 TRACE_DEBUG(INFO, "A command-line option is missing in parser: %c\n", c); 246 TRACE_DEBUG(INFO, "A command-line option is missing in parser: %c", c);
217 ASSERT(0); 247 ASSERT(0);
218 return EINVAL; 248 return EINVAL;
219 } 249 }
220 } 250 }
221 251
264 " -V, --version Print version and exit\n" 294 " -V, --version Print version and exit\n"
265 " -c, --config=filename Read configuration from this file instead of the \n" 295 " -c, --config=filename Read configuration from this file instead of the \n"
266 " default location (%s).\n", DEFAULT_CONF_FILE); 296 " default location (%s).\n", DEFAULT_CONF_FILE);
267 printf( "\nDebug:\n" 297 printf( "\nDebug:\n"
268 " These options are mostly useful for developers\n" 298 " These options are mostly useful for developers\n"
299 " -l, --dbglocale Set the locale for error messages\n"
269 " -d, --debug Increase verbosity of debug messages\n" 300 " -d, --debug Increase verbosity of debug messages\n"
270 " -q, --quiet Decrease verbosity then remove debug messages\n"); 301 " -q, --quiet Decrease verbosity then remove debug messages\n");
271 } 302 }
272 303
273 #ifdef HAVE_SIGNALENT_H 304 #ifdef HAVE_SIGNALENT_H
"Welcome to our mercurial repository"