]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup-util: don't expect cg_mask_from_string()'s return value to be initialized
authorLennart Poettering <lennart@poettering.net>
Wed, 24 Oct 2018 15:25:51 +0000 (17:25 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 26 Oct 2018 16:43:34 +0000 (18:43 +0200)
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.

src/basic/cgroup-util.c

index 65ca6f2f504b81a471bf3ef43ea179a968a52192..d2e8ef0c072317ae6573d6531e8ce2e92e8c0ada 100644 (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;