/* * 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 "action.h" #include "action_executor.h" #include "decision_made_event.h" #include "log.h" #include "systemd_dbus.h" #include "common.h" static int recover_service(struct faultd_action *action) { struct faultd_event *ev = nqueue_pop(&action->execution_queue, struct faultd_event, nq_node); struct decision_made_event *dm_ev = to_decision_made_event(ev); char *service_path = NULL; int ret; ret = faultd_object_get_string(dm_ev->action_data, FAULTD_AD_SERVICE_NAME, &service_path); if (ret < 0) { log_error("Service path has not been provided"); goto unref_old_event; } /* * TODO: * For now it's just copy paste of service restart * Add some real recovery action here */ ret = faultd_dbus_call_systemd_simple(service_path, SYSTEMD_UNIT_INTERFACE, "Restart", "s", "replace"); if (ret < 0) log_error_errno(ret, "Failed to restart service: %s", service_path); unref_old_event: faultd_event_unref(ev); return 0; } static struct faultd_action service_recover_action = { .action_id = FAULTD_ACTION_SERVICE_RECOVER_ID, .impl_name = FAULTD_DEFAULT_ACTION_IMPL, .execute = recover_service, .node = LIST_HEAD_INIT(service_recover_action.node), }; FAULTD_ACTION_REGISTER_SIMPLE(service_recover_action);