X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Ftools%2Fsysdbd%2Fmain.c;h=c7fad8027b4a0da2fe6175af33001ca6f9fd7145;hb=eb349b8f286dcd4e587c1229fb78c8d6ad41d1c9;hp=144128ccaadea8aeabf881ae9802e90dc69ec737;hpb=45226d384db52c8061838dfab5cea10a384f2e10;p=sysdb.git diff --git a/src/tools/sysdbd/main.c b/src/tools/sysdbd/main.c index 144128c..c7fad80 100644 --- a/src/tools/sysdbd/main.c +++ b/src/tools/sysdbd/main.c @@ -60,6 +60,9 @@ #include +#include +#include + #ifndef CONFIGFILE # define CONFIGFILE SYSCONFDIR"/sysdb/sysdbd.conf" #endif @@ -232,10 +235,11 @@ 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; @@ -252,20 +256,24 @@ main_loop(void) break; } - 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], NULL)) { + status = 1; break; + } + } /* break on error */ - if (i >= listen_addresses_num) { - sdb_log(SDB_LOG_INFO, "SysDB daemon "SDB_VERSION_STRING - SDB_VERSION_EXTRA " (pid %i) initialized successfully", - (int)getpid()); + if (status) + break; - sdb_connection_enable_logging(); + 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_fe_sock_listen_and_serve(sock, &frontend_main_loop); - } + 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; @@ -281,18 +289,25 @@ main_loop(void) sdb_fe_sock_clear_listeners(sock); if (do_reconfigure()) { sdb_log(SDB_LOG_ERR, "Reconfiguration failed"); + status = 1; break; } } + /* 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 0; + 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; @@ -354,6 +369,9 @@ main(int argc, char **argv) if (daemonize()) exit(1); + SSL_load_error_strings(); + OpenSSL_add_ssl_algorithms(); + sdb_plugin_init_all(); plugin_main_loop.default_interval = SECS_TO_SDB_TIME(60); @@ -377,6 +395,8 @@ main(int argc, char **argv) sdb_log(SDB_LOG_INFO, "Shutting down SysDB daemon "SDB_VERSION_STRING SDB_VERSION_EXTRA" (pid %i)", (int)getpid()); sdb_plugin_shutdown_all(); + + ERR_free_strings(); return status; } /* main */