Code

sysdbd: Return with status=1 in case of an initialization or config error.
[sysdb.git] / src / tools / sysdbd / main.c
index 3be49381e43f2bc37686b01ae60672e58e2baef2..4af2de13715ff1f59189ef0e9e4cab90e408b253 100644 (file)
@@ -217,7 +217,6 @@ do_reconfigure(void)
                return status;
        sdb_plugin_init_all();
        sdb_plugin_reconfigure_finish();
-       sdb_connection_enable_logging();
        return 0;
 } /* do_reconfigure */
 
@@ -233,9 +232,10 @@ static int
 main_loop(void)
 {
        sdb_fe_socket_t *sock = sdb_fe_sock_create();
-
        pthread_t backend_thread;
 
+       int status = 0;
+
        while (42) {
                size_t i;
 
@@ -253,13 +253,25 @@ 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])) {
+                               status = 1;
                                break;
+                       }
+               }
 
                /* break on error */
-               if (i >= listen_addresses_num)
-                       sdb_fe_sock_listen_and_serve(sock, &frontend_main_loop);
+               if (i < listen_addresses_num) {
+                       status = 1;
+                       break;
+               }
+
+               sdb_log(SDB_LOG_INFO, "SysDB daemon "SDB_VERSION_STRING
+                               SDB_VERSION_EXTRA " (pid %i) initialized successfully",
+                               (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;
@@ -275,12 +287,13 @@ main_loop(void)
                sdb_fe_sock_clear_listeners(sock);
                if (do_reconfigure()) {
                        sdb_log(SDB_LOG_ERR, "Reconfiguration failed");
+                       status = 1;
                        break;
                }
        }
 
        sdb_fe_sock_destroy(sock);
-       return 0;
+       return status;
 } /* main_loop */
 
 int
@@ -348,10 +361,6 @@ 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());
-
        sdb_plugin_init_all();
        plugin_main_loop.default_interval = SECS_TO_SDB_TIME(60);
 
@@ -370,11 +379,11 @@ 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();
        return status;
 } /* main */