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:
parent
bf516294c8
commit
6925a0de4e
|
@ -2369,21 +2369,29 @@ int cg_mask_supported(CGroupMask *ret) {
|
||||||
return 0;
|
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;
|
_cleanup_fclose_ FILE *f = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(controllers);
|
assert(ret);
|
||||||
|
|
||||||
/* Determines the full list of kernel-known controllers. Might
|
/* Determines the full list of kernel-known controllers. Might
|
||||||
* include controllers we don't actually support, arbitrary
|
* include controllers we don't actually support, arbitrary
|
||||||
* named hierarchies and controllers that aren't currently
|
* named hierarchies and controllers that aren't currently
|
||||||
* accessible (because not mounted). */
|
* accessible (because not mounted). */
|
||||||
|
|
||||||
|
controllers = set_new(&string_hash_ops);
|
||||||
|
if (!controllers)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
f = fopen("/proc/cgroups", "re");
|
f = fopen("/proc/cgroups", "re");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT) {
|
||||||
|
*ret = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2421,6 +2429,9 @@ int cg_kernel_controllers(Set *controllers) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*ret = controllers;
|
||||||
|
controllers = NULL;
|
||||||
|
|
||||||
return 0;
|
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_from_string(const char *s, CGroupMask *ret);
|
||||||
int cg_mask_to_string(CGroupMask mask, char **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);
|
bool cg_ns_supported(void);
|
||||||
|
|
||||||
|
|
|
@ -237,11 +237,7 @@ int mount_cgroup_controllers(char ***join_controllers) {
|
||||||
|
|
||||||
/* Mount all available cgroup controllers that are built into the kernel. */
|
/* Mount all available cgroup controllers that are built into the kernel. */
|
||||||
|
|
||||||
controllers = set_new(&string_hash_ops);
|
r = cg_kernel_controllers(&controllers);
|
||||||
if (!controllers)
|
|
||||||
return log_oom();
|
|
||||||
|
|
||||||
r = cg_kernel_controllers(controllers);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to enumerate cgroup controllers: %m");
|
return log_error_errno(r, "Failed to enumerate cgroup controllers: %m");
|
||||||
|
|
||||||
|
|
|
@ -1111,11 +1111,7 @@ static int mount_legacy_cgns_unsupported(
|
||||||
if (r > 0)
|
if (r > 0)
|
||||||
goto skip_controllers;
|
goto skip_controllers;
|
||||||
|
|
||||||
controllers = set_new(&string_hash_ops);
|
r = cg_kernel_controllers(&controllers);
|
||||||
if (!controllers)
|
|
||||||
return log_oom();
|
|
||||||
|
|
||||||
r = cg_kernel_controllers(controllers);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to determine cgroup controllers: %m");
|
return log_error_errno(r, "Failed to determine cgroup controllers: %m");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue