Code

Unload all plugins when shutting down sysdbd.
[sysdb.git] / src / tools / sysdbd / main.c
index 7dc9f26ba4b33bff7ab41a67996bedb34aa1a824..25f6499feecc4817903a4ccf13105c43d81ad08c 100644 (file)
@@ -60,6 +60,9 @@
 
 #include <pthread.h>
 
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+
 #ifndef CONFIGFILE
 #      define CONFIGFILE SYSCONFDIR"/sysdb/sysdbd.conf"
 #endif
@@ -74,8 +77,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
@@ -236,7 +239,7 @@ main_loop(void)
 
        int status = 0;
 
-       while (42) {
+       while (status == 0) {
                size_t i;
 
                plugin_main_loop.do_loop = 1;
@@ -254,20 +257,20 @@ main_loop(void)
                }
 
                for (i = 0; i < listen_addresses_num; ++i) {
-                       if (sdb_fe_sock_add_listener(sock, listen_addresses[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) {
-                       status = 1;
+               if (status)
                        break;
-               }
 
                sdb_log(SDB_LOG_INFO, "SysDB daemon "SDB_VERSION_STRING
-                               SDB_VERSION_EXTRA " (pid %i) initialized successfully",
+                               SDB_VERSION_EXTRA " (libsysdb %s%s, pid %i) initialized "
+                               "successfully", sdb_version_string(), sdb_version_extra(),
                                (int)getpid());
 
                sdb_connection_enable_logging();
@@ -293,6 +296,8 @@ main_loop(void)
        }
 
        /* 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);
 
@@ -303,7 +308,7 @@ main_loop(void)
 int
 main(int argc, char **argv)
 {
-       _Bool do_daemonize = 1;
+       bool do_daemonize = 1;
 
        struct sigaction sa_intterm;
        struct sigaction sa_hup;
@@ -365,6 +370,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);
 
@@ -388,6 +396,9 @@ 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();
+       sdb_plugin_unregister_all();
+
+       ERR_free_strings();
        return status;
 } /* main */