cgroup-util: don't expect cg_mask_from_string()'s return value to be initialized

Also, when we fail, don't clobber the return value.

This brings the call more in-line with our usual coding style, and
removes surprises.

None of the callers seemed to care about this behaviour.
This commit is contained in:
Lennart Poettering 2018-10-24 17:25:51 +02:00
parent 0887fa711c
commit 38a90d45ad
1 changed files with 9 additions and 4 deletions

View File

@ -2303,8 +2303,10 @@ int cg_mask_to_string(CGroupMask mask, char **ret) {
return 0;
}
int cg_mask_from_string(const char *value, CGroupMask *mask) {
assert(mask);
int cg_mask_from_string(const char *value, CGroupMask *ret) {
CGroupMask m = 0;
assert(ret);
assert(value);
for (;;) {
@ -2322,13 +2324,15 @@ int cg_mask_from_string(const char *value, CGroupMask *mask) {
if (v < 0)
continue;
*mask |= CGROUP_CONTROLLER_TO_MASK(v);
m |= CGROUP_CONTROLLER_TO_MASK(v);
}
*ret = m;
return 0;
}
int cg_mask_supported(CGroupMask *ret) {
CGroupMask mask = 0;
CGroupMask mask;
int r;
/* Determines the mask of supported cgroup controllers. Only
@ -2372,6 +2376,7 @@ int cg_mask_supported(CGroupMask *ret) {
/* In the legacy hierarchy, we check whether which
* hierarchies are mounted. */
mask = 0;
for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
const char *n;