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-21 11:54:08 +01:00
parent bf516294c8
commit 6925a0de4e
4 changed files with 17 additions and 14 deletions
+14 -3
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;
}
+1 -1
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);