Mercurial > hg > freeDiameter
diff freeDiameterd/main.c @ 1182:cc96a4dfb3d1
Early shutdown situation: detect the race condition and delay the shutdown in freeDiameterd. Alternative would be to initialize in a separate thread that we can cancel before calling shutdown.
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Thu, 06 Jun 2013 11:25:23 +0800 |
parents | 05f74dc19c49 |
children | d8c998e7c535 |
line wrap: on
line diff
--- a/freeDiameterd/main.c Wed Jun 05 19:22:26 2013 +0800 +++ b/freeDiameterd/main.c Thu Jun 06 11:25:23 2013 +0800 @@ -86,17 +86,17 @@ TRACE_DEBUG(INFO, "Enabled GNUTLS debug at level %d", gnutls_debug); } - /* Allow SIGINT and SIGTERM from this point to terminate the application */ - CHECK_POSIX( pthread_create(&signals_thr, NULL, catch_signals, NULL) ); - /* Parse the configuration file */ - CHECK_FCT( fd_core_parseconf(conffile) ); + CHECK_FCT_DO( fd_core_parseconf(conffile), goto error ); /* Start the servers */ - CHECK_FCT( fd_core_start() ); + CHECK_FCT_DO( fd_core_start(), goto error ); + + /* Allow SIGINT and SIGTERM from this point to terminate the application */ + CHECK_POSIX_DO( pthread_create(&signals_thr, NULL, catch_signals, NULL), goto error ); TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon initialized."); - + /* Now, just wait for termination */ CHECK_FCT( fd_core_wait_shutdown_complete() ); @@ -104,6 +104,11 @@ fd_thr_term(&signals_thr); return 0; +error: + CHECK_FCT_DO( fd_core_shutdown(), ); + CHECK_FCT( fd_core_wait_shutdown_complete() ); + fd_thr_term(&signals_thr); + return -1; }