1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-02-26 09:57:26 +03:00

nspawn-mount: rework get_controllers() a bit

Let's rename get_controllers() → get_process_controllers(), in order to
underline the difference to cg_kernel_controllers(). After all, one
returns the controllers available to the process, the other the
controllers enabled in the kernel at all).

Let's also update the code to use read_line() and set_put_strdup() to
shorten the code a bit, and make it more robust.
This commit is contained in:
Lennart Poettering 2017-11-17 13:35:56 +01:00
parent ea9053c5f8
commit d7c9693a3e

View File

@ -867,19 +867,30 @@ int mount_custom(
/* Retrieve existing subsystems. This function is called in a new cgroup
* namespace.
*/
static int get_controllers(Set *subsystems) {
static int get_process_controllers(Set **ret) {
_cleanup_set_free_free_ Set *controllers = NULL;
_cleanup_fclose_ FILE *f = NULL;
char line[LINE_MAX];
int r;
assert(subsystems);
assert(ret);
controllers = set_new(&string_hash_ops);
if (!controllers)
return -ENOMEM;
f = fopen("/proc/self/cgroup", "re");
if (!f)
return errno == ENOENT ? -ESRCH : -errno;
FOREACH_LINE(line, f, return -errno) {
int r;
char *e, *l, *p;
for (;;) {
_cleanup_free_ char *line = NULL;
char *e, *l;
r = read_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0)
break;
l = strchr(line, ':');
if (!l)
@ -895,15 +906,14 @@ static int get_controllers(Set *subsystems) {
if (STR_IN_SET(l, "", "name=systemd", "name=unified"))
continue;
p = strdup(l);
if (!p)
return -ENOMEM;
r = set_consume(subsystems, p);
r = set_put_strdup(controllers, l);
if (r < 0)
return r;
}
*ret = controllers;
controllers = NULL;
return 0;
}
@ -999,11 +1009,7 @@ static int mount_legacy_cgns_supported(
if (r > 0)
goto skip_controllers;
controllers = set_new(&string_hash_ops);
if (!controllers)
return log_oom();
r = get_controllers(controllers);
r = get_process_controllers(&controllers);
if (r < 0)
return log_error_errno(r, "Failed to determine cgroup controllers: %m");