confile: convert to strequal()

parent eed95eb0
...@@ -299,7 +299,7 @@ struct lxc_config_t *lxc_get_config(const char *key) ...@@ -299,7 +299,7 @@ struct lxc_config_t *lxc_get_config(const char *key)
size_t i; size_t i;
for (i = 0; i < config_jump_table_size; i++) for (i = 0; i < config_jump_table_size; i++)
if (!strncmp(config_jump_table[i].name, key, strlen(config_jump_table[i].name))) if (strnequal(config_jump_table[i].name, key, strlen(config_jump_table[i].name)))
return &config_jump_table[i]; return &config_jump_table[i];
return NULL; return NULL;
...@@ -396,7 +396,7 @@ static int create_matched_ifnames(const char *value, struct lxc_conf *lxc_conf, ...@@ -396,7 +396,7 @@ static int create_matched_ifnames(const char *value, struct lxc_conf *lxc_conf,
if (ifa->ifa_addr->sa_family != AF_PACKET) if (ifa->ifa_addr->sa_family != AF_PACKET)
continue; continue;
if (!strncmp(value, ifa->ifa_name, strlen(value) - 1)) { if (strnequal(value, ifa->ifa_name, strlen(value) - 1)) {
ret = set_config_net_type(type_key, tmpvalue, lxc_conf, ret = set_config_net_type(type_key, tmpvalue, lxc_conf,
netdev); netdev);
if (!ret) { if (!ret) {
...@@ -1107,7 +1107,7 @@ static int set_config_seccomp_notify_proxy(const char *key, const char *value, ...@@ -1107,7 +1107,7 @@ static int set_config_seccomp_notify_proxy(const char *key, const char *value,
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_seccomp_notify_proxy(key, lxc_conf, NULL); return clr_config_seccomp_notify_proxy(key, lxc_conf, NULL);
if (strncmp(value, "unix:", 5) != 0) if (!strnequal(value, "unix:", 5))
return ret_set_errno(-1, EINVAL); return ret_set_errno(-1, EINVAL);
offset = value + 5; offset = value + 5;
...@@ -1764,7 +1764,7 @@ static int __set_config_cgroup_controller(const char *key, const char *value, ...@@ -1764,7 +1764,7 @@ static int __set_config_cgroup_controller(const char *key, const char *value,
return ret_errno(EINVAL); return ret_errno(EINVAL);
} }
if (strncmp(key, token, token_len) != 0) if (!strnequal(key, token, token_len))
return ret_errno(EINVAL); return ret_errno(EINVAL);
subkey = key + token_len; subkey = key + token_len;
...@@ -1903,7 +1903,7 @@ static bool parse_limit_value(const char **value, rlim_t *res) ...@@ -1903,7 +1903,7 @@ static bool parse_limit_value(const char **value, rlim_t *res)
{ {
char *endptr = NULL; char *endptr = NULL;
if (strncmp(*value, "unlimited", STRLITERALLEN("unlimited")) == 0) { if (strnequal(*value, "unlimited", STRLITERALLEN("unlimited"))) {
*res = RLIM_INFINITY; *res = RLIM_INFINITY;
*value += STRLITERALLEN("unlimited"); *value += STRLITERALLEN("unlimited");
return true; return true;
...@@ -1931,7 +1931,7 @@ static int set_config_prlimit(const char *key, const char *value, ...@@ -1931,7 +1931,7 @@ static int set_config_prlimit(const char *key, const char *value,
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return lxc_clear_limits(lxc_conf, key); return lxc_clear_limits(lxc_conf, key);
if (strncmp(key, "lxc.prlimit.", STRLITERALLEN("lxc.prlimit.")) != 0) if (!strnequal(key, "lxc.prlimit.", STRLITERALLEN("lxc.prlimit.")))
return ret_errno(EINVAL); return ret_errno(EINVAL);
key += STRLITERALLEN("lxc.prlimit."); key += STRLITERALLEN("lxc.prlimit.");
...@@ -2012,7 +2012,7 @@ static int set_config_sysctl(const char *key, const char *value, ...@@ -2012,7 +2012,7 @@ static int set_config_sysctl(const char *key, const char *value,
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_sysctl(key, lxc_conf, NULL); return clr_config_sysctl(key, lxc_conf, NULL);
if (strncmp(key, "lxc.sysctl.", STRLITERALLEN("lxc.sysctl.")) != 0) if (!strnequal(key, "lxc.sysctl.", STRLITERALLEN("lxc.sysctl.")))
return -1; return -1;
key += STRLITERALLEN("lxc.sysctl."); key += STRLITERALLEN("lxc.sysctl.");
...@@ -2070,7 +2070,7 @@ static int set_config_proc(const char *key, const char *value, ...@@ -2070,7 +2070,7 @@ static int set_config_proc(const char *key, const char *value,
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_proc(key, lxc_conf, NULL); return clr_config_proc(key, lxc_conf, NULL);
if (strncmp(key, "lxc.proc.", STRLITERALLEN("lxc.proc.")) != 0) if (!strnequal(key, "lxc.proc.", STRLITERALLEN("lxc.proc.")))
return -1; return -1;
subkey = key + STRLITERALLEN("lxc.proc."); subkey = key + STRLITERALLEN("lxc.proc.");
...@@ -2224,7 +2224,7 @@ static int set_config_mount_auto(const char *key, const char *value, ...@@ -2224,7 +2224,7 @@ static int set_config_mount_auto(const char *key, const char *value,
break; break;
if (strequal("shmounts:", allowed_auto_mounts[i].token) && if (strequal("shmounts:", allowed_auto_mounts[i].token) &&
strncmp("shmounts:", token, STRLITERALLEN("shmounts:")) == 0) { strnequal("shmounts:", token, STRLITERALLEN("shmounts:"))) {
is_shmounts = true; is_shmounts = true;
break; break;
} }
...@@ -2569,7 +2569,7 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf) ...@@ -2569,7 +2569,7 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
continue; continue;
len = strlen(fnam); len = strlen(fnam);
if (len < 6 || strncmp(fnam + len - 5, ".conf", 5) != 0) if (len < 6 || !strnequal(fnam + len - 5, ".conf", 5))
continue; continue;
len = strnprintf(path, sizeof(path), "%s/%s", dirp, fnam); len = strnprintf(path, sizeof(path), "%s/%s", dirp, fnam);
...@@ -2897,7 +2897,7 @@ static int parse_line(char *buffer, void *data) ...@@ -2897,7 +2897,7 @@ static int parse_line(char *buffer, void *data)
return 0; return 0;
/* martian option - don't add it to the config itself */ /* martian option - don't add it to the config itself */
if (strncmp(line, "lxc.", 4)) if (!strnequal(line, "lxc.", 4))
return 0; return 0;
dot = strchr(line, '='); dot = strchr(line, '=');
...@@ -2944,7 +2944,7 @@ static struct new_config_item *parse_new_conf_line(char *buffer) ...@@ -2944,7 +2944,7 @@ static struct new_config_item *parse_new_conf_line(char *buffer)
line += lxc_char_left_gc(line, strlen(line)); line += lxc_char_left_gc(line, strlen(line));
/* martian option - don't add it to the config itself */ /* martian option - don't add it to the config itself */
if (strncmp(line, "lxc.", 4)) if (!strnequal(line, "lxc.", 4))
return 0; return 0;
dot = strchr(line, '='); dot = strchr(line, '=');
...@@ -3190,7 +3190,7 @@ void clear_unexp_config_line(struct lxc_conf *conf, const char *key, ...@@ -3190,7 +3190,7 @@ void clear_unexp_config_line(struct lxc_conf *conf, const char *key,
else else
lend++; lend++;
if (strncmp(lstart, key, strlen(key)) != 0) { if (!strnequal(lstart, key, strlen(key))) {
lstart = lend; lstart = lend;
continue; continue;
} }
...@@ -3247,7 +3247,7 @@ bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath, ...@@ -3247,7 +3247,7 @@ bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath,
else else
lend++; lend++;
if (strncmp(lstart, key, strlen(key)) != 0) if (!strnequal(lstart, key, strlen(key)))
goto next; goto next;
p = strchr(lstart + strlen(key), '='); p = strchr(lstart + strlen(key), '=');
...@@ -3354,7 +3354,7 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath, ...@@ -3354,7 +3354,7 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath,
else else
lend++; lend++;
if (strncmp(lstart, key, strlen(key)) != 0) if (!strnequal(lstart, key, strlen(key)))
goto next; goto next;
p = strchr(lstart + strlen(key), '='); p = strchr(lstart + strlen(key), '=');
...@@ -3368,7 +3368,7 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath, ...@@ -3368,7 +3368,7 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath,
if (p >= lend) if (p >= lend)
goto next; goto next;
if (strncmp(p, olddir, strlen(olddir)) != 0) if (!strnequal(p, olddir, strlen(olddir)))
goto next; goto next;
/* replace the olddir with newdir */ /* replace the olddir with newdir */
...@@ -3705,7 +3705,7 @@ static int __get_config_cgroup_controller(const char *key, char *retv, ...@@ -3705,7 +3705,7 @@ static int __get_config_cgroup_controller(const char *key, char *retv,
if (strequal(key, global_token)) if (strequal(key, global_token))
get_all = true; get_all = true;
else if (strncmp(key, namespaced_token, namespaced_token_len) == 0) else if (strnequal(key, namespaced_token, namespaced_token_len))
key += namespaced_token_len; key += namespaced_token_len;
else else
return ret_errno(EINVAL); return ret_errno(EINVAL);
...@@ -4384,7 +4384,7 @@ static int get_config_prlimit(const char *key, char *retv, int inlen, ...@@ -4384,7 +4384,7 @@ static int get_config_prlimit(const char *key, char *retv, int inlen,
if (strequal(key, "lxc.prlimit")) if (strequal(key, "lxc.prlimit"))
get_all = true; get_all = true;
else if (strncmp(key, "lxc.prlimit.", 12) == 0) else if (strnequal(key, "lxc.prlimit.", 12))
key += 12; key += 12;
else else
return ret_errno(EINVAL); return ret_errno(EINVAL);
...@@ -4442,7 +4442,7 @@ static int get_config_sysctl(const char *key, char *retv, int inlen, ...@@ -4442,7 +4442,7 @@ static int get_config_sysctl(const char *key, char *retv, int inlen,
if (strequal(key, "lxc.sysctl")) if (strequal(key, "lxc.sysctl"))
get_all = true; get_all = true;
else if (strncmp(key, "lxc.sysctl.", STRLITERALLEN("lxc.sysctl.")) == 0) else if (strnequal(key, "lxc.sysctl.", STRLITERALLEN("lxc.sysctl.")))
key += STRLITERALLEN("lxc.sysctl."); key += STRLITERALLEN("lxc.sysctl.");
else else
return ret_errno(EINVAL); return ret_errno(EINVAL);
...@@ -4475,7 +4475,7 @@ static int get_config_proc(const char *key, char *retv, int inlen, ...@@ -4475,7 +4475,7 @@ static int get_config_proc(const char *key, char *retv, int inlen,
if (strequal(key, "lxc.proc")) if (strequal(key, "lxc.proc"))
get_all = true; get_all = true;
else if (strncmp(key, "lxc.proc.", STRLITERALLEN("lxc.proc.")) == 0) else if (strnequal(key, "lxc.proc.", STRLITERALLEN("lxc.proc.")))
key += STRLITERALLEN("lxc.proc."); key += STRLITERALLEN("lxc.proc.");
else else
return ret_errno(EINVAL); return ret_errno(EINVAL);
...@@ -5151,7 +5151,7 @@ static struct lxc_config_t *get_network_config_ops(const char *key, ...@@ -5151,7 +5151,7 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
char *idx_start, *idx_end; char *idx_start, *idx_end;
/* check that this is a sensible network key */ /* check that this is a sensible network key */
if (strncmp("lxc.net.", key, 8)) if (!strnequal("lxc.net.", key, 8))
return log_error_errno(NULL, EINVAL, "Invalid network configuration key \"%s\"", key); return log_error_errno(NULL, EINVAL, "Invalid network configuration key \"%s\"", key);
copy = strdup(key); copy = strdup(key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment