Mercurial > hg > freeDiameter
comparison freeDiameter/main.c @ 14:14cf6daf716d
Some progress on peers module
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Thu, 01 Oct 2009 18:24:07 +0900 |
parents | ef9ef3bf4752 |
children | 013ce9851131 |
comparison
equal
deleted
inserted
replaced
13:ef9ef3bf4752 | 14:14cf6daf716d |
---|---|
39 #include <getopt.h> | 39 #include <getopt.h> |
40 | 40 |
41 /* forward declarations */ | 41 /* forward declarations */ |
42 static void * sig_hdl(void * arg); | 42 static void * sig_hdl(void * arg); |
43 static int main_cmdline(int argc, char *argv[]); | 43 static int main_cmdline(int argc, char *argv[]); |
44 static void main_version(void); | |
45 static void main_help( void ); | |
44 | 46 |
45 /* The static configuration structure */ | 47 /* The static configuration structure */ |
46 static struct fd_config conf; | 48 static struct fd_config conf; |
47 struct fd_config * fd_g_config = &conf; | 49 struct fd_config * fd_g_config = &conf; |
48 | 50 |
74 | 76 |
75 /* Add definitions of the base protocol */ | 77 /* Add definitions of the base protocol */ |
76 CHECK_FCT( fd_dict_base_protocol(fd_g_config->cnf_dict) ); | 78 CHECK_FCT( fd_dict_base_protocol(fd_g_config->cnf_dict) ); |
77 | 79 |
78 /* Initialize other modules */ | 80 /* Initialize other modules */ |
79 CHECK_FCT( fd_ext_init() ); | |
80 CHECK_FCT( fd_queues_init() ); | 81 CHECK_FCT( fd_queues_init() ); |
81 CHECK_FCT( fd_msg_init() ); | 82 CHECK_FCT( fd_msg_init() ); |
82 CHECK_FCT( fd_peer_init() ); | 83 CHECK_FCT( fd_p_expi_init() ); |
83 | 84 |
84 /* Parse the configuration file */ | 85 /* Parse the configuration file */ |
85 CHECK_FCT( fd_conf_parse() ); | 86 CHECK_FCT( fd_conf_parse() ); |
86 | 87 |
87 /* Load the dynamic extensions */ | 88 /* Load the dynamic extensions */ |
130 | 131 |
131 end: | 132 end: |
132 TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon is stopping..."); | 133 TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon is stopping..."); |
133 | 134 |
134 /* cleanups */ | 135 /* cleanups */ |
135 CHECK_FCT_DO( fd_ext_fini(), /* continue */ ); | 136 TODO("Stop dispatch thread(s) properly (no cancel yet)"); |
137 CHECK_FCT_DO( fd_peer_fini(), /* Stop all connections */ ); | |
138 TODO("Stop dispatch & routing threads"); | |
139 CHECK_FCT_DO( fd_ext_fini(), /* Cleaup all extensions */ ); | |
140 TODO("Cleanup queues (dump all remaining messages ?)"); | |
141 | |
136 CHECK_FCT_DO( fd_thr_term(&sig_th), /* continue */ ); | 142 CHECK_FCT_DO( fd_thr_term(&sig_th), /* continue */ ); |
137 | 143 |
138 return ret; | 144 return ret; |
145 } | |
146 | |
147 const char * fd_ev_str(int event) | |
148 { | |
149 switch (event) { | |
150 #define case_str( _val )\ | |
151 case _val : return #_val | |
152 case_str(FDEV_TERMINATE); | |
153 case_str(FDEV_DUMP_DICT); | |
154 case_str(FDEV_DUMP_EXT); | |
155 case_str(FDEV_DUMP_QUEUES); | |
156 case_str(FDEV_DUMP_CONFIG); | |
157 case_str(FDEV_DUMP_PEERS); | |
158 | |
159 default: | |
160 TRACE_DEBUG(FULL, "Unknown event : %d", event); | |
161 return "Unknown event"; | |
162 } | |
163 } | |
164 | |
165 /* Parse the command-line */ | |
166 static int main_cmdline(int argc, char *argv[]) | |
167 { | |
168 int c; | |
169 int option_index = 0; | |
170 | |
171 struct option long_options[] = { | |
172 { "help", 0, NULL, 'h' }, | |
173 { "version", 0, NULL, 'V' }, | |
174 { "config", 1, NULL, 'c' }, | |
175 { "debug", 0, NULL, 'd' }, | |
176 { "quiet", 0, NULL, 'q' }, | |
177 { NULL, 0, NULL, 0 } | |
178 }; | |
179 | |
180 TRACE_ENTRY("%d %p", argc, argv); | |
181 | |
182 /* Loop on arguments */ | |
183 while (1) { | |
184 c = getopt_long (argc, argv, "hVc:dq", long_options, &option_index); | |
185 if (c == -1) | |
186 break; /* Exit from the loop. */ | |
187 | |
188 switch (c) { | |
189 case 'h': /* Print help and exit. */ | |
190 main_help(); | |
191 exit(0); | |
192 | |
193 case 'V': /* Print version and exit. */ | |
194 main_version(); | |
195 exit(0); | |
196 | |
197 case 'c': /* Read configuration from this file instead of the default location.. */ | |
198 CHECK_PARAMS( optarg ); | |
199 fd_g_config->cnf_file = optarg; | |
200 break; | |
201 | |
202 case 'd': /* Increase verbosity of debug messages. */ | |
203 fd_g_debug_lvl++; | |
204 break; | |
205 | |
206 case 'q': /* Decrease verbosity then remove debug messages. */ | |
207 fd_g_debug_lvl--; | |
208 break; | |
209 | |
210 case '?': /* Invalid option. */ | |
211 /* `getopt_long' already printed an error message. */ | |
212 TRACE_DEBUG(INFO, "getopt_long found an invalid character\n"); | |
213 return EINVAL; | |
214 | |
215 default: /* bug: option not considered. */ | |
216 TRACE_DEBUG(INFO, "A command-line option is missing in parser: %c\n", c); | |
217 ASSERT(0); | |
218 return EINVAL; | |
219 } | |
220 } | |
221 | |
222 return 0; | |
139 } | 223 } |
140 | 224 |
141 /* Display package version */ | 225 /* Display package version */ |
142 static void main_version_core(void) | 226 static void main_version_core(void) |
143 { | 227 { |
184 " These options are mostly useful for developers\n" | 268 " These options are mostly useful for developers\n" |
185 " -d, --debug Increase verbosity of debug messages\n" | 269 " -d, --debug Increase verbosity of debug messages\n" |
186 " -q, --quiet Decrease verbosity then remove debug messages\n"); | 270 " -q, --quiet Decrease verbosity then remove debug messages\n"); |
187 } | 271 } |
188 | 272 |
189 /* Parse the command-line */ | |
190 static int main_cmdline(int argc, char *argv[]) | |
191 { | |
192 int c; | |
193 int option_index = 0; | |
194 | |
195 struct option long_options[] = { | |
196 { "help", 0, NULL, 'h' }, | |
197 { "version", 0, NULL, 'V' }, | |
198 { "config", 1, NULL, 'c' }, | |
199 { "debug", 0, NULL, 'd' }, | |
200 { "quiet", 0, NULL, 'q' }, | |
201 { NULL, 0, NULL, 0 } | |
202 }; | |
203 | |
204 TRACE_ENTRY("%d %p", argc, argv); | |
205 | |
206 /* Loop on arguments */ | |
207 while (1) { | |
208 c = getopt_long (argc, argv, "hVc:dq", long_options, &option_index); | |
209 if (c == -1) | |
210 break; /* Exit from the loop. */ | |
211 | |
212 switch (c) { | |
213 case 'h': /* Print help and exit. */ | |
214 main_help(); | |
215 exit(0); | |
216 | |
217 case 'V': /* Print version and exit. */ | |
218 main_version(); | |
219 exit(0); | |
220 | |
221 case 'c': /* Read configuration from this file instead of the default location.. */ | |
222 CHECK_PARAMS( optarg ); | |
223 fd_g_config->cnf_file = optarg; | |
224 break; | |
225 | |
226 case 'd': /* Increase verbosity of debug messages. */ | |
227 fd_g_debug_lvl++; | |
228 break; | |
229 | |
230 case 'q': /* Decrease verbosity then remove debug messages. */ | |
231 fd_g_debug_lvl--; | |
232 break; | |
233 | |
234 case '?': /* Invalid option. */ | |
235 /* `getopt_long' already printed an error message. */ | |
236 TRACE_DEBUG(INFO, "getopt_long found an invalid character\n"); | |
237 return EINVAL; | |
238 | |
239 default: /* bug: option not considered. */ | |
240 TRACE_DEBUG(INFO, "A command-line option is missing in parser: %c\n", c); | |
241 ASSERT(0); | |
242 return EINVAL; | |
243 } | |
244 } | |
245 | |
246 return 0; | |
247 | |
248 } | |
249 | |
250 #ifdef HAVE_SIGNALENT_H | 273 #ifdef HAVE_SIGNALENT_H |
251 const char *const signalstr[] = { | 274 const char *const signalstr[] = { |
252 # include "signalent.h" | 275 # include "signalent.h" |
253 }; | 276 }; |
254 const int nsignalstr = sizeof signalstr / sizeof signalstr[0]; | 277 const int nsignalstr = sizeof signalstr / sizeof signalstr[0]; |