add basic vconf decision maker sandbox/slodki/vconf
authorMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Fri, 22 Feb 2019 14:05:39 +0000 (15:05 +0100)
committerMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Thu, 28 Feb 2019 09:56:20 +0000 (10:56 +0100)
Makefile.am
packaging/faultd.spec
src/decision_makers/vconf_dm.c [new file with mode: 0644]

index d6cdadc580994111ecd1cad0e886cd18d7567f35..5b6e9128b2c60dfa81f0bad8769b01a9d79a912d 100644 (file)
@@ -127,6 +127,7 @@ EXTRA_faultd_SOURCES = \
     src/listeners/startup.c \
     src/listeners/vconf.c \
     src/database/sqlite.c \
+    src/decision_makers/vconf_dm.c \
     src/decision_makers/vip_fault_dm.c \
     src/decision_makers/rv_dm.c \
     src/decision_makers/standard_fault_dm.c \
@@ -145,6 +146,7 @@ modules_LTLIBRARIES = audit_listener.la \
                  startup_listener.la \
                  vconf_listener.la \
                  sqlite_dbadapter.la \
+                 vconf_eh.la \
                  vip_fault_eh.la \
                  resource_violation_eh.la \
                  standard_fault_eh.la \
@@ -164,6 +166,7 @@ vconf_listener_configdir = $(modulesconfigdir)/vconf_listener.conf.d
 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
+vconf_eh_la_SOURCES = src/decision_makers/vconf_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
 standard_fault_eh_config_DATA = modules.conf.d/standard_fault_eh.conf.d/50-default.conf
index 5b0c0b5bf2e7ab33e06c8f54ce929d76fcb0d5cb..8675f9de2a7006b2eadbadadab822d1e6c598f65 100644 (file)
@@ -69,6 +69,7 @@ ln -s %{_sbindir}/faultd %{buildroot}/%{_sbindir}/faultctl
 %define enabled_moduledir %{_sysconfdir}/faultd/enabled-modules/
 
 for mod in systemd_listener \
+       vconf_eh \
        vip_fault_eh \
        system_reboot_action
 do
diff --git a/src/decision_makers/vconf_dm.c b/src/decision_makers/vconf_dm.c
new file mode 100644 (file)
index 0000000..4e2e3c5
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * This file is 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 <malloc.h>
+#include <errno.h>
+
+#include "decision_made_event.h"
+#include "vconf_key_changed_event.h"
+#include "action.h"
+#include "event_processor.h"
+#include "log.h"
+
+#define MODULE_NAME "vconf_decision_maker"
+
+static int vkc_event_match(struct faultd_event_handler *handler,
+                                                 struct faultd_event *ev)
+{
+       struct vconf_key_changed_event *vkc_ev =
+               to_vconf_key_changed_event(ev);
+
+       if (faultd_event_is_of_type(ev, VCONF_KEY_CHANGED_EVENT_ID) &&
+                               vkc_ev->newval.type == VKC_STRING &&
+                               !strncmp(vkc_ev->newval.value.s, "reboot", 6))
+                       return true;
+
+       return false;
+}
+
+static int vkc_make_decision(struct faultd_event_handler *handler)
+{
+       struct faultd_event *ev = pop_faultd_event(&handler->event_queue);
+       struct faultd_event *new_ev;
+       struct dm_event_data ev_data = {
+               .reason = ev,
+               .who_made = MODULE_NAME,
+               .action = FAULTD_ACTION_REBOOT_ID,
+       };
+       int ret;
+
+       ret = faultd_object_new(&ev_data.action_data);
+       if (ret < 0) {
+               log_error("Unable to create faultd object");
+               goto unref_ev;
+       }
+
+       ret = faultd_fill_for_reboot(ev_data.action_data);
+       if (ret) {
+               log_error("Unable to create action data");
+               faultd_object_unref(ev_data.action_data);
+               goto unref_ev;
+       }
+
+       ret = faultd_event_create(DECISION_MADE_EVENT_ID, &ev_data, &new_ev);
+       faultd_object_unref(ev_data.action_data);
+       if (ret) {
+               log_error("Unable to create event");
+               goto unref_ev;
+       }
+
+       ret = event_processor_report_event(new_ev);
+       faultd_event_unref(new_ev);
+       if (ret) {
+               log_error("Unable to report event");
+               goto unref_ev;
+       }
+
+unref_ev:
+       faultd_event_unref(ev);
+       return 0;
+}
+
+static struct faultd_event_handler vconf_key_changed_event_handler = {
+       .name = MODULE_NAME,
+       .event_match = vkc_event_match,
+       .handle_event = vkc_make_decision,
+
+       .node = LIST_HEAD_INIT(vconf_key_changed_event_handler),
+};
+
+FAULTD_EVENT_HANDLER_REGISTER(vconf_key_changed_event_handler,
+                                                         vconf_key_changed_eh,
+                                                         FAULTD_MODULE_TYPE_DECISION_MAKER)