sqlite: Add sqlite-based database adapter 88/165888/9
authorPaweł Szewczyk <p.szewczyk@samsung.com>
Fri, 19 Jan 2018 13:28:58 +0000 (14:28 +0100)
committerPaweł Szewczyk <p.szewczyk@samsung.com>
Fri, 16 Feb 2018 11:56:27 +0000 (12:56 +0100)
The skeleton of new module is added and the module added to building
system.

Change-Id: Iee2431c20dcf26cc1b85af530cba085167235463
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
Makefile.am
configure.ac
packaging/faultd.spec
src/database/sqlite.c [new file with mode: 0644]

index a5fa6a3e2a9a1ad1051a8c7dbbedfc3b4b6953e5..022cbd22c3df9a8d769348089d639f2d29b42cb8 100644 (file)
@@ -123,6 +123,7 @@ EXTRA_faultd_SOURCES = \
     src/listeners/systemd.c \
     src/listeners/startup.c \
     src/database/ejdb.c \
+    src/database/sqlite.c \
     src/decision_makers/vip_fault_dm.c \
     src/decision_makers/rv_dm.c \
     src/decision_makers/standard_fault_dm.c \
@@ -140,6 +141,7 @@ modules_LTLIBRARIES = audit_listener.la \
                  systemd_listener.la \
                  startup_listener.la \
                  ejdb_dbadapter.la \
+                 sqlite_dbadapter.la \
                  vip_fault_eh.la \
                  resource_violation_eh.la \
                  standard_fault_eh.la \
@@ -155,6 +157,8 @@ systemd_listener_la_SOURCES = src/listeners/systemd.c
 startup_listener_la_SOURCES = src/listeners/startup.c
 ejdb_dbadapter_la_SOURCES = src/database/ejdb.c
 ejdb_dbadapter_la_LIBADD = $(LIBEJDB_LIBS)
+sqlite_dbadapter_la_SOURCES = src/database/sqlite.c
+sqlite_dbadapter_la_LIBADD = $(SQLITE3_LIBS)
 vip_fault_eh_la_SOURCES = src/decision_makers/vip_fault_dm.c
 resource_violation_eh_la_SOURCES = src/decision_makers/rv_dm.c
 standard_fault_eh_la_SOURCES = src/decision_makers/standard_fault_dm.c
@@ -228,6 +232,7 @@ test_LDADD = \
     $(faultd_LDADD) \
     $(CMOCKA_LIBS) \
     $(AUDIT_LIBS) \
+    $(SQLITE3_LIBS) \
     $(LIBEJDB_LIBS)
 
 test_CFLAGS = -I${top_srcdir}/src/util \
index a1dfd049a5b6cc3bf40804ad702f3def5b9895b4..be46d52964ddfdbc5ccac35d19db48f141ff092d 100644 (file)
@@ -134,6 +134,13 @@ PKG_CHECK_MODULES(LIBEJDB,
 AS_IF([test "x$have_libejdb" = "xno"],
       AC_MSG_ERROR([EJDB version 1.2.12 or newer not found]))
 
+PKG_CHECK_MODULES(SQLITE3,
+        [sqlite3],
+        have_sqlite=yes,
+        have_sqlite=no)
+AS_IF([test "x$have_sqlite" = "xno"],
+      AC_MSG_ERROR([SQLITE3 not found]))
+
 PKG_CHECK_MODULES(JSON_C,
         [json-c],
         have_json_c=yes,
index 28f0991bfed92ba198dd73a8f7cac61f67a301a9..e7c846fc2e267c51c136e3033f68e7c04abce8bf 100644 (file)
@@ -8,11 +8,13 @@ Summary:    Fault detection daemon
 Group:      System/Monitoring
 
 %define with_faultd_glib_support 0
+%define database_module sqlite_dbadapter
 
 BuildRequires: pkgconfig(libsystemd)
 BuildRequires: pkgconfig(json-c)
 BuildRequires: pkgconfig(cmocka)
 BuildRequires: pkgconfig(libejdb)
+BuildRequires: pkgconfig(sqlite3)
 %if %{with_faultd_glib_support}
 BuildRequires: pkgconfig(glib-2.0)
 %endif
@@ -76,7 +78,6 @@ do
 done
 
 for mod in audit_listener \
-       ejdb_dbadapter \
        resource_violation_eh \
        service_recover_action \
        service_restart_action \
@@ -92,6 +93,17 @@ do
        echo %{enabled_moduledir}/${mod}.so >> faultd-extra-files;
 done
 
+for mod in ejdb_dbadapter \
+       sqlite_dbadapter
+do
+       ln -s %{moduledir}/${mod}.so %{buildroot}/%{moduleconfdir}/${mod}.so;
+       echo %{moduledir}/${mod}.so >> faultd-extra-files;
+       echo %{moduleconfdir}/${mod}.so >> faultd-extra-files;
+done
+
+ln -s ../available-modules/%{database_module}.so %{buildroot}/%{enabled_moduledir}/%{database_module}.so;
+echo %{enabled_moduledir}/%{database_module}.so >> faultd-extra-files;
+
 %files -f faultd-files
 %license COPYING
 %manifest %{name}.manifest
diff --git a/src/database/sqlite.c b/src/database/sqlite.c
new file mode 100644 (file)
index 0000000..afa31d5
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * This file is a part of faultd.
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <assert.h>
+#include <errno.h>
+#include <sqlite3.h>
+
+#include "database.h"
+#include "log.h"
+#include "module.h"
+
+#define ID_KEY "id"
+
+struct sqlite_adapter {
+       struct faultd_database_adapter database_adapter;
+};
+
+#define to_sqlite_adapter(MOD)                         \
+       container_of(MOD, struct sqlite_adapter, database_adapter)
+
+static void cleanup_sqlite_adapter(struct faultd_module *module)
+{
+}
+
+static int init_sqlite_adapter(struct faultd_module *module,
+                                                                struct faultd_config *config,
+                                                                sd_event *event_loop)
+{
+       return 0;
+}
+
+static int sqlite_store(struct faultd_database_adapter *adapter, struct faultd_object *obj, faultd_oid_t *oid)
+{
+       return 0;
+}
+
+static int sqlite_get_by_oid(struct faultd_database_adapter *adapter, faultd_oid_t *oid, struct faultd_object *result)
+{
+       return -ENOENT;
+}
+
+static int sqlite_load(struct faultd_database_adapter *adapter, struct faultd_object *query,
+                                        struct faultd_object *hints, struct faultd_object *result, uint32_t *nr)
+{
+       return 0;
+}
+
+static int sqlite_get_well_known_oid(const char *name, faultd_oid_t *oid)
+{
+       return -ENOENT;
+}
+
+static bool sqlite_is_oid_valid(faultd_oid_t *oid)
+{
+       return true;
+}
+
+static struct sqlite_adapter sqlite_adapter = {
+       .database_adapter = {
+               .module = {
+                       .name = "sqlite_dbadapter",
+                       .type = FAULTD_MODULE_TYPE_DBADAPTER,
+                       .init = init_sqlite_adapter,
+                       .cleanup = cleanup_sqlite_adapter,
+                       .node = LIST_HEAD_INIT(sqlite_adapter.database_adapter.module.node),
+               },
+               .id_key = ID_KEY,
+               .store = sqlite_store,
+               .get_by_oid = sqlite_get_by_oid,
+               .load = sqlite_load,
+               .get_well_known_oid = sqlite_get_well_known_oid,
+               .is_oid_valid = sqlite_is_oid_valid,
+       }
+};
+
+FAULTD_MODULE_REGISTER(&sqlite_adapter.database_adapter.module);