cgroup-util: move Set* allocation into cg_kernel_controllers()

Previously, callers had to do this on their own. Let's make the call do
that instead, making the caller code a bit shorter.
This commit is contained in:
Lennart Poettering 2017-11-17 16:27:13 +01:00
parent bf516294c8
commit 6925a0de4e
4 changed files with 17 additions and 14 deletions

View File

@ -2369,21 +2369,29 @@ int cg_mask_supported(CGroupMask *ret) {
return 0;
}
int cg_kernel_controllers(Set *controllers) {
int cg_kernel_controllers(Set **ret) {
_cleanup_set_free_free_ Set *controllers = NULL;
_cleanup_fclose_ FILE *f = NULL;
int r;
assert(controllers);
assert(ret);
/* Determines the full list of kernel-known controllers. Might
* include controllers we don't actually support, arbitrary
* named hierarchies and controllers that aren't currently
* accessible (because not mounted). */
controllers = set_new(&string_hash_ops);
if (!controllers)
return -ENOMEM;
f = fopen("/proc/cgroups", "re");
if (!f) {
if (errno == ENOENT)
if (errno == ENOENT) {
*ret = NULL;
return 0;
}
return -errno;
}
@ -2421,6 +2429,9 @@ int cg_kernel_controllers(Set *controllers) {
return r;
}
*ret = controllers;
controllers = NULL;
return 0;
}

View File

@ -243,7 +243,7 @@ int cg_mask_supported(CGroupMask *ret);
int cg_mask_from_string(const char *s, CGroupMask *ret);
int cg_mask_to_string(CGroupMask mask, char **ret);
int cg_kernel_controllers(Set *controllers);
int cg_kernel_controllers(Set **controllers);
bool cg_ns_supported(void);

View File

@ -237,11 +237,7 @@ int mount_cgroup_controllers(char ***join_controllers) {
/* Mount all available cgroup controllers that are built into the kernel. */
controllers = set_new(&string_hash_ops);
if (!controllers)
return log_oom();
r = cg_kernel_controllers(controllers);
r = cg_kernel_controllers(&controllers);
if (r < 0)
return log_error_errno(r, "Failed to enumerate cgroup controllers: %m");

View File

@ -1111,11 +1111,7 @@ static int mount_legacy_cgns_unsupported(
if (r > 0)
goto skip_controllers;
controllers = set_new(&string_hash_ops);
if (!controllers)
return log_oom();
r = cg_kernel_controllers(controllers);
r = cg_kernel_controllers(&controllers);
if (r < 0)
return log_error_errno(r, "Failed to determine cgroup controllers: %m");