Add service restart action implementation 12/129512/3
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 16 May 2017 11:08:44 +0000 (13:08 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Thu, 18 May 2017 17:20:45 +0000 (19:20 +0200)
Change-Id: If82d9d6e4083504493f945a7bc5c309e49cbfac4
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Makefile.am
src/action/service_restart.c [new file with mode: 0644]

index 7a2c45dcac8f40850bc9fcfa4a5e8415d8b0a089..9ab0bff50e0c0d3e90899b3d3f55192a020fcee2 100644 (file)
@@ -35,6 +35,7 @@ SED_PROCESS = \
 sbin_PROGRAMS = faultd
 faultd_SOURCES = \
     src/action/action_executor.c \
+    src/action/service_restart.c \
     src/core/event.c \
     src/core/event_processor.c \
     src/core/service.c \
diff --git a/src/action/service_restart.c b/src/action/service_restart.c
new file mode 100644 (file)
index 0000000..949cb45
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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 restart_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);
+       int ret;
+
+       ret = faultd_dbus_call_systemd_simple((char *)dm_ev->action_data,
+                                                                                 SYSTEMD_UNIT_INTERFACE,
+                                                                                 "Restart",
+                                                                                 "s",
+                                                                                 "replace");
+       if (ret < 0)
+               log_error_errno(ret, "Failed to restart service: %s",
+                                               (char *)dm_ev->action_data);
+
+       faultd_event_unref(ev);
+       return 0;
+}
+
+static struct faultd_action service_restart_action = {
+       .action_id = FAULTD_ACTION_SERVICE_RESTART_ID,
+       .impl_name = FAULTD_DEFAULT_ACTION_IMPL,
+       .execute = restart_service,
+       .node = LIST_HEAD_INIT(service_restart_action.node),
+};
+
+FAULTD_ACTION_REGISTER_SIMPLE(service_restart_action);
+