chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
cg_shift_path(): Do not shift if cgroup and root are equal
[elogind.git]
/
src
/
basic
/
cgroup-util.c
diff --git
a/src/basic/cgroup-util.c
b/src/basic/cgroup-util.c
index cd5db6f69c1ab46ed94efdb01bc43a12217a6766..f7a892380a7e4975dd439ca22e0470e251ca6c70 100644
(file)
--- a/
src/basic/cgroup-util.c
+++ b/
src/basic/cgroup-util.c
@@
-297,6
+297,10
@@
int cg_migrate(const char *cfrom, const char *pfrom, const char *cto, const char
my_pid = getpid();
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;
do {
_cleanup_fclose_ FILE *f = NULL;
pid_t pid = 0;
@@
-570,7
+574,7
@@
static int controller_is_accessible(const char *controller) {
* the unified hierarchy. */
if (streq(controller, ELOGIND_CGROUP_CONTROLLER))
* the unified hierarchy. */
if (streq(controller, ELOGIND_CGROUP_CONTROLLER))
- return 0;
+
return 0;
if (startswith(controller, "name="))
return -EOPNOTSUPP;
if (startswith(controller, "name="))
return -EOPNOTSUPP;
@@
-581,8
+585,8
@@
static int controller_is_accessible(const char *controller) {
dn = controller_to_dirname(controller);
cc = strjoina("/sys/fs/cgroup/", dn);
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;
}
return 0;
@@
-811,11
+815,11
@@
int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
if (unified < 0)
return unified;
if (unified == 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);
}
cs = strlen(controller);
}
@@
-840,29
+844,29
@@
int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
continue;
} else {
char *l;
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);
}
p = strdup(e + 1);
@@
-1199,10
+1203,11
@@
int cg_shift_path(const char *cgroup, const char *root, const char **shifted) {
return r;
root = rt;
return r;
root = rt;
+ log_debug_elogind("Determined root path: \"%s\"", root);
}
p = path_startswith(cgroup, root);
}
p = path_startswith(cgroup, root);
- if (p && p
> cgroup
)
+ if (p && p
[0] && (p > cgroup)
)
*shifted = p - 1;
else
*shifted = cgroup;
*shifted = p - 1;
else
*shifted = cgroup;
@@
-1222,6
+1227,8
@@
int cg_pid_get_path_shifted(pid_t pid, const char *root, char **cgroup) {
if (r < 0)
return r;
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;
r = cg_shift_path(raw, root, &c);
if (r < 0)
return r;
@@
-1238,6
+1245,7
@@
int cg_pid_get_path_shifted(pid_t pid, const char *root, char **cgroup) {
*cgroup = n;
}
*cgroup = n;
}
+ log_debug_elogind("Resulting cgroup:\"%s\"", *cgroup);
return 0;
}
return 0;
}
@@
-1522,6
+1530,7
@@
int cg_path_get_session(const char *path, char **session) {
const char *e, *n, *start;
assert(path);
const char *e, *n, *start;
assert(path);
+ log_debug_elogind("path is \"%s\"", path);
assert(path[0] == '/');
e = path + 1;
assert(path[0] == '/');
e = path + 1;
@@
-1539,6
+1548,7
@@
int cg_path_get_session(const char *path, char **session) {
if (session) {
char *rr;
if (session) {
char *rr;
+ log_debug_elogind("found session: \"%s\"", start);
rr = strdup(start);
if (!rr)
return -ENOMEM;
rr = strdup(start);
if (!rr)
return -ENOMEM;