From: Paweł Szewczyk Date: Tue, 29 Jan 2019 12:44:30 +0000 (+0100) Subject: action: Add unit_start action X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0cf917c014cf42747fa5990205f752ba833bd7c3;p=platform%2Fcore%2Fsystem%2Ffaultd.git action: Add unit_start action Change-Id: I86ef58114a55e876ebce14ec2c9e8f44ae428677 Signed-off-by: Paweł Szewczyk --- diff --git a/Makefile.am b/Makefile.am index 3530c11..95a249e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -130,7 +130,8 @@ EXTRA_faultd_SOURCES = \ 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 @@ -147,7 +148,8 @@ modules_LTLIBRARIES = audit_listener.la \ 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) @@ -167,6 +169,7 @@ service_restart_action_la_SOURCES = src/action/service_restart.c 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 diff --git a/packaging/faultd.spec b/packaging/faultd.spec index 60de114..d1d78cd 100644 --- a/packaging/faultd.spec +++ b/packaging/faultd.spec @@ -85,7 +85,8 @@ for mod in audit_listener \ standard_fault_eh \ standard_reboot_eh \ startup_listener \ - system_reboot_to_recovery_action + system_reboot_to_recovery_action \ + unit_start_action do ln -s %{moduledir}/${mod}.so %{buildroot}/%{moduleconfdir}/${mod}.so; ln -s ../available-modules/${mod}.so %{buildroot}/%{enabled_moduledir}/${mod}.so; diff --git a/src/action/unit_start.c b/src/action/unit_start.c new file mode 100644 index 0000000..128e8f3 --- /dev/null +++ b/src/action/unit_start.c @@ -0,0 +1,69 @@ +/* + * 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); diff --git a/src/core/action.c b/src/core/action.c index 517d3d6..92c85e7 100644 --- a/src/core/action.c +++ b/src/core/action.c @@ -58,3 +58,17 @@ int faultd_fill_for_srv_recover(struct faultd_object *obj, char *service_path, c return 0; } + +int faultd_fill_for_unit_start(struct faultd_object *obj, char *unit_path) +{ + int ret; + + ret = faultd_object_append_string(obj, FAULTD_AD_UNIT_NAME, unit_path); + if (ret < 0) { + log_error("Unable to append %s:%s", + FAULTD_AD_UNIT_NAME, unit_path); + return -ENOMEM; + } + + return 0; +} diff --git a/src/core/action.h b/src/core/action.h index 13785fc..d13fcb6 100644 --- a/src/core/action.h +++ b/src/core/action.h @@ -25,16 +25,20 @@ #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)