Skip to content

Commit

Permalink
cgroups: convert to strequal()
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 13, 2021
1 parent e8c4335 commit 8b99a20
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
24 changes: 12 additions & 12 deletions src/lxc/cgroups/cgfsng.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/lxc/cgroups/cgroup.c
Expand Up @@ -16,6 +16,7 @@
#include "initutils.h"
#include "log.h"
#include "start.h"
#include "string_utils.h"

lxc_log_define(cgroup, lxc);

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lxc/cgroups/cgroup2_devices.c
Expand Up @@ -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;

/*
Expand Down

0 comments on commit 8b99a20

Please sign in to comment.