unit_control: Do not query systemd for non-wildcards 01/208601/1
authorPaweł Szewczyk <p.szewczyk@samsung.com>
Wed, 26 Jun 2019 08:55:51 +0000 (10:55 +0200)
committerPaweł Szewczyk <p.szewczyk@samsung.com>
Wed, 26 Jun 2019 08:55:51 +0000 (10:55 +0200)
Unit names with wildcards can match multiple units, but non-wildcard
names are always matched directly and do not need querying systemd.
Avoiding this should reduce delay and fixes restarting inactive units
(which systemctl does, and so should we)

Change-Id: I2609fc619a84875e77039ae80995ed249edcf85d
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
src/decision_makers/unit_control_dm.c

index 5f54727b36299d473a24226973caeb16d5454970..9e5714a3e26d983e36d7437c9a194583acdc7045 100644 (file)
@@ -399,6 +399,14 @@ static char *construct_proper_service_name(char *requested_name, char *whitelist
        return ret;
 }
 
+static bool is_wildcard(char *service_name)
+{
+       char *c;
+
+       c = strchr(service_name, '*');
+       return c && *c != '\0';
+}
+
 static int unit_control_make_decision(struct epc_event_handler *handler)
 {
        assert(handler);
@@ -435,7 +443,7 @@ static int unit_control_make_decision(struct epc_event_handler *handler)
 
                log_debug("execute action %s on pattern %s", ev->method, service_name);
 
-               if (!strcmp(ev->method, "start")) /* no need to query when starting */
+               if (!strcmp(ev->method, "start") || !is_wildcard(service_name)) /* no need to query when starting or for single unit*/
                        ret = unit_control_execute(service_name, ev->method, event);
                else
                        ret = unit_control_query_and_execute(service_name, ev->method, event);