Changes in freeDiameterd/main.c [1339:e70ce64ce689:1305:84a3c9c4b834] in freeDiameter
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
freeDiameterd/main.c
r1339 r1305 34 34 *********************************************************************************************************/ 35 35 36 #if defined(__GLIBC__)37 #define _BSD_SOURCE /* for vsyslog */38 #endif39 40 36 #include <freeDiameter/freeDiameter-host.h> 41 37 #include <freeDiameter/libfdcore.h> … … 44 40 #include <getopt.h> 45 41 #include <locale.h> 46 #include <syslog.h> 47 #include <stdarg.h> 42 48 43 49 44 /* forward declarations */ … … 61 56 62 57 63 static void syslog_logger(int loglevel, const char * format, va_list args)64 {65 int level;66 67 switch (loglevel) {68 case FD_LOG_NOTICE:69 level = LOG_NOTICE;70 break;71 case FD_LOG_ERROR:72 level = LOG_ERR;73 break;74 case FD_LOG_FATAL:75 level = LOG_CRIT;76 break;77 default:78 /* fallthrough */79 case FD_LOG_DEBUG:80 /* some systems log LOG_DEBUG to a file; but81 * freeDiameter debug output is too verbose */82 return;83 #if 084 level = LOG_DEBUG;85 break;86 #endif87 }88 89 vsyslog(level, format, args);90 }91 92 93 58 /* freeDiameter starting point */ 94 59 int main(int argc, char * argv[]) … … 96 61 int ret; 97 62 sigset_t sig_all; 98 63 99 64 /* Block all signals from the current thread and all its future children -- we will catch everything in catch_signals */ 100 65 sigfillset(&sig_all); 101 66 ret = pthread_sigmask(SIG_BLOCK, &sig_all, NULL); 102 67 ASSERT(ret == 0); 103 68 104 69 /* Parse the command-line */ 105 70 ret = main_cmdline(argc, argv); … … 107 72 return ret; 108 73 } 109 74 110 75 /* Initialize the core library */ 111 76 ret = fd_core_initialize(); … … 114 79 return ret; 115 80 } 116 81 117 82 /* Set gnutls debug level ? */ 118 83 if (gnutls_debug) { … … 121 86 TRACE_DEBUG(INFO, "Enabled GNUTLS debug at level %d", gnutls_debug); 122 87 } 123 88 124 89 /* Parse the configuration file */ 125 90 CHECK_FCT_DO( fd_core_parseconf(conffile), goto error ); 126 91 127 92 /* Start the servers */ 128 93 CHECK_FCT_DO( fd_core_start(), goto error ); 129 94 130 95 /* Allow SIGINT and SIGTERM from this point to terminate the application */ 131 96 CHECK_POSIX_DO( pthread_create(&signals_thr, NULL, catch_signals, NULL), goto error ); 132 97 133 98 TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon initialized."); 134 99 135 100 /* Now, just wait for termination */ 136 101 CHECK_FCT( fd_core_wait_shutdown_complete() ); 137 102 138 103 /* Just in case it was not the result of a signal, we cancel signals_thr */ 139 104 fd_thr_term(&signals_thr); 140 105 141 106 return 0; 142 error: 107 error: 143 108 CHECK_FCT_DO( fd_core_shutdown(), ); 144 109 CHECK_FCT( fd_core_wait_shutdown_complete() ); … … 173 138 " -V, --version Print version and exit\n" 174 139 " -c, --config=filename Read configuration from this file instead of the \n" 175 " default location (" DEFAULT_CONF_PATH "/" FD_DEFAULT_CONF_FILENAME ").\n" 176 " -s, --syslog Write log output to syslog (instead of stdout)\n"); 140 " default location (" DEFAULT_CONF_PATH "/" FD_DEFAULT_CONF_FILENAME ").\n"); 177 141 printf( "\nDebug:\n" 178 142 " These options are mostly useful for developers\n" … … 192 156 int option_index = 0; 193 157 char * locale; 194 158 195 159 struct option long_options[] = { 196 160 { "help", no_argument, NULL, 'h' }, 197 161 { "version", no_argument, NULL, 'V' }, 198 162 { "config", required_argument, NULL, 'c' }, 199 { "syslog", no_argument, NULL, 's' },200 163 { "debug", no_argument, NULL, 'd' }, 201 164 { "quiet", no_argument, NULL, 'q' }, … … 206 169 { NULL, 0, NULL, 0 } 207 170 }; 208 171 209 172 /* Loop on arguments */ 210 173 while (1) { 211 c = getopt_long (argc, argv, "hVc:dql:f:F:g: s", long_options, &option_index);212 if (c == -1) 174 c = getopt_long (argc, argv, "hVc:dql:f:F:g:", long_options, &option_index); 175 if (c == -1) 213 176 break; /* Exit from the loop. */ 214 177 215 178 switch (c) { 216 179 case 'h': /* Print help and exit. */ … … 237 200 } 238 201 break; 239 202 240 203 case 'd': /* Increase verbosity of debug messages. */ 241 204 fd_g_debug_lvl--; 242 205 break; 243 206 244 207 case 'f': /* Full debug for the function with this name. */ 245 208 #ifdef DEBUG … … 251 214 #endif /* DEBUG */ 252 215 break; 253 216 254 217 case 'F': /* Full debug for the file with this name. */ 255 218 #ifdef DEBUG … … 261 224 #endif /* DEBUG */ 262 225 break; 263 226 264 227 case 'g': /* Set a debug level and function for GNU TLS calls. */ 265 228 gnutls_debug = (int)atoi(optarg); 266 229 break; 267 230 268 231 case 'q': /* Decrease verbosity then remove debug messages. */ 269 232 fd_g_debug_lvl++; 270 break;271 272 case 's': /* Write log data using syslog(3) */273 if (fd_log_handler_register(syslog_logger) != 0) {274 fprintf(stderr, "Cannot initialize syslog logger\n");275 return EINVAL;276 }277 233 break; 278 234 … … 288 244 } 289 245 } 290 246 291 247 return 0; 292 248 } … … 297 253 sigset_t ss; 298 254 fd_log_threadname ( "signals catcher" ); 299 255 300 256 sigemptyset(&ss); 301 257 302 258 /* Signals that terminate the daemon */ 303 259 sigaddset(&ss, SIGTERM); 304 260 sigaddset(&ss, SIGINT); 305 261 306 262 /* Signals that send an event */ 307 263 sigaddset(&ss, SIGUSR1); 308 264 sigaddset(&ss, SIGUSR2); 309 265 310 266 /* We unblock all other signals, so that their default handler is used (such as SIGTSTP) */ 311 267 CHECK_SYS_DO( pthread_sigmask( SIG_SETMASK, &ss, NULL ), goto out ); 312 268 313 269 /* Now loop on the reception of the signal */ 314 270 while (1) { 315 271 int sig, *ps; 316 272 317 273 /* Wait to receive the next signal */ 318 274 CHECK_POSIX_DO( sigwait(&ss, &sig), break ); 319 275 320 276 TRACE_DEBUG(FULL, "Signal %d caught", sig); 321 277 322 278 switch (sig) { 323 279 case SIGUSR1: … … 327 283 CHECK_FCT_DO( fd_event_send(fd_g_config->cnf_main_ev, FDEV_TRIGGER, sizeof(int), ps), goto out ); 328 284 break; 329 285 330 286 case SIGINT: 331 287 case SIGTERM: … … 334 290 } 335 291 } 336 out: 292 out: 337 293 /* Better way to handle this ? */ 338 294 ASSERT(0);
Note: See TracChangeset
for help on using the changeset viewer.