annotate freeDiameter/main.c @ 628:e1c6f45f5fcd

Improvements to usability, still work ongoing
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 14 Dec 2010 11:53:48 +0900
parents a9a938287b49
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
258
5df55136361b Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 253
diff changeset
5 * Copyright (c) 2010, WIDE Project and NICT *
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
1
bafb831ba688 Fix names to proper case for freeDiameter
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 0
diff changeset
36 #include "fD.h"
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
38 #include <signal.h>
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
39 #include <getopt.h>
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
40 #include <locale.h>
17
ab3c58d88be3 Added proper gcrypt initializer
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 16
diff changeset
41 #include <gcrypt.h>
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
42
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
43 /* forward declarations */
235
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
44 static void fd_shutdown(int signal);
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
45 static int main_cmdline(int argc, char *argv[]);
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
46 static void main_version(void);
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
47 static void main_help( void );
628
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
48 static int signal_framework_ready(void);
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
49
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
50 /* The static configuration structure */
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
51 static struct fd_config conf;
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
52 struct fd_config * fd_g_config = &conf;
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
53
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
54 /* gcrypt functions to support posix threads */
18
e7187583dcf8 Added CA helper script
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 17
diff changeset
55 GCRY_THREAD_OPTION_PTHREAD_IMPL;
e7187583dcf8 Added CA helper script
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 17
diff changeset
56
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
57 /* freeDiameter starting point */
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
58 int main(int argc, char * argv[])
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
59 {
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
60 int ret;
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
61
142
dee0a871abcd Added number of CA certificates for debug
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 126
diff changeset
62 memset(fd_g_config, 0, sizeof(struct fd_config));
dee0a871abcd Added number of CA certificates for debug
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 126
diff changeset
63
217
739098a7d297 Remove the gcry initializer, following Nikos advice on help-gnutls mailing-list
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 214
diff changeset
64 /* Initialize the library -- must come first since it initializes the debug facility */
235
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
65 CHECK_FCT( fd_lib_init(1) );
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
66 TRACE_DEBUG(INFO, "libfreeDiameter initialized.");
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
67
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
68 /* Name this thread */
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
69 fd_log_threadname("Main");
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
70
18
e7187583dcf8 Added CA helper script
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 17
diff changeset
71 /* Initialize gcrypt and gnutls */
214
5a1b93f59f8f Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 213
diff changeset
72 GNUTLS_TRACE( (void) gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread) );
5a1b93f59f8f Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 213
diff changeset
73 GNUTLS_TRACE( (void) gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0) );
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
74 CHECK_GNUTLS_DO( gnutls_global_init(), return EINVAL );
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
75 if ( ! gnutls_check_version(GNUTLS_VERSION) ) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
76 fprintf(stderr, "The GNUTLS library is too old; found '%s', need '" GNUTLS_VERSION "'\n", gnutls_check_version(NULL));
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
77 return EINVAL;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
78 } else {
218
113eb3d50ad9 Add libgcrypt version in debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 217
diff changeset
79 TRACE_DEBUG(INFO, "libgnutls '%s', libgcrypt '%s', initialized.", gnutls_check_version(NULL), gcry_check_version(NULL) );
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
80 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
81
213
890a9b6379f0 Fix initialization order for gnutls
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
82 /* Initialize the config */
890a9b6379f0 Fix initialization order for gnutls
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
83 CHECK_FCT( fd_conf_init() );
890a9b6379f0 Fix initialization order for gnutls
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
84
890a9b6379f0 Fix initialization order for gnutls
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
85 /* Parse the command-line */
890a9b6379f0 Fix initialization order for gnutls
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
86 CHECK_FCT( main_cmdline(argc, argv) );
890a9b6379f0 Fix initialization order for gnutls
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 212
diff changeset
87
235
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
88 /* Allow SIGINT and SIGTERM from this point to terminate the application */
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
89 CHECK_FCT( fd_sig_register(SIGINT, "freeDiameter.main", fd_shutdown) );
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
90 CHECK_FCT( fd_sig_register(SIGTERM, "freeDiameter.main", fd_shutdown) );
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
91
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
92 /* Add definitions of the base protocol */
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
93 CHECK_FCT( fd_dict_base_protocol(fd_g_config->cnf_dict) );
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
94
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
95 /* Initialize other modules */
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
96 CHECK_FCT( fd_queues_init() );
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
97 CHECK_FCT( fd_msg_init() );
453
9a8b3178a7a7 Postpone the creation of session expiry thread to allow some global variables to be set (debug level, etc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 447
diff changeset
98 CHECK_FCT( fd_sess_start() );
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
99 CHECK_FCT( fd_p_expi_init() );
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
100
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
101 /* Parse the configuration file */
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
102 CHECK_FCT( fd_conf_parse() );
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
103
253
ad6c0118fb50 Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
104 /* Create the daemon's threads */
ad6c0118fb50 Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
105 CHECK_FCT( fd_rtdisp_init() );
ad6c0118fb50 Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 236
diff changeset
106
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
107 /* Load the dynamic extensions */
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
108 CHECK_FCT( fd_ext_load() );
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
109
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
110 fd_conf_dump();
235
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
111 fd_sig_dump(FULL, 1);
23
db6c40b8b307 Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
112
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
113 /* Start the servers */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
114 CHECK_FCT( fd_servers_start() );
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
115
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
116 /* Start the peer state machines */
13
ef9ef3bf4752 Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 12
diff changeset
117 CHECK_FCT( fd_psm_start() );
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
118
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
119 /* Now, just wait for events */
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
120 TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon initialized.");
628
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
121 CHECK_FCT( signal_framework_ready() );
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
122 while (1) {
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
123 int code; size_t sz; void * data;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 23
diff changeset
124 CHECK_FCT_DO( fd_event_get(fd_g_config->cnf_main_ev, &code, &sz, &data), break );
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
125 switch (code) {
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
126 case FDEV_DUMP_DICT:
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
127 fd_dict_dump(fd_g_config->cnf_dict);
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
128 break;
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
129
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
130 case FDEV_DUMP_EXT:
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
131 fd_ext_dump();
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
132 break;
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
133
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 18
diff changeset
134 case FDEV_DUMP_SERV:
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 18
diff changeset
135 fd_servers_dump();
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 18
diff changeset
136 break;
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 18
diff changeset
137
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
138 case FDEV_DUMP_QUEUES:
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
139 fd_fifo_dump(0, "Incoming messages", fd_g_incoming, fd_msg_dump_walk);
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
140 fd_fifo_dump(0, "Outgoing messages", fd_g_outgoing, fd_msg_dump_walk);
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
141 fd_fifo_dump(0, "Local messages", fd_g_local, fd_msg_dump_walk);
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
142 break;
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
143
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
144 case FDEV_DUMP_CONFIG:
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
145 fd_conf_dump();
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
146 break;
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
147
11
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 10
diff changeset
148 case FDEV_DUMP_PEERS:
12
418d2ce80dc8 Added support in configuration file for peers declaration
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 11
diff changeset
149 fd_peer_dump_list(FULL);
11
6576ef5e01eb Added some support for peers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 10
diff changeset
150 break;
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
151
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
152 case FDEV_TERMINATE:
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
153 ret = 0;
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
154 goto end;
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
155
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
156 default:
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
157 TRACE_DEBUG(INFO, "Unexpected event in the daemon (%d), ignored.\n", code);
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
158 }
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
159 }
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
160
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
161 end:
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
162 TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon is stopping...");
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
163
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
164 /* cleanups */
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
165 CHECK_FCT_DO( fd_servers_stop(), /* Stop accepting new connections */ );
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
166 CHECK_FCT_DO( fd_rtdisp_cleanstop(), /* Stop dispatch thread(s) after a clean loop if possible */ );
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
167 CHECK_FCT_DO( fd_peer_fini(), /* Stop all connections */ );
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
168 CHECK_FCT_DO( fd_rtdisp_fini(), /* Stop routing threads and destroy routing queues */ );
90
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 82
diff changeset
169
285
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
170 CHECK_FCT_DO( fd_ext_term(), /* Cleanup all extensions */ );
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
171 CHECK_FCT_DO( fd_rtdisp_cleanup(), /* destroy remaining handlers */ );
122
e66a82a739fa Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 90
diff changeset
172
214
5a1b93f59f8f Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 213
diff changeset
173 GNUTLS_TRACE( gnutls_global_deinit() );
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
174
447
097bae83b07a Forgot to cleanup the configuration on exit, spotted by valgrind
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 335
diff changeset
175 CHECK_FCT_DO( fd_conf_deinit(), );
097bae83b07a Forgot to cleanup the configuration on exit, spotted by valgrind
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 335
diff changeset
176
126
0ad5825eccdb Added a final trace
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
177 fd_log_debug(FD_PROJECT_BINARY " daemon is terminated.\n");
235
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
178
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
179 fd_lib_fini();
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
180
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
181 return ret;
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
182 }
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
183
501
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
184 /* gnutls debug */
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
185 static void fd_gnutls_debug(int level, const char * str) {
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
186 fd_log_debug(" [gnutls:%d] %s", level, str);
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
187 }
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
188
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
189 /* Parse the command-line */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
190 static int main_cmdline(int argc, char *argv[])
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
191 {
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
192 int c;
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
193 int option_index = 0;
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
194 char * locale;
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
195
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
196 struct option long_options[] = {
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
197 { "help", no_argument, NULL, 'h' },
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
198 { "version", no_argument, NULL, 'V' },
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
199 { "config", required_argument, NULL, 'c' },
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
200 { "debug", no_argument, NULL, 'd' },
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
201 { "quiet", no_argument, NULL, 'q' },
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
202 { "dbglocale", optional_argument, NULL, 'l' },
174
2b2f78036749 Added simple command-line switch to turn on full debug for specific function or file
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 142
diff changeset
203 { "dbg_func", required_argument, NULL, 'f' },
2b2f78036749 Added simple command-line switch to turn on full debug for specific function or file
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 142
diff changeset
204 { "dbg_file", required_argument, NULL, 'F' },
501
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
205 { "dbg_gnutls", required_argument, NULL, 'g' },
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
206 { NULL, 0, NULL, 0 }
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
207 };
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
208
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
209 TRACE_ENTRY("%d %p", argc, argv);
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
210
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
211 /* Loop on arguments */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
212 while (1) {
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
213 c = getopt_long (argc, argv, "hVc:dql:", long_options, &option_index);
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
214 if (c == -1)
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
215 break; /* Exit from the loop. */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
216
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
217 switch (c) {
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
218 case 'h': /* Print help and exit. */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
219 main_help();
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
220 exit(0);
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
221
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
222 case 'V': /* Print version and exit. */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
223 main_version();
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
224 exit(0);
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
225
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
226 case 'c': /* Read configuration from this file instead of the default location.. */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
227 CHECK_PARAMS( optarg );
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 9
diff changeset
228 fd_g_config->cnf_file = optarg;
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
229 break;
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
230
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
231 case 'l': /* Change the locale. */
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
232 locale = setlocale(LC_ALL, optarg?:"");
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
233 if (locale) {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
234 TRACE_DEBUG(INFO, "Locale set to: %s", optarg ?: locale);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
235 } else {
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
236 TRACE_DEBUG(INFO, "Unable to set locale (%s)", optarg);
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
237 return EINVAL;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
238 }
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
239 break;
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
240
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
241 case 'd': /* Increase verbosity of debug messages. */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
242 fd_g_debug_lvl++;
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
243 break;
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
244
174
2b2f78036749 Added simple command-line switch to turn on full debug for specific function or file
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 142
diff changeset
245 case 'f': /* Full debug for the function with this name. */
205
ff9ade352076 Simplified use of --dbg_file option
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
246 #ifdef DEBUG
174
2b2f78036749 Added simple command-line switch to turn on full debug for specific function or file
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 142
diff changeset
247 fd_debug_one_function = optarg;
205
ff9ade352076 Simplified use of --dbg_file option
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
248 #else /* DEBUG */
ff9ade352076 Simplified use of --dbg_file option
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
249 TRACE_DEBUG(INFO, "Error: must compile with DEBUG support to use this feature");
ff9ade352076 Simplified use of --dbg_file option
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
250 return EINVAL;
ff9ade352076 Simplified use of --dbg_file option
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
251 #endif /* DEBUG */
174
2b2f78036749 Added simple command-line switch to turn on full debug for specific function or file
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 142
diff changeset
252 break;
2b2f78036749 Added simple command-line switch to turn on full debug for specific function or file
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 142
diff changeset
253
2b2f78036749 Added simple command-line switch to turn on full debug for specific function or file
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 142
diff changeset
254 case 'F': /* Full debug for the file with this name. */
205
ff9ade352076 Simplified use of --dbg_file option
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
255 #ifdef DEBUG
ff9ade352076 Simplified use of --dbg_file option
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
256 fd_debug_one_file = basename(optarg);
ff9ade352076 Simplified use of --dbg_file option
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
257 #else /* DEBUG */
ff9ade352076 Simplified use of --dbg_file option
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
258 TRACE_DEBUG(INFO, "Error: must compile with DEBUG support to use this feature");
ff9ade352076 Simplified use of --dbg_file option
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
259 return EINVAL;
ff9ade352076 Simplified use of --dbg_file option
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
260 #endif /* DEBUG */
174
2b2f78036749 Added simple command-line switch to turn on full debug for specific function or file
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 142
diff changeset
261 break;
2b2f78036749 Added simple command-line switch to turn on full debug for specific function or file
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 142
diff changeset
262
501
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
263 case 'g': /* Full debug for the function with this name. */
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
264 {
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
265 int l = (int)atoi(optarg);
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
266 if (l) {
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
267 gnutls_global_set_log_function((gnutls_log_func)fd_gnutls_debug);
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
268 gnutls_global_set_log_level (l);
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
269 TRACE_DEBUG(INFO, "Enabled GNUTLS debug at level %d", l);
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
270 }
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
271 }
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
272 break;
e5f06199cee7 New command-line option to enable GNUTLS debugging
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 453
diff changeset
273
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
274 case 'q': /* Decrease verbosity then remove debug messages. */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
275 fd_g_debug_lvl--;
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
276 break;
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
277
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
278 case '?': /* Invalid option. */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
279 /* `getopt_long' already printed an error message. */
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
280 TRACE_DEBUG(INFO, "getopt_long found an invalid character");
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
281 return EINVAL;
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
282
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
283 default: /* bug: option not considered. */
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
284 TRACE_DEBUG(INFO, "A command-line option is missing in parser: %c", c);
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
285 ASSERT(0);
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
286 return EINVAL;
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
287 }
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
288 }
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
289
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
290 return 0;
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
291 }
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
292
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
293 /* Display package version */
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
294 static void main_version_core(void)
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
295 {
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
296 printf("%s, version %d.%d.%d"
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
297 #ifdef HG_VERSION
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
298 " (r%s"
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
299 # ifdef PACKAGE_HG_REVISION
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
300 "/%s"
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
301 # endif /* PACKAGE_HG_VERSION */
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
302 ")"
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
303 #endif /* HG_VERSION */
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
304 "\n",
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
305 FD_PROJECT_NAME, FD_PROJECT_VERSION_MAJOR, FD_PROJECT_VERSION_MINOR, FD_PROJECT_VERSION_REV
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
306 #ifdef HG_VERSION
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
307 , HG_VERSION
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
308 # ifdef PACKAGE_HG_REVISION
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
309 , PACKAGE_HG_REVISION
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
310 # endif /* PACKAGE_HG_VERSION */
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
311 #endif /* HG_VERSION */
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
312 );
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
313 }
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
314
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
315 /* Display package version and general info */
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
316 static void main_version(void)
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
317 {
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
318 main_version_core();
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
319 printf( "%s\n", FD_PROJECT_COPYRIGHT);
335
603791d2dcc4 Updated website information
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 304
diff changeset
320 printf( "\nSee " FD_PROJECT_NAME " homepage at http://www.freediameter.net/\n"
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
321 " for information, updates and bug reports on this software.\n");
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
322 }
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
323
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
324 /* Print command-line options */
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
325 static void main_help( void )
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
326 {
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
327 main_version_core();
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
328 printf( " This daemon is an implementation of the Diameter protocol\n"
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
329 " used for Authentication, Authorization, and Accounting (AAA).\n");
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
330 printf("\nUsage: " FD_PROJECT_BINARY " [OPTIONS]...\n");
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
331 printf( " -h, --help Print help and exit\n"
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
332 " -V, --version Print version and exit\n"
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
333 " -c, --config=filename Read configuration from this file instead of the \n"
304
ad3c46016584 Added install directives for cmake; also allow default directory to seek for extensions and configuration files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 285
diff changeset
334 " default location (" DEFAULT_CONF_PATH "/" FD_DEFAULT_CONF_FILENAME ").\n");
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
335 printf( "\nDebug:\n"
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
336 " These options are mostly useful for developers\n"
16
013ce9851131 Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
337 " -l, --dbglocale Set the locale for error messages\n"
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 13
diff changeset
338 " -d, --debug Increase verbosity of debug messages\n"
502
a9a938287b49 Updated help message
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 501
diff changeset
339 " -q, --quiet Decrease verbosity then remove debug messages\n"
a9a938287b49 Updated help message
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 501
diff changeset
340 " --dbg_gnutls <int> Enable GNU TLS debug at level <int>\n");
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
341 }
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
342
235
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
343 /* Terminate the application */
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
344 static void fd_shutdown(int signal)
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
345 {
235
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
346 TRACE_ENTRY("%d", signal);
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
347
236
60f34df3e025 Remove dependency on signalent.h
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 235
diff changeset
348 TRACE_DEBUG(INFO, "Received signal %s (%d), exiting", fd_sig_abbrev(signal), signal);
235
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
349
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
350 CHECK_FCT_DO( fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), exit(2) );
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
351
235
8773740401a5 Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 218
diff changeset
352 return;
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 3
diff changeset
353 }
628
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
354
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
355
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
356 /* Signal extensions when the framework is completly initialized */
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
357 static int is_ready = 0;
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
358 static pthread_mutex_t is_ready_mtx = PTHREAD_MUTEX_INITIALIZER;
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
359 static pthread_cond_t is_ready_cnd = PTHREAD_COND_INITIALIZER;
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
360 static int signal_framework_ready(void)
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
361 {
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
362 TRACE_ENTRY("");
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
363 CHECK_POSIX( pthread_mutex_lock( &is_ready_mtx ) );
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
364 is_ready = 1;
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
365 CHECK_POSIX( pthread_cond_broadcast( &is_ready_cnd ) );
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
366 CHECK_POSIX( pthread_mutex_unlock( &is_ready_mtx ) );
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
367 return 0;
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
368 }
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
369 int fd_wait_initialization_complete(void)
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
370 {
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
371 TRACE_ENTRY("");
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
372 CHECK_POSIX( pthread_mutex_lock( &is_ready_mtx ) );
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
373 pthread_cleanup_push( fd_cleanup_mutex, &is_ready_mtx );
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
374 while (!is_ready) {
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
375 CHECK_POSIX( pthread_cond_wait( &is_ready_cnd, &is_ready_mtx ) );
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
376 }
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
377 pthread_cleanup_pop( 0 );
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
378 CHECK_POSIX( pthread_mutex_unlock( &is_ready_mtx ) );
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
379 return 0;
e1c6f45f5fcd Improvements to usability, still work ongoing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 502
diff changeset
380 }
"Welcome to our mercurial repository"