src/action/service_restart.c \
src/action/system_reboot.c \
src/action/system_reboot_to_recovery.c \
- src/action/service_recover.c
+ src/action/service_recover.c \
+ src/action/unit_start.c
faultd_CFLAGS = $(AM_CFLAGS)
faultd_LDFLAGS = -ldl
service_restart_action.la \
system_reboot_action.la \
system_reboot_to_recovery_action.la \
- service_recover_action.la
+ service_recover_action.la \
+ unit_start_action.la
audit_listener_la_SOURCES = src/listeners/audit.c
audit_listener_la_LIBADD = $(AUDIT_LIBS)
system_reboot_action_la_SOURCES = src/action/system_reboot.c
system_reboot_to_recovery_action_la_SOURCES = src/action/system_reboot_to_recovery.c
service_recover_action_la_SOURCES = src/action/service_recover.c
+unit_start_action_la_SOURCES = src/action/unit_start.c
if USE_EJDB
EXTRA_faultd_SOURCES += src/database/ejdb.c
--- /dev/null
+/*
+ * This file is part of faultd.
+ *
+ * Copyright © 2019 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"
+#include "common.h"
+
+static int start_unit(struct faultd_action *action,
+ struct action_executed_event *exe_info)
+{
+ struct faultd_event *ev = pop_faultd_event(&action->execution_queue);
+ struct decision_made_event *dm_ev = to_decision_made_event(ev);
+ char *unit_path = NULL;
+ int ret;
+
+ /*
+ * We are passing an event to exe_info, so there is no need to unref it
+ * in this function
+ */
+ exe_info->reason = ev;
+
+ ret = faultd_object_get_string(dm_ev->action_data,
+ FAULTD_AD_UNIT_NAME, &unit_path);
+ if (!unit_path) {
+ faultd_object_append_string(exe_info->action_log, "error",
+ "Unit path not specified");
+ exe_info->result = -EINVAL;
+ return 0;
+ }
+
+ ret = faultd_dbus_call_systemd_simple(unit_path,
+ SYSTEMD_UNIT_INTERFACE,
+ "Start", NULL);
+ if (ret < 0)
+ faultd_object_append_string(exe_info->action_log, "error",
+ "Failed to call systemd");
+ else
+ log_kmsg("Starting unit: %s", unit_path);
+
+ exe_info->result = ret;
+ return 0;
+}
+
+static struct faultd_action unit_start_action = {
+ .action_id = FAULTD_ACTION_UNIT_START_ID,
+ .impl_name = FAULTD_DEFAULT_ACTION_IMPL,
+ .execute = start_unit,
+ .node = LIST_HEAD_INIT(unit_start_action.node),
+};
+
+FAULTD_ACTION_REGISTER_SIMPLE(unit_start_action);
#define FAULTD_ACTION_SERVICE_RECOVER_ID "org.tizen.faultd.action.SERVICE_RECOVER"
#define FAULTD_ACTION_REBOOT_ID "org.tizen.faultd.action.REBOOT"
#define FAULTD_ACTION_RECOVERY_REBOOT_ID "org.tizen.faultd.action.RECOVERY_REBOOT"
+#define FAULTD_ACTION_UNIT_START_ID "org.tizen.faultd.action.UNIT_START"
#define FAULTD_DEFAULT_ACTION_IMPL "default"
#define FAULTD_AD_SERVICE_NAME "ServiceName"
#define FAULTD_AD_CLEANUP_UNIT "RecoveryUnit"
+#define FAULTD_AD_UNIT_NAME "UnitName"
int faultd_fill_for_srv_restart(struct faultd_object *obj, char *service_path);
int faultd_fill_for_srv_recover(struct faultd_object *obj, char *service_path, char *recovery);
+int faultd_fill_for_unit_start(struct faultd_object *obj, char *unit_path);
+
#define faultd_fill_for_reboot(o) \
faultd_object_fill_empty(o)