Code

store: Drop the global (default) store.
[sysdb.git] / src / tools / sysdbd / main.c
index cc3525e30ef4374e3c904797cccd176de2e94043..ce54313542df26cd254847d601f01fc14413d74a 100644 (file)
@@ -181,6 +181,31 @@ daemonize(void)
        return 0;
 } /* daemonize */
 
+static int
+store_init(void)
+{
+       sdb_store_t *store = sdb_store_create();
+
+       if (! store) {
+               sdb_log(SDB_LOG_ERR, "store: Failed to allocate store");
+               return -1;
+       }
+       if (sdb_plugin_register_writer("memstore",
+                               &sdb_store_writer, SDB_OBJ(store))) {
+               sdb_object_deref(SDB_OBJ(store));
+               return -1;
+       }
+       if (sdb_plugin_register_reader("memstore",
+                               &sdb_store_reader, SDB_OBJ(store))) {
+               sdb_object_deref(SDB_OBJ(store));
+               return -1;
+       }
+
+       /* Pass ownership to the plugins */
+       sdb_object_deref(SDB_OBJ(store));
+       return 0;
+} /* store_init */
+
 static int
 configure(void)
 {
@@ -194,6 +219,10 @@ configure(void)
                                        "\tCheck other error messages for details.");
                return 1;
        }
+       if (store_init()) {
+               sdb_log(SDB_LOG_ERR, "Failed to initialize the store");
+               return 1;
+       }
 
        if (! listen_addresses) {
                listen_addresses = default_listen_addresses;
@@ -370,8 +399,6 @@ main(int argc, char **argv)
 
        if (sdb_ssl_init())
                exit(1);
-       if (sdb_store_init())
-               exit(1);
        sdb_plugin_init_all();
        plugin_main_loop.default_interval = SECS_TO_SDB_TIME(60);