X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftools%2Fsysdbd%2Fmain.c;h=7bfbaa650c2888c5c30e183c89eb873768c5c8d3;hb=b59edbb81af9c2c1a2cb27bb96fc205e32b1deae;hp=4a4d55ec0ec9eb6e57abb7dcd501be923c0f8c86;hpb=c19016cd990659ef8a99373f3d0debde80952094;p=sysdb.git diff --git a/src/tools/sysdbd/main.c b/src/tools/sysdbd/main.c index 4a4d55e..7bfbaa6 100644 --- a/src/tools/sysdbd/main.c +++ b/src/tools/sysdbd/main.c @@ -33,6 +33,7 @@ #include "core/plugin.h" #include "core/store.h" #include "utils/error.h" +#include "utils/ssl.h" #include "frontend/connection.h" #include "frontend/sock.h" @@ -46,6 +47,7 @@ #endif /* ! HAVE_LIBGEN_H */ #include +#include #include #include @@ -74,8 +76,8 @@ static sdb_fe_loop_t frontend_main_loop = SDB_FE_LOOP_INIT; static char *config_filename = NULL; static int reconfigure = 0; -static char *default_listen_addresses[] = { - DEFAULT_SOCKET, +static daemon_listener_t default_listen_addresses[] = { + { DEFAULT_SOCKET, SDB_SSL_DEFAULT_OPTIONS }, }; static void @@ -217,7 +219,6 @@ do_reconfigure(void) return status; sdb_plugin_init_all(); sdb_plugin_reconfigure_finish(); - sdb_connection_enable_logging(); return 0; } /* do_reconfigure */ @@ -232,9 +233,12 @@ backend_handler(void __attribute__((unused)) *data) static int main_loop(void) { + sdb_fe_socket_t *sock = sdb_fe_sock_create(); pthread_t backend_thread; - while (42) { + int status = 0; + + while (status == 0) { size_t i; plugin_main_loop.do_loop = 1; @@ -251,14 +255,25 @@ main_loop(void) break; } - sdb_fe_socket_t *sock = sdb_fe_sock_create(); - for (i = 0; i < listen_addresses_num; ++i) - if (sdb_fe_sock_add_listener(sock, listen_addresses[i])) + for (i = 0; i < listen_addresses_num; ++i) { + if (sdb_fe_sock_add_listener(sock, listen_addresses[i].address, + &listen_addresses[i].ssl_opts)) { + status = 1; break; + } + } /* break on error */ - if (i >= listen_addresses_num) - sdb_fe_sock_listen_and_serve(sock, &frontend_main_loop); + if (status) + break; + + sdb_log(SDB_LOG_INFO, "SysDB daemon "SDB_VERSION_STRING + SDB_VERSION_EXTRA " (libsysdb %s%s, pid %i) initialized " + "successfully", sdb_version_string(), sdb_version_extra(), + (int)getpid()); + + sdb_connection_enable_logging(); + sdb_fe_sock_listen_and_serve(sock, &frontend_main_loop); sdb_log(SDB_LOG_INFO, "Waiting for backend thread to terminate"); plugin_main_loop.do_loop = 0; @@ -266,24 +281,33 @@ main_loop(void) * and make the thread shut down faster */ pthread_kill(backend_thread, SIGINT); pthread_join(backend_thread, NULL); - sdb_fe_sock_destroy(sock); if (! reconfigure) break; reconfigure = 0; + sdb_fe_sock_clear_listeners(sock); if (do_reconfigure()) { sdb_log(SDB_LOG_ERR, "Reconfiguration failed"); + status = 1; break; } } - return 0; + + /* clean up in case we exited the loop on error */ + plugin_main_loop.do_loop = 0; + frontend_main_loop.do_loop = 0; + pthread_kill(backend_thread, SIGINT); + pthread_join(backend_thread, NULL); + + sdb_fe_sock_destroy(sock); + return status; } /* main_loop */ int main(int argc, char **argv) { - _Bool do_daemonize = 1; + bool do_daemonize = 1; struct sigaction sa_intterm; struct sigaction sa_hup; @@ -345,10 +369,8 @@ main(int argc, char **argv) if (daemonize()) exit(1); - sdb_log(SDB_LOG_INFO, "SysDB daemon "SDB_VERSION_STRING - SDB_VERSION_EXTRA " (pid %i) initialized successfully", - (int)getpid()); - + if (sdb_ssl_init()) + exit(1); sdb_plugin_init_all(); plugin_main_loop.default_interval = SECS_TO_SDB_TIME(60); @@ -367,11 +389,13 @@ main(int argc, char **argv) * closing the connection cleanly */ signal(SIGPIPE, SIG_IGN); - sdb_connection_enable_logging(); status = main_loop(); sdb_log(SDB_LOG_INFO, "Shutting down SysDB daemon "SDB_VERSION_STRING SDB_VERSION_EXTRA" (pid %i)", (int)getpid()); + sdb_plugin_shutdown_all(); + sdb_plugin_unregister_all(); + sdb_ssl_shutdown(); return status; } /* main */