my_pid = getpid();
+ log_debug_elogind("Migrating \"%s\"/\"%s\" to \"%s\"/\"%s\" (%s)",
+ cfrom, pfrom, cto, pto,
+ ignore_self ? "ignoring self" : "watching self");
+
do {
_cleanup_fclose_ FILE *f = NULL;
pid_t pid = 0;
if (e)
return e;
- return controller;
+ return controller;
}
static int join_path_legacy(const char *controller, const char *path, const char *suffix, char **fs) {
r = join_path_unified(path, suffix, fs);
else
r = join_path_legacy(controller, path, suffix, fs);
- if (r < 0)
- return r;
+
+ if (r < 0)
+ return r;
path_kill_slashes(*fs);
return 0;
* the unified hierarchy. */
if (streq(controller, ELOGIND_CGROUP_CONTROLLER))
- return 0;
+ return 0;
if (startswith(controller, "name="))
return -EOPNOTSUPP;
dn = controller_to_dirname(controller);
cc = strjoina("/sys/fs/cgroup/", dn);
- if (laccess(cc, F_OK) < 0)
- return -errno;
+ if (laccess(cc, F_OK) < 0)
+ return -errno;
}
return 0;
if (unified < 0)
return unified;
if (unified == 0) {
- if (controller) {
- if (!cg_controller_is_valid(controller))
- return -EINVAL;
- } else
- controller = ELOGIND_CGROUP_CONTROLLER;
+ if (controller) {
+ if (!cg_controller_is_valid(controller))
+ return -EINVAL;
+ } else
+ controller = ELOGIND_CGROUP_CONTROLLER;
cs = strlen(controller);
}
fs = procfs_file_alloca(pid, "cgroup");
+ log_debug_elogind("Searching for PID %u in \"%s\" (controller \"%s\")",
+ pid, fs, controller);
f = fopen(fs, "re");
if (!f)
return errno == ENOENT ? -ESRCH : -errno;
continue;
} else {
char *l;
- size_t k;
- const char *word, *state;
- bool found = false;
+ size_t k;
+ const char *word, *state;
+ bool found = false;
- l = strchr(line, ':');
- if (!l)
- continue;
+ l = strchr(line, ':');
+ if (!l)
+ continue;
- l++;
- e = strchr(l, ':');
- if (!e)
- continue;
+ l++;
+ e = strchr(l, ':');
+ if (!e)
+ continue;
- *e = 0;
- FOREACH_WORD_SEPARATOR(word, k, l, ",", state) {
- if (k == cs && memcmp(word, controller, cs) == 0) {
- found = true;
- break;
+ *e = 0;
+ FOREACH_WORD_SEPARATOR(word, k, l, ",", state) {
+ if (k == cs && memcmp(word, controller, cs) == 0) {
+ found = true;
+ break;
+ }
}
- }
- if (!found)
- continue;
+ if (!found)
+ continue;
}
+ log_debug_elogind("Found %s:%s", line, e+1);
p = strdup(e + 1);
if (!p)
return -ENOMEM;
* via the "cgroup.populated" attribute. */
r = cg_get_path(controller, path, "cgroup.populated", &populated);
- if (r < 0)
- return r;
+ if (r < 0)
+ return r;
r = read_one_line_file(populated, &t);
if (r == -ENOENT)
return streq(t, "0");
} else {
- _cleanup_closedir_ DIR *d = NULL;
- char *fn;
+ _cleanup_closedir_ DIR *d = NULL;
+ char *fn;
r = cg_is_empty(controller, path);
- if (r <= 0)
- return r;
+ if (r <= 0)
+ return r;
- r = cg_enumerate_subgroups(controller, path, &d);
- if (r == -ENOENT)
- return 1;
- if (r < 0)
+ r = cg_enumerate_subgroups(controller, path, &d);
+ if (r == -ENOENT)
+ return 1;
+ if (r < 0)
return r;
- while ((r = cg_read_subgroup(d, &fn)) > 0) {
- _cleanup_free_ char *p = NULL;
+ while ((r = cg_read_subgroup(d, &fn)) > 0) {
+ _cleanup_free_ char *p = NULL;
- p = strjoin(path, "/", fn, NULL);
- free(fn);
- if (!p)
- return -ENOMEM;
+ p = strjoin(path, "/", fn, NULL);
+ free(fn);
+ if (!p)
+ return -ENOMEM;
r = cg_is_empty_recursive(controller, p);
- if (r <= 0)
+ if (r <= 0)
+ return r;
+ }
+ if (r < 0)
return r;
- }
- if (r < 0)
- return r;
return true;
}
return r;
root = rt;
+ log_debug_elogind("Determined root path: \"%s\"", root);
}
p = path_startswith(cgroup, root);
- if (p && p > cgroup)
+ if (p && p[0] && (p > cgroup))
*shifted = p - 1;
else
*shifted = cgroup;
if (r < 0)
return r;
+ log_debug_elogind("Shifting path: \"%s\" (PID %u, root: \"%s\")",
+ raw, pid, root ? root : "NULL");
r = cg_shift_path(raw, root, &c);
if (r < 0)
return r;
*cgroup = n;
}
+ log_debug_elogind("Resulting cgroup:\"%s\"", *cgroup);
return 0;
}
const char *e, *n, *start;
assert(path);
+ log_debug_elogind("path is \"%s\"", path);
assert(path[0] == '/');
e = path + 1;
if (session) {
char *rr;
+ log_debug_elogind("found session: \"%s\"", start);
rr = strdup(start);
if (!rr)
return -ENOMEM;
if (memcmp(p, n, l) != 0)
continue;
- need_prefix = true;
+ need_prefix = true;
break;
}
}
if (need_prefix)
return strappend("_", p);
- return strdup(p);
+ return strdup(p);
}
char *cg_unescape(const char *p) {
return 0;
}
-#endif // 0
int cg_attach_everywhere(CGroupMask supported, const char *path, pid_t pid, cg_migrate_callback_t path_callback, void *userdata) {
CGroupController c;
return 0;
}
-/// UNNEEDED by elogind
-#if 0
int cg_attach_many_everywhere(CGroupMask supported, const char *path, Set* pids, cg_migrate_callback_t path_callback, void *userdata) {
Iterator i;
void *pidp;
else if (F_TYPE_EQUAL(fs.f_type, TMPFS_MAGIC))
#else
if (F_TYPE_EQUAL(fs.f_type, TMPFS_MAGIC))
-#endif // elogind
+#endif // 0
unified_cache = false;
else
return -ENOEXEC;
return 0;
}
-#endif // 0
bool cg_is_unified_wanted(void) {
static thread_local int wanted = -1;
}
}
-/// UNNEEDED by elogind
-#if 0
bool cg_is_legacy_wanted(void) {
return !cg_is_unified_wanted();
}