#include "formats-util.h"
#include "process-util.h"
#include "path-util.h"
-#include "unit-name.h"
+// #include "unit-name.h"
#include "fileio.h"
// #include "special.h"
#include "mkdir.h"
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;
* 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);
}
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;
}
p = strdup(e + 1);
}
int cg_get_root_path(char **path) {
- char *p; //, *e;
+/// elogind does not support systemd scopes and slices
+#if 0
+ char *p, *e;
int r;
assert(path);
if (r < 0)
return r;
-/// elogind does not support systemd scopes and slices
-#if 0
e = endswith(p, "/" SPECIAL_INIT_SCOPE);
if (!e)
e = endswith(p, "/" SPECIAL_SYSTEM_SLICE); /* legacy */
e = endswith(p, "/system"); /* even more legacy */
if (e)
*e = 0;
-#endif // 0
*path = p;
return 0;
+#else
+ assert(path);
+ return cg_pid_get_path(ELOGIND_CGROUP_CONTROLLER, 1, path);
+#endif // 0
}
int cg_shift_path(const char *cgroup, const char *root, const char **shifted) {
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;
}
+/// UNNEEDED by elogind
+#if 0
int cg_path_decode_unit(const char *cgroup, char **unit){
char *c, *s;
size_t n;
return cg_path_get_machine_name(cgroup, machine);
}
+#endif // 0
int cg_path_get_session(const char *path, char **session) {
+ /* Elogind uses a flat hierarchy, just "/SESSION". The only
+ wrinkle is that SESSION might be escaped. */
+#if 0
_cleanup_free_ char *unit = NULL;
char *start, *end;
int r;
*end = 0;
if (!session_id_valid(start))
return -ENXIO;
+#else
+ const char *e, *n, *start;
+
+ assert(path);
+ log_debug_elogind("path is \"%s\"", path);
+ assert(path[0] == '/');
+
+ e = path + 1;
+ n = strchrnul(e, '/');
+ if (e == n)
+ return -ENOENT;
+
+ start = strndupa(e, n - e);
+ start = cg_unescape(start);
+
+ if (!start[0])
+ return -ENOENT;
+#endif // 0
if (session) {
char *rr;
+ log_debug_elogind("found session: \"%s\"", start);
rr = strdup(start);
if (!rr)
return -ENOMEM;
return cg_path_get_session(cgroup, session);
}
+/// UNNEEDED by elogind
+#if 0
int cg_path_get_owner_uid(const char *path, uid_t *uid) {
_cleanup_free_ char *slice = NULL;
char *start, *end;
return cg_path_get_user_slice(cgroup, slice);
}
+#endif // 0
char *cg_escape(const char *p) {
bool need_prefix = false;