Add default implementation of system reboot action 10/129710/3
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Wed, 17 May 2017 20:48:45 +0000 (22:48 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Thu, 18 May 2017 17:20:45 +0000 (19:20 +0200)
Change-Id: Ib6c0f18dc7037bf1b0bc5259bfad023ec00ea330
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Makefile.am
src/action/system_reboot.c [new file with mode: 0644]

index c25b279539f746be95d846e3749cb6237e1c3ddd..8b609eab5769e330cccba63ab3346d6887e7d63a 100644 (file)
@@ -39,6 +39,7 @@ faultd_SOURCES = \
     src/action/action_executor.c \
     src/action/service_recover.c \
     src/action/service_restart.c \
+    src/action/system_reboot.c \
     src/core/event.c \
     src/core/event_processor.c \
     src/core/service.c \
diff --git a/src/action/system_reboot.c b/src/action/system_reboot.c
new file mode 100644 (file)
index 0000000..78a77be
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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 "action.h"
+#include "action_executor.h"
+#include "decision_made_event.h"
+#include "log.h"
+#include "systemd_dbus.h"
+
+static int reboot_system(struct faultd_action *action)
+{
+       struct faultd_event *ev = nqueue_pop(&action->execution_queue,
+                                                                                struct faultd_event, nq_node);
+       int ret;
+
+       /*
+        * We reboot the system without using logind because this action may be
+        * executed when for example dbus daemon is dead
+        */
+       ret = faultd_dbus_call_systemd_simple(SYSTEMD_OBJ,
+                                                                                 SYSTEMD_MANAGER_INTERFACE,
+                                                                                 "StartUnit",
+                                                                                 "ss",
+                                                                                 "reboot.target",
+                                                                                 "replace-irreversibly");
+       if (ret < 0)
+               log_error_errno(ret, "Failed to reboot the system");
+
+       faultd_event_unref(ev);
+       return 0;
+}
+
+static struct faultd_action system_reboot_action = {
+       .action_id = FAULTD_ACTION_REBOOT_ID,
+       .impl_name = FAULTD_DEFAULT_ACTION_IMPL,
+       .execute = reboot_system,
+       .node = LIST_HEAD_INIT(system_reboot_action.node),
+};
+
+FAULTD_ACTION_REGISTER_SIMPLE(system_reboot_action);