]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: convert to strequal()
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 13 Feb 2021 20:14:19 +0000 (21:14 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sat, 13 Feb 2021 20:14:19 +0000 (21:14 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfsng.c
src/lxc/cgroups/cgroup.c
src/lxc/cgroups/cgroup2_devices.c

index aff6bc8521fcb2251afddb33221b2847fac19845..ef2a82ba9c7e490cc9d4032a57564f47b8ce2326 100644 (file)
@@ -86,7 +86,7 @@ static bool string_in_list(char **list, const char *entry)
                return false;
 
        for (int i = 0; list[i]; i++)
-               if (strcmp(list[i], entry) == 0)
+               if (strequal(list[i], entry))
                        return true;
 
        return false;
@@ -167,12 +167,12 @@ static struct hierarchy *get_hierarchy(struct cgroup_ops *ops, const char *contr
                 * from cgroup to cgroup2.
                 */
                if (pure_unified_layout(ops)) {
-                       if (strcmp(controller, "devices") == 0) {
+                       if (strequal(controller, "devices")) {
                                if (ops->unified->bpf_device_controller)
                                        return ops->unified;
 
                                break;
-                       } else if (strcmp(controller, "freezer") == 0) {
+                       } else if (strequal(controller, "freezer")) {
                                if (ops->unified->freezer_controller)
                                        return ops->unified;
 
@@ -782,7 +782,7 @@ static bool controller_in_clist(char *cgline, char *c)
        tmp[len] = '\0';
 
        lxc_iterate_parts(tok, tmp, ",")
-               if (strcmp(tok, c) == 0)
+               if (strequal(tok, c))
                        return true;
 
        return false;
@@ -2619,12 +2619,12 @@ static int device_cgroup_rule_parse(struct device_item *device, const char *key,
        int count, ret;
        char temp[50];
 
-       if (strcmp("devices.allow", key) == 0)
+       if (strequal("devices.allow", key))
                device->allow = 1;
        else
                device->allow = 0;
 
-       if (strcmp(val, "a") == 0) {
+       if (strequal(val, "a")) {
                /* global rule */
                device->type = 'a';
                device->major = -1;
@@ -2723,7 +2723,7 @@ __cgfsng_ops static int cgfsng_set(struct cgroup_ops *ops,
        if (p)
                *p = '\0';
 
-       if (pure_unified_layout(ops) && strcmp(controller, "devices") == 0) {
+       if (pure_unified_layout(ops) && strequal(controller, "devices")) {
                struct device_item device = {};
 
                ret = device_cgroup_rule_parse(&device, key, value);
@@ -2863,7 +2863,7 @@ static int cg_legacy_set_data(struct cgroup_ops *ops, const char *filename,
        if (p)
                *p = '\0';
 
-       if (strcmp("devices.allow", filename) == 0 && value[0] == '/') {
+       if (strequal("devices.allow", filename) && value[0] == '/') {
                int ret;
 
                ret = convert_devpath(value, converted_value);
@@ -2953,7 +2953,7 @@ static int bpf_device_cgroup_prepare(struct cgroup_ops *ops,
        struct device_item device_item = {};
        int ret;
 
-       if (strcmp("devices.allow", key) == 0 && *val == '/')
+       if (strequal("devices.allow", key) && *val == '/')
                ret = device_cgroup_rule_parse_devpath(&device_item, val);
        else
                ret = device_cgroup_rule_parse(&device_item, key, val);
@@ -3191,7 +3191,7 @@ static bool cgroup_use_wants_controllers(const struct cgroup_ops *ops,
                bool found = false;
 
                for (char **cur_use = ops->cgroup_use; cur_use && *cur_use; cur_use++) {
-                       if (strcmp(*cur_use, *cur_ctrl) != 0)
+                       if (!strequal(*cur_use, *cur_ctrl))
                                continue;
 
                        found = true;
@@ -3229,7 +3229,7 @@ static void cg_unified_delegate(char ***delegate)
                 * We always need to chown this for both cgroup and
                 * cgroup2.
                 */
-               if (strcmp(token, "cgroup.procs") == 0)
+               if (strequal(token, "cgroup.procs"))
                        continue;
 
                idx = append_null_to_list((void ***)delegate);
@@ -3504,7 +3504,7 @@ __cgfsng_ops static int cgfsng_data_init(struct cgroup_ops *ops)
 
        /* copy system-wide cgroup information */
        cgroup_pattern = lxc_global_config_value("lxc.cgroup.pattern");
-       if (cgroup_pattern && strcmp(cgroup_pattern, "") != 0)
+       if (cgroup_pattern && !strequal(cgroup_pattern, ""))
                ops->cgroup_pattern = must_copy_string(cgroup_pattern);
 
        return 0;
index 6a46fb651f15eb68342eb2ab3d261c7118a2ebaf..acfda8af3cb88bead183064db6a1280b13b9a702 100644 (file)
@@ -16,6 +16,7 @@
 #include "initutils.h"
 #include "log.h"
 #include "start.h"
+#include "string_utils.h"
 
 lxc_log_define(cgroup, lxc);
 
@@ -105,7 +106,7 @@ void prune_init_scope(char *cg)
        if (point < cg)
                return;
 
-       if (strcmp(point, INIT_SCOPE) == 0) {
+       if (strequal(point, INIT_SCOPE)) {
                if (point == cg)
                        *(point + 1) = '\0';
                else
index faee4cc5359c0c7b39fcd80d74bc72e624f2c327..31e75485347775691c6d48383a157310b75bad7b 100644 (file)
@@ -493,7 +493,7 @@ int bpf_list_add_device(struct lxc_conf *conf, struct device_item *device)
                        continue;
                if (cur->minor != device->minor)
                        continue;
-               if (strcmp(cur->access, device->access))
+               if (!strequal(cur->access, device->access))
                        continue;
 
                /*