activationd decision maker: add stop and restart actions 50/201050/12
authorMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Thu, 7 Mar 2019 18:08:37 +0000 (19:08 +0100)
committerMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Mon, 25 Mar 2019 14:28:57 +0000 (15:28 +0100)
Change-Id: Ie54f143190540e9f5560e2a0611a246c280d6f55
Signed-off-by: Maciej Slodczyk <m.slodczyk2@partner.samsung.com>
activationd/decision_makers/activation_dm.c
include/action.h
modules.conf.d/activation_eh.conf.d/activation_eh.conf
src/action/unit_start.c
src/core/action.c

index dfa4837348c7a2f0ec178ab0ce8f854641ee0f61..fcccecacf962b1fa45b00b223d6034e8cc998287 100644 (file)
@@ -111,6 +111,7 @@ static int execute_rule(struct rule *r, struct epc_event *ev)
                log_error("Unable to create event data");
                goto out;
        }
+       epc_fill_for_unit_action(ev_data.action_data, r->action);
 
        ret = epc_event_create(DECISION_MADE_EVENT_ID, &ev_data, &new_ev);
        if (ret) {
index 79c2afd3aadc86358538c726488ccae024d17f20..cae577d8024f0189a45ff310feb40e6e0f9e8698 100644 (file)
 #define EPC_AD_SERVICE_NAME "ServiceName"
 #define EPC_AD_CLEANUP_UNIT "RecoveryUnit"
 #define EPC_AD_UNIT_NAME "UnitName"
+#define EPC_AD_UNIT_ACTION "UnitAction"
 
 int epc_fill_for_srv_restart(struct epc_object *obj, char *service_path);
 
 int epc_fill_for_srv_recover(struct epc_object *obj, char *service_path, char *recovery);
 
 int epc_fill_for_unit_start(struct epc_object *obj, char *unit_path);
+int epc_fill_for_unit_action(struct epc_object *obj, char *action);
 
 #define epc_fill_for_reboot(o)                                 \
        epc_object_fill_empty(o)
index 47a25692a5b7dbf2727ce2706a478b142ef4667c..9d55a9a98e80bb3088685298044d5727cdf6412c 100644 (file)
@@ -1,5 +1,5 @@
 {
        "rules":[
-       {"event":"vconf_key_changed", "key_name":"db/test/key3", "action":"Start", "target":"foo.service"}
+       {"event":"vconf_key_changed", "key_name":"db/test/key3", "action":"StartUnit", "target":"foo.service"}
        ]
 }
index 53c2b7815f0a54d78849ede6f12168138f5e8d5f..ea2853e0bb5ce447f40d2d8dda182bd111aa8d88 100644 (file)
@@ -29,6 +29,7 @@ static int start_unit(struct epc_action *action,
        struct epc_event *ev = pop_epc_event(&action->execution_queue);
        struct decision_made_event *dm_ev = to_decision_made_event(ev);
        char *unit_name = NULL;
+       char *unit_action = NULL;
        int ret;
 
        /*
@@ -46,9 +47,28 @@ static int start_unit(struct epc_action *action,
                return 0;
        }
 
+       epc_object_get_string(dm_ev->action_data,
+                       EPC_AD_UNIT_ACTION, &unit_action);
+       if (!unit_action) {
+               epc_object_append_string(exe_info->action_log, "error",
+                               "Unit action not specified");
+               exe_info->result = -EINVAL;
+               return 0;
+       }
+
+       if (strcmp(unit_action, "StartUnit") &&
+                       strcmp(unit_action, "StopUnit") &&
+                       strcmp(unit_action, "RestartUnit")) {
+               epc_object_append_string(exe_info->action_log, "error",
+                               "Unit action is not one of \"StartUnit\", "
+                               "\"StopUnit\" or \"RestartUnit\"");
+               exe_info->result = -EINVAL;
+               return 0;
+       }
+
        ret = epc_dbus_call_systemd_simple(SYSTEMD_OBJ,
                        SYSTEMD_MANAGER_INTERFACE,
-                       "StartUnit",
+                       unit_action,
                        "ss",
                        unit_name,
                        "replace");
index f9e219f1f6cc4495f5bf7a67b64b94dd5641d080..87eed93f3cfe04c182d675113e9d0b8d4c7ea2f2 100644 (file)
@@ -72,3 +72,17 @@ int epc_fill_for_unit_start(struct epc_object *obj, char *unit_path)
 
        return 0;
 }
+
+int epc_fill_for_unit_action(struct epc_object *obj, char *unit_action)
+{
+       int ret;
+
+       ret = epc_object_append_string(obj, EPC_AD_UNIT_ACTION, unit_action);
+       if (ret < 0) {
+               log_error("Unable to append %s:%s",
+                                 EPC_AD_UNIT_ACTION, unit_action);
+               return -ENOMEM;
+       }
+
+       return 0;
+}