core: fix the CGROUP spawning error as a workaround
authorSangjung Woo <sangjung.woo@samsung.com>
Wed, 26 Aug 2015 01:32:29 +0000 (10:32 +0900)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Fri, 24 Feb 2017 15:08:15 +0000 (16:08 +0100)
When logging in and out continually, the below error occurs.

* systemd: Failed at step CGROUP spawning /usr/lib/systemd/systemd: No
such file or directory

This is mainly because the cgroup path of systemd user session does not
exists even though that cgroup is marked as 'realized'. That is
definitely bug and it is already reported into systemd mainline last
January. But there is no _right_ solution right now and it looks like a
picky problem to resolve. So I made this patch as a workaround for Tizen
TDC demonstration.

Change-Id: Ie2e164a4e4daeb88fc102e5fa88e0faca28088b0
Signed-off-by: Sangjung Woo <sangjung.woo@samsung.com>
src/basic/cgroup-util.c
src/core/service.c

index 472e24b..4702d85 100644 (file)
@@ -2363,3 +2363,15 @@ static const char *cgroup_controller_table[_CGROUP_CONTROLLER_MAX] = {
 };
 
 DEFINE_STRING_TABLE_LOOKUP(cgroup_controller, CGroupController);
+
+int cg_check_cgroup_exist(const char *p) {
+        const char *cc;
+        assert(p);
+
+        cc = strjoina("/sys/fs/cgroup/systemd", p);
+        if (laccess(cc, F_OK) < 0) {
+                return -errno;
+        }
+
+        return 0;
+}
index afb1985..458d74a 100644 (file)
@@ -1174,12 +1174,21 @@ static int service_spawn(
         assert(c);
         assert(_pid);
 
-        (void) unit_realize_cgroup(UNIT(s));
-        if (s->reset_cpu_usage) {
-                (void) unit_reset_cpu_usage(UNIT(s));
-                s->reset_cpu_usage = false;
+
+        /* TODO workaround code */
+        if (UNIT(s)->cgroup_realized) {
+                _cleanup_free_ char *path = NULL;
+                path = unit_default_cgroup_path(UNIT(s));
+
+                if (cg_check_cgroup_exist(path) < 0) {
+                        log_unit_error(UNIT(s)->id, "CGROUP ERROR! (%s) is already realized but not exists", UNIT(s)->id);
+                        UNIT(s)->cgroup_realized = false;
+                        UNIT(s)->cgroup_realized_mask = 0;
+                }
         }
 
+        unit_realize_cgroup(UNIT(s));
+
         r = unit_setup_exec_runtime(UNIT(s));
         if (r < 0)
                 return r;