From: Christian Brauner Date: Sat, 13 Feb 2021 20:20:26 +0000 (+0100) Subject: confile: convert to strequal() X-Git-Tag: lxc-5.0.0~290^2~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d62177e99a5cc8a045d677a7e32d2f1eb863350f;p=thirdparty%2Flxc.git confile: convert to strequal() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/confile.c b/src/lxc/confile.c index d9ed32ba0..42889d5a8 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -287,7 +287,7 @@ struct lxc_config_t *lxc_get_config_exact(const char *key) size_t i; for (i = 0; i < config_jump_table_size; i++) - if (!strcmp(config_jump_table[i].name, key)) + if (strequal(config_jump_table[i].name, key)) return &config_jump_table[i]; return NULL; @@ -327,30 +327,30 @@ static int set_config_net_type(const char *key, const char *value, if (!netdev) return ret_errno(EINVAL); - if (strcmp(value, "veth") == 0) { + if (strequal(value, "veth")) { netdev->type = LXC_NET_VETH; lxc_list_init(&netdev->priv.veth_attr.ipv4_routes); lxc_list_init(&netdev->priv.veth_attr.ipv6_routes); lxc_list_init(&netdev->priv.veth_attr.vlan_tagged_ids); if (!lxc_veth_flag_to_mode(netdev->priv.veth_attr.mode)) lxc_veth_mode_to_flag(&netdev->priv.veth_attr.mode, "bridge"); - } else if (strcmp(value, "macvlan") == 0) { + } else if (strequal(value, "macvlan")) { netdev->type = LXC_NET_MACVLAN; if (!lxc_macvlan_flag_to_mode(netdev->priv.veth_attr.mode)) lxc_macvlan_mode_to_flag(&netdev->priv.macvlan_attr.mode, "private"); - } else if (strcmp(value, "ipvlan") == 0) { + } else if (strequal(value, "ipvlan")) { netdev->type = LXC_NET_IPVLAN; if (!lxc_ipvlan_flag_to_mode(netdev->priv.ipvlan_attr.mode)) lxc_ipvlan_mode_to_flag(&netdev->priv.ipvlan_attr.mode, "l3"); if (!lxc_ipvlan_flag_to_isolation(netdev->priv.ipvlan_attr.isolation)) lxc_ipvlan_isolation_to_flag(&netdev->priv.ipvlan_attr.isolation, "bridge"); - } else if (strcmp(value, "vlan") == 0) { + } else if (strequal(value, "vlan")) { netdev->type = LXC_NET_VLAN; - } else if (strcmp(value, "phys") == 0) { + } else if (strequal(value, "phys")) { netdev->type = LXC_NET_PHYS; - } else if (strcmp(value, "empty") == 0) { + } else if (strequal(value, "empty")) { netdev->type = LXC_NET_EMPTY; - } else if (strcmp(value, "none") == 0) { + } else if (strequal(value, "none")) { netdev->type = LXC_NET_NONE; } else { return log_error(-1, "Invalid network type %s", value); @@ -521,7 +521,7 @@ static int set_config_net_veth_vlan_id(const char *key, const char *value, if (lxc_config_value_empty(value)) return clr_config_net_veth_vlan_id(key, lxc_conf, data); - if (strcmp(value, "none") == 0) { + if (strequal(value, "none")) { netdev->priv.veth_attr.vlan_id = BRIDGE_VLAN_NONE; } else { unsigned short vlan_id; @@ -779,10 +779,10 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value, free(netdev->ipv4_gateway); - if (strcmp(value, "auto") == 0) { + if (strequal(value, "auto")) { netdev->ipv4_gateway = NULL; netdev->ipv4_gateway_auto = true; - } else if (strcmp(value, "dev") == 0) { + } else if (strequal(value, "dev")) { netdev->ipv4_gateway = NULL; netdev->ipv4_gateway_auto = false; netdev->ipv4_gateway_dev = true; @@ -935,10 +935,10 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value, free(netdev->ipv6_gateway); - if (strcmp(value, "auto") == 0) { + if (strequal(value, "auto")) { netdev->ipv6_gateway = NULL; netdev->ipv6_gateway_auto = true; - } else if (strcmp(value, "dev") == 0) { + } else if (strequal(value, "dev")) { netdev->ipv6_gateway = NULL; netdev->ipv6_gateway_auto = false; netdev->ipv6_gateway_dev = true; @@ -1246,32 +1246,32 @@ static int set_config_hooks(const char *key, const char *value, if (lxc_config_value_empty(value)) return lxc_clear_hooks(lxc_conf, key); - if (strcmp(key + 4, "hook") == 0) + if (strequal(key + 4, "hook")) return log_error_errno(-EINVAL, EINVAL, "lxc.hook must not have a value"); copy = strdup(value); if (!copy) return ret_errno(ENOMEM); - if (strcmp(key + 9, "pre-start") == 0) + if (strequal(key + 9, "pre-start")) return add_hook(lxc_conf, LXCHOOK_PRESTART, move_ptr(copy)); - else if (strcmp(key + 9, "start-host") == 0) + else if (strequal(key + 9, "start-host")) return add_hook(lxc_conf, LXCHOOK_START_HOST, move_ptr(copy)); - else if (strcmp(key + 9, "pre-mount") == 0) + else if (strequal(key + 9, "pre-mount")) return add_hook(lxc_conf, LXCHOOK_PREMOUNT, move_ptr(copy)); - else if (strcmp(key + 9, "autodev") == 0) + else if (strequal(key + 9, "autodev")) return add_hook(lxc_conf, LXCHOOK_AUTODEV, move_ptr(copy)); - else if (strcmp(key + 9, "mount") == 0) + else if (strequal(key + 9, "mount")) return add_hook(lxc_conf, LXCHOOK_MOUNT, move_ptr(copy)); - else if (strcmp(key + 9, "start") == 0) + else if (strequal(key + 9, "start")) return add_hook(lxc_conf, LXCHOOK_START, move_ptr(copy)); - else if (strcmp(key + 9, "stop") == 0) + else if (strequal(key + 9, "stop")) return add_hook(lxc_conf, LXCHOOK_STOP, move_ptr(copy)); - else if (strcmp(key + 9, "post-stop") == 0) + else if (strequal(key + 9, "post-stop")) return add_hook(lxc_conf, LXCHOOK_POSTSTOP, move_ptr(copy)); - else if (strcmp(key + 9, "clone") == 0) + else if (strequal(key + 9, "clone")) return add_hook(lxc_conf, LXCHOOK_CLONE, move_ptr(copy)); - else if (strcmp(key + 9, "destroy") == 0) + else if (strequal(key + 9, "destroy")) return add_hook(lxc_conf, LXCHOOK_DESTROY, move_ptr(copy)); return ret_errno(EINVAL); @@ -1387,7 +1387,7 @@ static int set_config_monitor(const char *key, const char *value, return 0; } - if (strcmp(key + 12, "unshare") == 0) + if (strequal(key + 12, "unshare")) return lxc_safe_uint(value, &lxc_conf->monitor_unshare); return ret_errno(EINVAL); @@ -1401,7 +1401,7 @@ static int set_config_monitor_signal_pdeath(const char *key, const char *value, return 0; } - if (strcmp(key + 12, "signal.pdeath") == 0) { + if (strequal(key + 12, "signal.pdeath")) { int sig_n; sig_n = sig_parse(value); @@ -1819,7 +1819,7 @@ static int set_config_cgroup2_controller(const char *key, const char *value, static int set_config_cgroup_dir(const char *key, const char *value, struct lxc_conf *lxc_conf, void *data) { - if (strcmp(key, "lxc.cgroup.dir") != 0) + if (!strequal(key, "lxc.cgroup.dir")) return ret_errno(EINVAL); if (lxc_config_value_empty(value)) @@ -1867,9 +1867,7 @@ static int set_config_cgroup_container_inner_dir(const char *key, if (lxc_config_value_empty(value)) return clr_config_cgroup_container_inner_dir(key, lxc_conf, NULL); - if (strchr(value, '/') || - strcmp(value, ".") == 0 || - strcmp(value, "..") == 0) + if (strchr(value, '/') || strequal(value, ".") || strequal(value, "..")) return log_error_errno(-EINVAL, EINVAL, "lxc.cgroup.dir.container.inner must be a single directory name"); return set_config_string_item(&lxc_conf->cgroup_meta.namespace_dir, value); @@ -1977,7 +1975,7 @@ static int set_config_prlimit(const char *key, const char *value, /* find existing list element */ lxc_list_for_each(iter, &lxc_conf->limits) { limelem = iter->elem; - if (!strcmp(key, limelem->resource)) { + if (strequal(key, limelem->resource)) { limelem->limit = limit; return 0; } @@ -2025,7 +2023,7 @@ static int set_config_sysctl(const char *key, const char *value, sysctl_elem = iter->elem; - if (strcmp(key, sysctl_elem->key) != 0) + if (!strequal(key, sysctl_elem->key)) continue; replace_value = strdup(value); @@ -2222,10 +2220,10 @@ static int set_config_mount_auto(const char *key, const char *value, bool is_shmounts = false; for (i = 0; allowed_auto_mounts[i].token; i++) { - if (!strcmp(allowed_auto_mounts[i].token, token)) + if (strequal(allowed_auto_mounts[i].token, token)) break; - if (strcmp("shmounts:", allowed_auto_mounts[i].token) == 0 && + if (strequal("shmounts:", allowed_auto_mounts[i].token) && strncmp("shmounts:", token, STRLITERALLEN("shmounts:")) == 0) { is_shmounts = true; break; @@ -2313,7 +2311,7 @@ static int set_config_cap_keep(const char *key, const char *value, * split these caps in a single element for the list. */ lxc_iterate_parts(token, keepcaps, " \t") { - if (!strcmp(token, "none")) + if (strequal(token, "none")) lxc_clear_config_keepcaps(lxc_conf); keeplist = malloc(sizeof(*keeplist)); @@ -2407,7 +2405,7 @@ static int set_config_console_buffer_size(const char *key, const char *value, } /* If the user specified "auto" the default log size is 2^17 = 128 Kib */ - if (!strcmp(value, "auto")) { + if (strequal(value, "auto")) { lxc_conf->console.buffer_size = 1 << 17; return 0; } @@ -2452,7 +2450,7 @@ static int set_config_console_size(const char *key, const char *value, } /* If the user specified "auto" the default log size is 2^17 = 128 Kib */ - if (!strcmp(value, "auto")) { + if (strequal(value, "auto")) { lxc_conf->console.log_size = 1 << 17; return 0; } @@ -2564,10 +2562,10 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf) char path[PATH_MAX]; fnam = direntp->d_name; - if (!strcmp(fnam, ".")) + if (strequal(fnam, ".")) continue; - if (!strcmp(fnam, "..")) + if (strequal(fnam, "..")) continue; len = strlen(fnam); @@ -2776,21 +2774,21 @@ static int set_config_time_offset_boot(const char *key, const char *value, return ret; unit = lxc_trim_whitespace_in_place(buf); - if (strcmp(unit, "h") == 0) { + if (strequal(unit, "h")) { if (!multiply_overflow(offset, 3600, &lxc_conf->timens.s_boot)) return ret_errno(EOVERFLOW); - } else if (strcmp(unit, "m") == 0) { + } else if (strequal(unit, "m")) { if (!multiply_overflow(offset, 60, &lxc_conf->timens.s_boot)) return ret_errno(EOVERFLOW); - } else if (strcmp(unit, "s") == 0) { + } else if (strequal(unit, "s")) { lxc_conf->timens.s_boot = offset; - } else if (strcmp(unit, "ms") == 0) { + } else if (strequal(unit, "ms")) { if (!multiply_overflow(offset, 1000000, &lxc_conf->timens.ns_boot)) return ret_errno(EOVERFLOW); - } else if (strcmp(unit, "us") == 0) { + } else if (strequal(unit, "us")) { if (!multiply_overflow(offset, 1000, &lxc_conf->timens.ns_boot)) return ret_errno(EOVERFLOW); - } else if (strcmp(unit, "ns") == 0) { + } else if (strequal(unit, "ns")) { lxc_conf->timens.ns_boot = offset; } else { return ret_errno(EINVAL); @@ -2815,21 +2813,21 @@ static int set_config_time_offset_monotonic(const char *key, const char *value, return ret; unit = lxc_trim_whitespace_in_place(buf); - if (strcmp(unit, "h") == 0) { + if (strequal(unit, "h")) { if (!multiply_overflow(offset, 3600, &lxc_conf->timens.s_monotonic)) return ret_errno(EOVERFLOW); - } else if (strcmp(unit, "m") == 0) { + } else if (strequal(unit, "m")) { if (!multiply_overflow(offset, 60, &lxc_conf->timens.s_monotonic)) return ret_errno(EOVERFLOW); - } else if (strcmp(unit, "s") == 0) { + } else if (strequal(unit, "s")) { lxc_conf->timens.s_monotonic = offset; - } else if (strcmp(unit, "ms") == 0) { + } else if (strequal(unit, "ms")) { if (!multiply_overflow(offset, 1000000, &lxc_conf->timens.ns_monotonic)) return ret_errno(EOVERFLOW); - } else if (strcmp(unit, "us") == 0) { + } else if (strequal(unit, "us")) { if (!multiply_overflow(offset, 1000, &lxc_conf->timens.ns_monotonic)) return ret_errno(EOVERFLOW); - } else if (strcmp(unit, "ns") == 0) { + } else if (strequal(unit, "ns")) { lxc_conf->timens.ns_monotonic = offset; } else { return ret_errno(EINVAL); @@ -3087,7 +3085,7 @@ signed long lxc_config_parse_arch(const char *arch) size_t len = sizeof(pername) / sizeof(pername[0]); for (int i = 0; i < len; i++) - if (!strcmp(pername[i].name, arch)) + if (strequal(pername[i].name, arch)) return pername[i].per; #endif @@ -3122,7 +3120,7 @@ int lxc_fill_elevated_privileges(char *flaglist, int *flags) aflag = -1; for (i = 0; all_privs[i].token; i++) - if (!strcmp(all_privs[i].token, token)) + if (strequal(all_privs[i].token, token)) aflag = all_privs[i].flag; if (aflag < 0) @@ -3705,7 +3703,7 @@ static int __get_config_cgroup_controller(const char *key, char *retv, return ret_errno(EINVAL); } - if (strcmp(key, global_token) == 0) + if (strequal(key, global_token)) get_all = true; else if (strncmp(key, namespaced_token, namespaced_token_len) == 0) key += namespaced_token_len; @@ -3721,7 +3719,7 @@ static int __get_config_cgroup_controller(const char *key, char *retv, strprint(retv, inlen, "%s.%s = %s\n", global_token, cg->subsystem, cg->value); - } else if (strcmp(cg->subsystem, key) == 0) { + } else if (strequal(cg->subsystem, key)) { strprint(retv, inlen, "%s\n", cg->value); } } @@ -3749,7 +3747,7 @@ static int get_config_cgroup_dir(const char *key, char *retv, int inlen, int len; int fulllen = 0; - if (strcmp(key, "lxc.cgroup.dir") != 0) + if (!strequal(key, "lxc.cgroup.dir")) return ret_errno(EINVAL); if (!retv) @@ -4053,7 +4051,7 @@ static int get_config_hooks(const char *key, char *retv, int inlen, return ret_errno(EINVAL); for (i = 0; i < NUM_LXC_HOOKS; i++) { - if (strcmp(lxchook_names[i], subkey) == 0) { + if (strequal(lxchook_names[i], subkey)) { found = i; break; } @@ -4241,11 +4239,11 @@ static int get_config_signal_stop(const char *key, char *retv, int inlen, static int get_config_start(const char *key, char *retv, int inlen, struct lxc_conf *c, void *data) { - if (strcmp(key + 10, "auto") == 0) + if (strequal(key + 10, "auto")) return lxc_get_conf_int(c, retv, inlen, c->start_auto); - else if (strcmp(key + 10, "delay") == 0) + else if (strequal(key + 10, "delay")) return lxc_get_conf_int(c, retv, inlen, c->start_delay); - else if (strcmp(key + 10, "order") == 0) + else if (strequal(key + 10, "order")) return lxc_get_conf_int(c, retv, inlen, c->start_order); return -1; @@ -4384,7 +4382,7 @@ static int get_config_prlimit(const char *key, char *retv, int inlen, else memset(retv, 0, inlen); - if (!strcmp(key, "lxc.prlimit")) + if (strequal(key, "lxc.prlimit")) get_all = true; else if (strncmp(key, "lxc.prlimit.", 12) == 0) key += 12; @@ -4417,7 +4415,7 @@ static int get_config_prlimit(const char *key, char *retv, int inlen, if (get_all) { strprint(retv, inlen, "lxc.prlimit.%s = %s\n", lim->resource, buf); - } else if (strcmp(lim->resource, key) == 0) { + } else if (strequal(lim->resource, key)) { strprint(retv, inlen, "%s", buf); } } @@ -4442,7 +4440,7 @@ static int get_config_sysctl(const char *key, char *retv, int inlen, else memset(retv, 0, inlen); - if (strcmp(key, "lxc.sysctl") == 0) + if (strequal(key, "lxc.sysctl")) get_all = true; else if (strncmp(key, "lxc.sysctl.", STRLITERALLEN("lxc.sysctl.")) == 0) key += STRLITERALLEN("lxc.sysctl."); @@ -4454,7 +4452,7 @@ static int get_config_sysctl(const char *key, char *retv, int inlen, if (get_all) { strprint(retv, inlen, "lxc.sysctl.%s = %s\n", elem->key, elem->value); - } else if (strcmp(elem->key, key) == 0) { + } else if (strequal(elem->key, key)) { strprint(retv, inlen, "%s", elem->value); } } @@ -4475,7 +4473,7 @@ static int get_config_proc(const char *key, char *retv, int inlen, else memset(retv, 0, inlen); - if (strcmp(key, "lxc.proc") == 0) + if (strequal(key, "lxc.proc")) get_all = true; else if (strncmp(key, "lxc.proc.", STRLITERALLEN("lxc.proc.")) == 0) key += STRLITERALLEN("lxc.proc."); @@ -4488,7 +4486,7 @@ static int get_config_proc(const char *key, char *retv, int inlen, if (get_all) { strprint(retv, inlen, "lxc.proc.%s = %s\n", proc->filename, proc->value); - } else if (strcmp(proc->filename, key) == 0) { + } else if (strequal(proc->filename, key)) { strprint(retv, inlen, "%s", proc->value); } } @@ -4691,7 +4689,7 @@ static inline int clr_config_cgroup2_controller(const char *key, static int clr_config_cgroup_dir(const char *key, struct lxc_conf *lxc_conf, void *data) { - if (strcmp(key, "lxc.cgroup.dir") != 0) + if (!strequal(key, "lxc.cgroup.dir")) return ret_errno(EINVAL); if (lxc_conf->cgroup_meta.dir) @@ -4964,11 +4962,11 @@ static inline int clr_config_signal_stop(const char *key, struct lxc_conf *c, static inline int clr_config_start(const char *key, struct lxc_conf *c, void *data) { - if (strcmp(key + 10, "auto") == 0) + if (strequal(key + 10, "auto")) c->start_auto = 0; - else if (strcmp(key + 10, "delay") == 0) + else if (strequal(key + 10, "delay")) c->start_delay = 0; - else if (strcmp(key + 10, "order") == 0) + else if (strequal(key + 10, "order")) c->start_order = 0; return 0; @@ -6302,27 +6300,27 @@ int lxc_list_subkeys(struct lxc_conf *conf, const char *key, char *retv, else memset(retv, 0, inlen); - if (!strcmp(key, "lxc.apparmor")) { + if (strequal(key, "lxc.apparmor")) { strprint(retv, inlen, "allow_incomplete\n"); strprint(retv, inlen, "allow_nesting\n"); strprint(retv, inlen, "profile\n"); strprint(retv, inlen, "raw\n"); - } else if (!strcmp(key, "lxc.cgroup")) { + } else if (strequal(key, "lxc.cgroup")) { strprint(retv, inlen, "dir\n"); - } else if (!strcmp(key, "lxc.selinux")) { + } else if (strequal(key, "lxc.selinux")) { strprint(retv, inlen, "context\n"); strprint(retv, inlen, "context.keyring\n"); - } else if (!strcmp(key, "lxc.mount")) { + } else if (strequal(key, "lxc.mount")) { strprint(retv, inlen, "auto\n"); strprint(retv, inlen, "entry\n"); strprint(retv, inlen, "fstab\n"); - } else if (!strcmp(key, "lxc.rootfs")) { + } else if (strequal(key, "lxc.rootfs")) { strprint(retv, inlen, "mount\n"); strprint(retv, inlen, "options\n"); strprint(retv, inlen, "path\n"); - } else if (!strcmp(key, "lxc.uts")) { + } else if (strequal(key, "lxc.uts")) { strprint(retv, inlen, "name\n"); - } else if (!strcmp(key, "lxc.hook")) { + } else if (strequal(key, "lxc.hook")) { strprint(retv, inlen, "autodev\n"); strprint(retv, inlen, "autodevtmpfssize\n"); strprint(retv, inlen, "clone\n"); @@ -6334,25 +6332,25 @@ int lxc_list_subkeys(struct lxc_conf *conf, const char *key, char *retv, strprint(retv, inlen, "start-host\n"); strprint(retv, inlen, "start\n"); strprint(retv, inlen, "stop\n"); - } else if (!strcmp(key, "lxc.cap")) { + } else if (strequal(key, "lxc.cap")) { strprint(retv, inlen, "drop\n"); strprint(retv, inlen, "keep\n"); - } else if (!strcmp(key, "lxc.console")) { + } else if (strequal(key, "lxc.console")) { strprint(retv, inlen, "logfile\n"); strprint(retv, inlen, "path\n"); - } else if (!strcmp(key, "lxc.seccomp")) { + } else if (strequal(key, "lxc.seccomp")) { strprint(retv, inlen, "profile\n"); - } else if (!strcmp(key, "lxc.signal")) { + } else if (strequal(key, "lxc.signal")) { strprint(retv, inlen, "halt\n"); strprint(retv, inlen, "reboot\n"); strprint(retv, inlen, "stop\n"); - } else if (!strcmp(key, "lxc.start")) { + } else if (strequal(key, "lxc.start")) { strprint(retv, inlen, "auto\n"); strprint(retv, inlen, "delay\n"); strprint(retv, inlen, "order\n"); - } else if (!strcmp(key, "lxc.monitor")) { + } else if (strequal(key, "lxc.monitor")) { strprint(retv, inlen, "unshare\n"); - } else if (!strcmp(key, "lxc.keyring")) { + } else if (strequal(key, "lxc.keyring")) { strprint(retv, inlen, "session\n"); } else { fulllen = ret_errno(EINVAL);