summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-09-22 18:25:45 +0200
committerSven Eden <yamakuzure@gmx.net>2017-09-25 14:40:38 +0200
commit0fa84e5e28182901ddf8d7d8a76372b07ed05b07 (patch)
tree5a4de3e30ffd1b7d95253a20cd90a69bc6f7babc
parenta16ec69cb4f6e63a2d9e20e7c5e27174049f1de5 (diff)
cgroup-util: replace one use of fgets() by read_line()
-rw-r--r--src/basic/cgroup-util.c47
1 files changed, 8 insertions, 39 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
index 7d64c6a2b..7c8f5e29f 100644
--- a/src/basic/cgroup-util.c
+++ b/src/basic/cgroup-util.c
@@ -909,7 +909,7 @@ int cg_set_group_access(
if (r > 0 && streq(controller, SYSTEMD_CGROUP_CONTROLLER)) {
r = cg_set_group_access(SYSTEMD_CGROUP_CONTROLLER_LEGACY, path, mode, uid, gid);
if (r < 0)
- log_debug_errno(r, "Failed to set group access on compatibility systemd cgroup %s, ignoring: %m", path);
+ log_warning_errno(r, "Failed to set group access on compat systemd cgroup %s: %m", path);
}
return 0;
@@ -922,7 +922,7 @@ int cg_set_task_access(
uid_t uid,
gid_t gid) {
- _cleanup_free_ char *fs = NULL;
+ _cleanup_free_ char *fs = NULL, *procs = NULL;
int r;
assert(path);
@@ -933,7 +933,6 @@ int cg_set_task_access(
if (mode != MODE_INVALID)
mode &= 0666;
- /* For both the legacy and unified hierarchies, "cgroup.procs" is the main entry point for PIDs */
r = cg_get_path(controller, path, "cgroup.procs", &fs);
if (r < 0)
return r;
@@ -946,48 +945,19 @@ int cg_set_task_access(
if (r < 0)
return r;
if (r == 0) {
- const char *fn;
-
- /* Compatibility: on cgroupsv1 always keep values for the legacy files "tasks" and
- * "cgroup.clone_children" in sync with "cgroup.procs". Since this is legacy stuff, we don't care if
- * this fails. */
-
- FOREACH_STRING(fn,
- "tasks",
- "cgroup.clone_children") {
-
- fs = mfree(fs);
-
- r = cg_get_path(controller, path, fn, &fs);
- if (r < 0)
- log_debug_errno(r, "Failed to get path for %s of %s, ignoring: %m", fn, path);
-
- r = chmod_and_chown(fs, mode, uid, gid);
- if (r < 0)
- log_debug_errno(r, "Failed to to change ownership/access mode for %s of %s, ignoring: %m", fn, path);
- }
- } else {
- /* On the unified controller, we want to permit subtree controllers too. */
-
- fs = mfree(fs);
- r = cg_get_path(controller, path, "cgroup.subtree_control", &fs);
- if (r < 0)
- return r;
-
- r = chmod_and_chown(fs, mode, uid, gid);
- if (r < 0)
- return r;
+ /* Compatibility, Always keep values for "tasks" in sync with
+ * "cgroup.procs" */
+ if (cg_get_path(controller, path, "tasks", &procs) >= 0)
+ (void) chmod_and_chown(procs, mode, uid, gid);
}
r = cg_hybrid_unified();
if (r < 0)
return r;
if (r > 0 && streq(controller, SYSTEMD_CGROUP_CONTROLLER)) {
- /* Always propagate access mode from unified to legacy controller */
-
r = cg_set_task_access(SYSTEMD_CGROUP_CONTROLLER_LEGACY, path, mode, uid, gid);
if (r < 0)
- log_debug_errno(r, "Failed to set task access on compatibility systemd cgroup %s, ignoring: %m", path);
+ log_warning_errno(r, "Failed to set task access on compat systemd cgroup %s: %m", path);
}
return 0;
@@ -2412,7 +2382,6 @@ int cg_mask_supported(CGroupMask *ret) {
#if 0 /// UNNEEDED by elogind
int cg_kernel_controllers(Set *controllers) {
_cleanup_fclose_ FILE *f = NULL;
- char buf[LINE_MAX];
int r;
assert(controllers);
@@ -2430,7 +2399,7 @@ int cg_kernel_controllers(Set *controllers) {
}
/* Ignore the header line */
- (void) fgets(buf, sizeof(buf), f);
+ (void) read_line(f, (size_t) -1, NULL);
for (;;) {
char *controller;