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:
+14
-3
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user