[CRIU] [PATCHv2 2/3] Replace !strcmp() with STREQ()

Radostin Stoyanov rstoyanov1 at gmail.com
Tue Jan 29 16:11:20 MSK 2019


Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
---
 criu/autofs.c       |  7 +++----
 criu/cgroup-props.c |  8 ++++----
 criu/cgroup.c       | 34 +++++++++++++++++-----------------
 criu/config.c       | 22 +++++++++++-----------
 criu/cr-check.c     |  2 +-
 criu/crtools.c      | 34 +++++++++++++++++-----------------
 criu/external.c     |  2 +-
 criu/files-reg.c    |  4 ++--
 criu/files.c        |  2 +-
 criu/filesystems.c  |  9 ++++-----
 criu/lsm.c          |  8 ++++----
 criu/mount.c        | 12 ++++++------
 criu/net.c          | 28 ++++++++++++++--------------
 criu/proc_parse.c   | 42 +++++++++++++++++++++---------------------
 criu/seize.c        |  7 +++----
 criu/tty.c          |  2 +-
 criu/tun.c          |  2 +-
 criu/util.c         |  2 +-
 18 files changed, 112 insertions(+), 115 deletions(-)

diff --git a/criu/autofs.c b/criu/autofs.c
index 576edef68..4af58e87a 100644
--- a/criu/autofs.c
+++ b/criu/autofs.c
@@ -239,11 +239,11 @@ static int parse_options(char *options, AutofsEntry *entry, long *pipe_ino)
 			err = xatoi(opt + strlen("minproto="), &entry->minproto);
 		else if (!strncmp(opt, "maxproto=", strlen("maxproto=")))
 			err = xatoi(opt + strlen("maxproto="), &entry->maxproto);
-		else if (!strcmp(opt, "indirect"))
+		else if (STREQ(opt, "indirect"))
 			entry->mode = AUTOFS_MODE_INDIRECT;
-		else if (!strcmp(opt, "offset"))
+		else if (STREQ(opt, "offset"))
 			entry->mode = AUTOFS_MODE_OFFSET;
-		else if (!strcmp(opt, "direct"))
+		else if (STREQ(opt, "direct"))
 			entry->mode = AUTOFS_MODE_DIRECT;
 		else if (!strncmp(opt, "uid=", strlen("uid=")))
 			err = xatoi(opt + strlen("uid="), &entry->uid);
@@ -1076,4 +1076,3 @@ umount:
 		pr_perror("Failed to umount %s", mi->mountpoint);
 	goto close_pipe;
 }
-
diff --git a/criu/cgroup-props.c b/criu/cgroup-props.c
index ecd959352..21f0ddea4 100644
--- a/criu/cgroup-props.c
+++ b/criu/cgroup-props.c
@@ -276,9 +276,9 @@ static int cgp_parse_stream(char *stream, size_t len)
 			goto err_parse;
 		};
 
-		if (!strcmp(p, "merge")) {
+		if (STREQ(p, "merge")) {
 			strategy = CGP_MERGE;
-		} else if (!strcmp(p, "replace")) {
+		} else if (STREQ(p, "replace")) {
 			strategy = CGP_REPLACE;
 		} else {
 			pr_err("Unknown strategy \"%s\" in controller's %s stream\n",
@@ -543,7 +543,7 @@ bool cgp_should_skip_controller(const char *name)
 		return false;
 
 	for (i = 0; i < nr_dump_controllers; i++) {
-		if (!strcmp(name, dump_controllers[i]))
+		if (STREQ(name, dump_controllers[i]))
 			return false;
 	}
 
@@ -555,7 +555,7 @@ const cgp_t *cgp_get_props(const char *name)
 	cgp_list_entry_t *p;
 
 	list_for_each_entry(p, &cgp_list, list) {
-		if (!strcmp(p->cgp.name, name))
+		if (STREQ(p->cgp.name, name))
 			return &p->cgp;
 	}
 
diff --git a/criu/cgroup.c b/criu/cgroup.c
index 22e722acf..9d460188d 100644
--- a/criu/cgroup.c
+++ b/criu/cgroup.c
@@ -227,7 +227,7 @@ static int find_dir(const char *path, struct list_head *dirs, struct cgroup_dir
 {
 	struct cgroup_dir *d;
 	list_for_each_entry(d, dirs, siblings) {
-		if (strcmp(d->path, path) == 0) {
+		if (STREQ(d->path, path)) {
 			*rdir = d;
 			return EXACT_MATCH;
 		}
@@ -289,7 +289,7 @@ static int read_cgroup_prop(struct cgroup_prop *property, const char *fullpath)
 
 	/* skip dumping the value of these, since it doesn't make sense (we
 	 * just want to restore the perms) */
-	if (!strcmp(property->name, "cgroup.procs") || !strcmp(property->name, "tasks")) {
+	if (STREQ(property->name, "cgroup.procs") || STREQ(property->name, "tasks")) {
 		ret = 0;
 		/* libprotobuf segfaults if we leave a null pointer in a
 		 * string, so let's not do that */
@@ -387,7 +387,7 @@ static int dump_cg_props_array(const char *fpath, struct cgroup_dir *ncd, const
 			return -1;
 		}
 
-		if (!strcmp("memory.oom_control", cgp->props[j])) {
+		if (STREQ("memory.oom_control", cgp->props[j])) {
 			char *new;
 			int disable;
 
@@ -613,7 +613,7 @@ static int collect_cgroups(struct list_head *ctls)
 			root = opts.new_global_cg_root;
 
 		list_for_each_entry(o, &opts.new_cgroup_roots, node) {
-			if (!strcmp(cc->name, o->controller))
+			if (STREQ(cc->name, o->controller))
 				root = o->newroot;
 		}
 
@@ -628,7 +628,7 @@ static int collect_cgroups(struct list_head *ctls)
 		if (ret < 0)
 			return ret;
 
-		if (opts.freeze_cgroup && !strcmp(cc->name, "freezer") &&
+		if (opts.freeze_cgroup && STREQ(cc->name, "freezer") &&
 				add_freezer_state(current_controller))
 			return -1;
 	}
@@ -978,7 +978,7 @@ bool is_special_property(const char *prop)
 	size_t i = 0;
 
 	for (i = 0; special_props[i]; i++)
-		if (strcmp(prop, special_props[i]) == 0)
+		if (STREQ(prop, special_props[i]))
 			return true;
 
 	return false;
@@ -1232,7 +1232,7 @@ static int restore_cgroup_prop(const CgroupPropEntry *cg_prop_entry_p,
 		goto out;
 
 	/* skip these two since restoring their values doesn't make sense */
-	if (!strcmp(cg_prop_entry_p->name, "cgroup.procs") || !strcmp(cg_prop_entry_p->name, "tasks")) {
+	if (STREQ(cg_prop_entry_p->name, "cgroup.procs") || STREQ(cg_prop_entry_p->name, "tasks")) {
 		ret = 0;
 		goto out;
 	}
@@ -1389,14 +1389,14 @@ static int prepare_cgroup_dir_properties(char *path, int off, CgroupDirEntry **e
 		CgroupDirEntry *e = ents[i];
 		size_t off2 = off;
 
-		if (strcmp(e->dir_name, "") == 0)
+		if (STREQ(e->dir_name, ""))
 			goto skip; /* skip root cgroups */
 
 		off2 += sprintf(path + off, "/%s", e->dir_name);
 		for (j = 0; j < e->n_properties; ++j) {
 			CgroupPropEntry *p = e->properties[j];
 
-			if (!strcmp(p->name, "freezer.state")) {
+			if (STREQ(p->name, "freezer.state")) {
 				add_freezer_state_for_restore(p, path, off2);
 				continue; /* skip restore now */
 			}
@@ -1413,7 +1413,7 @@ static int prepare_cgroup_dir_properties(char *path, int off, CgroupDirEntry **e
 			 * The kernel can't handle it in one write()
 			 * Number of network interfaces on host may differ.
 			 */
-			if (strcmp(p->name, "net_prio.ifpriomap") == 0) {
+			if (STREQ(p->name, "net_prio.ifpriomap")) {
 				if (restore_cgroup_ifpriomap(p, path, off2))
 					return -1;
 				continue;
@@ -1478,7 +1478,7 @@ static int restore_devices_list(char *paux, size_t off, CgroupPropEntry *pr)
 	 * and the kernel disallows writing an "" to devices.allow,
 	 * so let's just keep going.
 	 */
-	if (!strcmp(dev_allow.value, ""))
+	if (STREQ(dev_allow.value, ""))
 		return 0;
 
 	if (ret < 0)
@@ -1494,12 +1494,12 @@ static int restore_special_property(char *paux, size_t off, CgroupPropEntry *pr)
 	 * memory.oom_control regular properties when we drop support for
 	 * kernels < 3.16. See 3dae7fec5.
 	 */
-	if (!strcmp(pr->name, "memory.swappiness") && !strcmp(pr->value, "60"))
+	if (STREQ(pr->name, "memory.swappiness") && STREQ(pr->value, "60"))
 		return 0;
-	if (!strcmp(pr->name, "memory.oom_control") && !strcmp(pr->value, "0"))
+	if (STREQ(pr->name, "memory.oom_control") && STREQ(pr->value, "0"))
 		return 0;
 
-	if (!strcmp(pr->name, "devices.list")) {
+	if (STREQ(pr->name, "devices.list")) {
 		/*
 		 * A bit of a fudge here. These are write only by owner
 		 * by default, but the container engine could have changed
@@ -1583,9 +1583,9 @@ static int prepare_cgroup_dirs(char **controllers, int n_controllers, char *paux
 				return -1;
 
 			for (j = 0; j < n_controllers; j++) {
-				if (!strcmp(controllers[j], "cpuset")
-						|| !strcmp(controllers[j], "memory")
-						|| !strcmp(controllers[j], "devices")) {
+				if (STREQ(controllers[j], "cpuset")
+						|| STREQ(controllers[j], "memory")
+						|| STREQ(controllers[j], "devices")) {
 					if (restore_special_props(paux, off2, e) < 0) {
 						pr_err("Restoring special cpuset props failed!\n");
 						return -1;
diff --git a/criu/config.c b/criu/config.c
index b6ecbfb64..304fcb5f2 100644
--- a/criu/config.c
+++ b/criu/config.c
@@ -97,7 +97,7 @@ static char ** parse_config(char *filepath)
 				/*
 				 * Handle empty strings which strtok ignores
 				 */
-				if (!strcmp(configuration[i], "\"\"")) {
+				if (STREQ(configuration[i], "\"\"")) {
 					configuration[i] = "";
 					offset += strlen("\"\"");
 				} else if ((configuration[i] = strtok_r(line + offset, "\"", &quotedptr))) {
@@ -220,12 +220,12 @@ static int pre_parse(int argc, char **argv, bool *usage_error, bool *no_default_
 	 * number of argv iterations, but checks for help have higher priority.
 	 */
 	for (i = 0; i < argc; i++) {
-		if ((!strcmp(argv[i], "--help")) || (!strcmp(argv[i], "-h"))) {
+		if ((STREQ(argv[i], "--help")) || (STREQ(argv[i], "-h"))) {
 			*usage_error = false;
 			return 1;
-		} else if (!strcmp(argv[i], "--no-default-config")) {
+		} else if (STREQ(argv[i], "--no-default-config")) {
 			*no_default_config = true;
-		} else if (!strcmp(argv[i], "--config")) {
+		} else if (STREQ(argv[i], "--config")) {
 			/*
 			 * getopt takes next string as required
 			 * argument automatically, we do the same
@@ -344,15 +344,15 @@ static int parse_manage_cgroups(struct cr_options *opts, const char *optarg)
 		return 0;
 	}
 
-	if (!strcmp(optarg, "none")) {
+	if (STREQ(optarg, "none")) {
 		opts->manage_cgroups = CG_MODE_NONE;
-	} else if (!strcmp(optarg, "props")) {
+	} else if (STREQ(optarg, "props")) {
 		opts->manage_cgroups = CG_MODE_PROPS;
-	} else if (!strcmp(optarg, "soft")) {
+	} else if (STREQ(optarg, "soft")) {
 		opts->manage_cgroups = CG_MODE_SOFT;
-	} else if (!strcmp(optarg, "full")) {
+	} else if (STREQ(optarg, "full")) {
 		opts->manage_cgroups = CG_MODE_FULL;
-	} else if (!strcmp(optarg, "strict")) {
+	} else if (STREQ(optarg, "strict")) {
 		opts->manage_cgroups = CG_MODE_STRICT;
 	} else
 		goto Esyntax;
@@ -725,7 +725,7 @@ int parse_options(int argc, char **argv, bool *usage_error,
 			{
 				char *aux;
 
-				if (strcmp(optarg, "auto") == 0) {
+				if (STREQ(optarg, "auto")) {
 					opts.autodetect_ext_mounts = true;
 					break;
 				}
@@ -744,7 +744,7 @@ int parse_options(int argc, char **argv, bool *usage_error,
 				return 1;
 			break;
 		case 1074:
-			if (!strcmp("net", optarg))
+			if (STREQ("net", optarg))
 				opts.empty_ns |= CLONE_NEWNET;
 			else {
 				pr_err("Unsupported empty namespace: %s\n",
diff --git a/criu/cr-check.c b/criu/cr-check.c
index 7addb9fb0..1574099cd 100644
--- a/criu/cr-check.c
+++ b/criu/cr-check.c
@@ -1336,7 +1336,7 @@ int check_add_feature(char *feat)
 	struct feature_list *fl;
 
 	for (fl = feature_list; fl->name; fl++) {
-		if (!strcmp(feat, fl->name)) {
+		if (STREQ(feat, fl->name)) {
 			chk_feature = fl->func;
 			return 0;
 		}
diff --git a/criu/crtools.c b/criu/crtools.c
index cbee1b76a..ecdc0a207 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -98,7 +98,7 @@ int main(int argc, char *argv[], char *envp[])
 	if (early_init())
 		return -1;
 
-	if (!strcmp(argv[1], "swrk")) {
+	if (STREQ(argv[1], "swrk")) {
 		if (argc < 3)
 			goto usage;
 		/*
@@ -125,7 +125,7 @@ int main(int argc, char *argv[], char *envp[])
 		goto usage;
 	}
 
-	if (!strcmp(argv[optind], "exec")) {
+	if (STREQ(argv[optind], "exec")) {
 		pr_msg("The \"exec\" action is deprecated by the Compel library.\n");
 		return -1;
 	}
@@ -173,7 +173,7 @@ int main(int argc, char *argv[], char *envp[])
 	 * When a process group becomes an orphan,
 	 * its processes are sent a SIGHUP signal
 	 */
-	if (!strcmp(argv[optind], "restore") &&
+	if (STREQ(argv[optind], "restore") &&
 			opts.restore_detach &&
 			opts.final_state == TASK_STOPPED &&
 			opts.shell_job)
@@ -205,13 +205,13 @@ int main(int argc, char *argv[], char *envp[])
 	if (opts.img_parent)
 		pr_info("Will do snapshot from %s\n", opts.img_parent);
 
-	if (!strcmp(argv[optind], "dump")) {
+	if (STREQ(argv[optind], "dump")) {
 		if (!opts.tree_id)
 			goto opt_pid_missing;
 		return cr_dump_tasks(opts.tree_id);
 	}
 
-	if (!strcmp(argv[optind], "pre-dump")) {
+	if (STREQ(argv[optind], "pre-dump")) {
 		if (!opts.tree_id)
 			goto opt_pid_missing;
 
@@ -223,7 +223,7 @@ int main(int argc, char *argv[], char *envp[])
 		return cr_pre_dump_tasks(opts.tree_id) != 0;
 	}
 
-	if (!strcmp(argv[optind], "restore")) {
+	if (STREQ(argv[optind], "restore")) {
 		if (opts.tree_id)
 			pr_warn("Using -t with criu restore is obsoleted\n");
 
@@ -238,28 +238,28 @@ int main(int argc, char *argv[], char *envp[])
 		return ret != 0;
 	}
 
-	if (!strcmp(argv[optind], "show")) {
+	if (STREQ(argv[optind], "show")) {
 		pr_msg("The \"show\" action is deprecated by the CRIT utility.\n");
 		pr_msg("To view an image use the \"crit decode -i $name --pretty\" command.\n");
 		return -1;
 	}
 
-	if (!strcmp(argv[optind], "lazy-pages"))
+	if (STREQ(argv[optind], "lazy-pages"))
 		return cr_lazy_pages(opts.daemon_mode) != 0;
 
-	if (!strcmp(argv[optind], "check"))
+	if (STREQ(argv[optind], "check"))
 		return cr_check() != 0;
 
-	if (!strcmp(argv[optind], "page-server"))
+	if (STREQ(argv[optind], "page-server"))
 		return cr_page_server(opts.daemon_mode, false, -1) != 0;
 
-	if (!strcmp(argv[optind], "image-cache")) {
+	if (STREQ(argv[optind], "image-cache")) {
 		if (!opts.port)
 			goto opt_port_missing;
 		return image_cache(opts.daemon_mode, DEFAULT_CACHE_SOCKET, opts.port);
 	}
 
-	if (!strcmp(argv[optind], "image-proxy")) {
+	if (STREQ(argv[optind], "image-proxy")) {
 		if (!opts.addr) {
 			pr_msg("Error: address not specified\n");
 			return 1;
@@ -269,20 +269,20 @@ int main(int argc, char *argv[], char *envp[])
 		return image_proxy(opts.daemon_mode, DEFAULT_PROXY_SOCKET, opts.addr, opts.port);
 	}
 
-	if (!strcmp(argv[optind], "service"))
+	if (STREQ(argv[optind], "service"))
 		return cr_service(opts.daemon_mode);
 
-	if (!strcmp(argv[optind], "dedup"))
+	if (STREQ(argv[optind], "dedup"))
 		return cr_dedup() != 0;
 
-	if (!strcmp(argv[optind], "cpuinfo")) {
+	if (STREQ(argv[optind], "cpuinfo")) {
 		if (!argv[optind + 1]) {
 			pr_msg("Error: cpuinfo requires an action: dump or check\n");
 			goto usage;
 		}
-		if (!strcmp(argv[optind + 1], "dump"))
+		if (STREQ(argv[optind + 1], "dump"))
 			return cpuinfo_dump();
-		else if (!strcmp(argv[optind + 1], "check"))
+		else if (STREQ(argv[optind + 1], "check"))
 			return cpuinfo_check();
 	}
 
diff --git a/criu/external.c b/criu/external.c
index 96e676849..ec69966a5 100644
--- a/criu/external.c
+++ b/criu/external.c
@@ -37,7 +37,7 @@ bool external_lookup_id(char *id)
 	struct external *ext;
 
 	list_for_each_entry(ext, &opts.external, node)
-		if (!strcmp(ext->id, id))
+		if (STREQ(ext->id, id))
 			return true;
 	return false;
 }
diff --git a/criu/files-reg.c b/criu/files-reg.c
index 892b62304..829ca0ce0 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -1117,7 +1117,7 @@ int strip_deleted(struct fd_link *link)
 			continue;
 
 		at = link->len - prepends[i].len;
-		if (!strcmp(&link->name[at], prepends[i].str)) {
+		if (STREQ(&link->name[at], prepends[i].str)) {
 			pr_debug("Strip '%s' tag from '%s'\n",
 				 prepends[i].str, link->name);
 			link->name[at] = '\0';
@@ -1634,7 +1634,7 @@ int open_path(struct file_desc *d,
 		tmp = inherit_fd_lookup_id(rfi->rfe->name);
 		if (tmp >= 0) {
 			inh_fd = tmp;
-			/* 
+			/*
 			 * PROC_SELF isn't used, because only service
 			 * descriptors can be used here.
 			 */
diff --git a/criu/files.c b/criu/files.c
index 31f847ee9..5124a50ad 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -1587,7 +1587,7 @@ int inherit_fd_lookup_id(char *id)
 
 	ret = -1;
 	list_for_each_entry(inh, &opts.inherit_fds, inh_list) {
-		if (!strcmp(inh->inh_id, id)) {
+		if (STREQ(inh->inh_id, id)) {
 			ret = fdstore_get(inh->inh_fd_id);
 			pr_debug("Found id %s (fd %d) in inherit fd list\n",
 				id, ret);
diff --git a/criu/filesystems.c b/criu/filesystems.c
index d227427b8..d99cf3bf7 100644
--- a/criu/filesystems.c
+++ b/criu/filesystems.c
@@ -165,9 +165,9 @@ static int binfmt_misc_dump(struct mount_info *pm)
 	while ((de = readdir(fdir))) {
 		if (dir_dots(de))
 			continue;
-		if (!strcmp(de->d_name, "register"))
+		if (STREQ(de->d_name, "register"))
 			continue;
-		if (!strcmp(de->d_name, "status"))
+		if (STREQ(de->d_name, "status"))
 			continue;
 
 		if (!img) {
@@ -632,7 +632,7 @@ static bool btrfs_sb_equal(struct mount_info *a, struct mount_info *b)
 	}
 
 	*posa = *posb = 0;
-	equal = !strcmp(a->options, b->options);
+	equal = STREQ(a->options, b->options);
 	*posa = *posb = 's';
 
 	if (!equal)
@@ -841,7 +841,7 @@ struct fstype *find_fstype_by_name(char *fst)
 	for (i = 1; i < ARRAY_SIZE(fstypes); i++) {
 		struct fstype *fstype = fstypes + i;
 
-		if (!strcmp(fstype->name, fst))
+		if (STREQ(fstype->name, fst))
 			return fstype;
 	}
 
@@ -870,4 +870,3 @@ struct fstype *decode_fstype(u32 fst)
 uns:
 	return &fstypes[0];
 }
-
diff --git a/criu/lsm.c b/criu/lsm.c
index eec73ede5..c6e4e1b8f 100644
--- a/criu/lsm.c
+++ b/criu/lsm.c
@@ -50,7 +50,7 @@ static int apparmor_get_label(pid_t pid, char **profile_name)
 	 * An "unconfined" value means there is no profile, so we don't need to
 	 * worry about trying to restore one.
 	 */
-	if (strcmp(*profile_name, "unconfined") == 0) {
+	if (STREQ(*profile_name, "unconfined")) {
 		free(*profile_name);
 		*profile_name = NULL;
 	}
@@ -224,21 +224,21 @@ int lsm_check_opts(void)
 	*aux = '\0';
 	aux++;
 
-	if (strcmp(opts.lsm_profile, "apparmor") == 0) {
+	if (STREQ(opts.lsm_profile, "apparmor")) {
 		if (kdat.lsm != LSMTYPE__APPARMOR) {
 			pr_err("apparmor LSM specified but apparmor not supported by kernel\n");
 			return -1;
 		}
 
 		SET_CHAR_OPTS(lsm_profile, aux);
-	} else if (strcmp(opts.lsm_profile, "selinux") == 0) {
+	} else if (STREQ(opts.lsm_profile, "selinux")) {
 		if (kdat.lsm != LSMTYPE__SELINUX) {
 			pr_err("selinux LSM specified but selinux not supported by kernel\n");
 			return -1;
 		}
 
 		SET_CHAR_OPTS(lsm_profile, aux);
-	} else if (strcmp(opts.lsm_profile, "none") == 0) {
+	} else if (STREQ(opts.lsm_profile, "none")) {
 		xfree(opts.lsm_profile);
 		opts.lsm_profile = NULL;
 	} else {
diff --git a/criu/mount.c b/criu/mount.c
index 696aed526..4a2169e9b 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -546,7 +546,7 @@ static bool mnt_needs_remap(struct mount_info *m)
 	 * remapped too, else fixup_remap_mounts() won't be able to move parent
 	 * to it's real place, it will move child instead.
 	 */
-	if (!strcmp(m->parent->mountpoint, m->mountpoint))
+	if (STREQ(m->parent->mountpoint, m->mountpoint))
 		return mnt_needs_remap(m->parent);
 
 	return false;
@@ -599,7 +599,7 @@ static int validate_children_collision(struct mount_info *mnt)
 		list_for_each_entry(chj, &mnt->children, siblings) {
 			if (chj == chi)
 				break;
-			if (!strcmp(chj->mountpoint, chi->mountpoint)) {
+			if (STREQ(chj->mountpoint, chi->mountpoint)) {
 				pr_err("Mount %d has two children with same "
 				       "mountpoint: %d %d\n",
 				       mnt->mnt_id, chj->mnt_id, chi->mnt_id);
@@ -889,7 +889,7 @@ static int same_propagation_group(struct mount_info *a, struct mount_info *b) {
 	 * 3) Their mountpoints relative to the root of the superblock of their
 	 * parent's share should be equal
 	 */
-	if (!strcmp(root_path_a, root_path_b))
+	if (STREQ(root_path_a, root_path_b))
 		return 1;
 	return 0;
 }
@@ -1174,7 +1174,7 @@ static bool mnt_is_overmounted(struct mount_info *mi)
 
 	/* Check there is no children-overmount */
 	list_for_each_entry(c, &mi->children, siblings)
-		if (!strcmp(c->mountpoint, mi->mountpoint))
+		if (STREQ(c->mountpoint, mi->mountpoint))
 			return true;
 
 	return false;
@@ -1196,7 +1196,7 @@ static int __umount_children_overmounts(struct mount_info *mi)
 	 */
 again:
 	list_for_each_entry(c, &m->children, siblings) {
-		if (!strcmp(c->mountpoint, m->mountpoint)) {
+		if (STREQ(c->mountpoint, m->mountpoint)) {
 			m = c;
 			goto again;
 		}
@@ -2464,7 +2464,7 @@ static int do_mount_one(struct mount_info *mi)
 		return 1;
 	}
 
-	if (!strcmp(mi->parent->mountpoint, mi->mountpoint)) {
+	if (STREQ(mi->parent->mountpoint, mi->mountpoint)) {
 		mi->parent->fd = open(mi->parent->mountpoint, O_PATH);
 		if (mi->parent->fd < 0) {
 			pr_perror("Unable to open %s", mi->mountpoint);
diff --git a/criu/net.c b/criu/net.c
index c1a6e3094..827c5eee8 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -116,7 +116,7 @@ static bool sysctl_entries_equal(SysctlEntry *a, SysctlEntry *b)
 		case SYSCTL_TYPE__CTL_32:
 			return a->has_iarg && b->has_iarg && a->iarg == b->iarg;
 		case SYSCTL_TYPE__CTL_STR:
-			return a->sarg && b->sarg && !strcmp(a->sarg, b->sarg);
+			return a->sarg && b->sarg && STREQ(a->sarg, b->sarg);
 		default:;
 	}
 
@@ -243,7 +243,7 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto
 		 * Make "accept_redirects" go last on write(it should
 		 * restore after forwarding to be correct)
 		 */
-		if (op == CTL_WRITE && !strcmp(devconfs[i], "accept_redirects")) {
+		if (op == CTL_WRITE && STREQ(devconfs[i], "accept_redirects")) {
 			ar = i;
 			continue;
 		}
@@ -263,7 +263,7 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto
 				break;
 			case SYSCTL_TYPE__CTL_STR:
 				req[ri].type = CTL_STR(MAX_STR_CONF_LEN);
-				req[ri].flags |= op == CTL_READ && !strcmp(devconfs[i], "stable_secret")
+				req[ri].flags |= op == CTL_READ && STREQ(devconfs[i], "stable_secret")
 					? CTL_FLAGS_READ_EIO_SKIP : 0;
 
 				/* skip non-existing sysctl */
@@ -608,7 +608,7 @@ static int dump_macvlan(NetDeviceEntry *nde, struct cr_imgset *imgset, struct nl
 static int dump_one_ethernet(struct ifinfomsg *ifi, char *kind,
 		struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds)
 {
-	if (!strcmp(kind, "veth"))
+	if (STREQ(kind, "veth"))
 		/*
 		 * This is not correct. The peer of the veth device may
 		 * be either outside or inside the netns we're working
@@ -618,11 +618,11 @@ static int dump_one_ethernet(struct ifinfomsg *ifi, char *kind,
 		 * connection to the outer world and just dump this end :(
 		 */
 		return dump_one_netdev(ND_TYPE__VETH, ifi, tb, ns, fds, NULL);
-	if (!strcmp(kind, "tun"))
+	if (STREQ(kind, "tun"))
 		return dump_one_netdev(ND_TYPE__TUN, ifi, tb, ns, fds, dump_tun_link);
-	if (!strcmp(kind, "bridge"))
+	if (STREQ(kind, "bridge"))
 		return dump_one_netdev(ND_TYPE__BRIDGE, ifi, tb, ns, fds, dump_bridge);
-	if (!strcmp(kind, "gretap")) {
+	if (STREQ(kind, "gretap")) {
 		char *name = (char *)RTA_DATA(tb[IFLA_IFNAME]);
 
 		if (!name) {
@@ -630,14 +630,14 @@ static int dump_one_ethernet(struct ifinfomsg *ifi, char *kind,
 			return -1;
 		}
 
-		if (!strcmp(name, "gretap0")) {
+		if (STREQ(name, "gretap0")) {
 			pr_info("found %s, ignoring\n", name);
 			return 0;
 		}
 
 		pr_warn("GRE tap device %s not supported natively\n", name);
 	}
-	if (!strcmp(kind, "macvlan"))
+	if (STREQ(kind, "macvlan"))
 		return dump_one_netdev(ND_TYPE__MACVLAN, ifi, tb, ns, fds, dump_macvlan);
 
 	return dump_unknown_device(ifi, kind, tb, ns, fds);
@@ -646,7 +646,7 @@ static int dump_one_ethernet(struct ifinfomsg *ifi, char *kind,
 static int dump_one_gendev(struct ifinfomsg *ifi, char *kind,
 		struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds)
 {
-	if (!strcmp(kind, "tun"))
+	if (STREQ(kind, "tun"))
 		return dump_one_netdev(ND_TYPE__TUN, ifi, tb, ns, fds, dump_tun_link);
 
 	return dump_unknown_device(ifi, kind, tb, ns, fds);
@@ -655,7 +655,7 @@ static int dump_one_gendev(struct ifinfomsg *ifi, char *kind,
 static int dump_one_voiddev(struct ifinfomsg *ifi, char *kind,
 		struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds)
 {
-	if (!strcmp(kind, "venet"))
+	if (STREQ(kind, "venet"))
 		return dump_one_netdev(ND_TYPE__VENET, ifi, tb, ns, fds, NULL);
 
 	return dump_unknown_device(ifi, kind, tb, ns, fds);
@@ -664,14 +664,14 @@ static int dump_one_voiddev(struct ifinfomsg *ifi, char *kind,
 static int dump_one_gre(struct ifinfomsg *ifi, char *kind,
 		struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds)
 {
-	if (!strcmp(kind, "gre")) {
+	if (STREQ(kind, "gre")) {
 		char *name = (char *)RTA_DATA(tb[IFLA_IFNAME]);
 		if (!name) {
 			pr_err("gre device %d has no name\n", ifi->ifi_index);
 			return -1;
 		}
 
-		if (!strcmp(name, "gre0")) {
+		if (STREQ(name, "gre0")) {
 			pr_info("found %s, ignoring\n", name);
 			return 0;
 		}
@@ -797,7 +797,7 @@ static int dump_one_sit(struct ifinfomsg *ifi, char *kind,
 		return -1;
 	}
 
-	if (!strcmp(name, "sit0")) {
+	if (STREQ(name, "sit0")) {
 		pr_info("found %s, ignoring\n", name);
 		return 0;
 	}
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 1a5722eaf..03debf622 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -545,16 +545,16 @@ static int handle_vma(pid_t pid, struct vma_area *vma_area,
 	if (vma_area->e->status != 0)
 		return 0;
 
-	if (!strcmp(file_path, "[vsyscall]") ||
-		   !strcmp(file_path, "[vectors]")) {
+	if (STREQ(file_path, "[vsyscall]") ||
+		   STREQ(file_path, "[vectors]")) {
 		vma_area->e->status |= VMA_AREA_VSYSCALL;
-	} else if (!strcmp(file_path, "[vdso]")) {
+	} else if (STREQ(file_path, "[vdso]")) {
 		if (handle_vdso_vma(vma_area))
 			goto err;
-	} else if (!strcmp(file_path, "[vvar]")) {
+	} else if (STREQ(file_path, "[vvar]")) {
 		if (handle_vvar_vma(vma_area))
 			goto err;
-	} else if (!strcmp(file_path, "[heap]")) {
+	} else if (STREQ(file_path, "[heap]")) {
 		vma_area->e->status |= VMA_AREA_REGULAR | VMA_AREA_HEAP;
 	} else {
 		vma_area->e->status = VMA_AREA_REGULAR;
@@ -1206,7 +1206,7 @@ static int do_opt2flag(char *opt, unsigned *flags,
 			*end = '\0';
 
 		for (i = 0; opts[i].opt != NULL; i++)
-			if (!strcmp(opts[i].opt, opt)) {
+			if (STREQ(opts[i].opt, opt)) {
 				(*flags) |= opts[i].flag;
 				break;
 			}
@@ -1458,7 +1458,7 @@ static bool should_skip_mount(const char *mountpoint)
 	struct str_node *pos;
 
 	list_for_each_entry(pos, &skip_mount_list, node) {
-		if (strcmp(mountpoint, pos->string) == 0)
+		if (STREQ(mountpoint, pos->string))
 			return true;
 	}
 
@@ -2023,40 +2023,40 @@ static int parse_file_lock_buf(char *buf, struct file_lock *fl,
 		return -1;
 	}
 
-	if (!strcmp(fl_flag, "POSIX"))
+	if (STREQ(fl_flag, "POSIX"))
 		fl->fl_kind = FL_POSIX;
-	else if (!strcmp(fl_flag, "FLOCK"))
+	else if (STREQ(fl_flag, "FLOCK"))
 		fl->fl_kind = FL_FLOCK;
-	else if (!strcmp(fl_flag, "OFDLCK"))
+	else if (STREQ(fl_flag, "OFDLCK"))
 		fl->fl_kind = FL_OFD;
-	else if (!strcmp(fl_flag, "LEASE"))
+	else if (STREQ(fl_flag, "LEASE"))
 		fl->fl_kind = FL_LEASE;
 	else
 		fl->fl_kind = FL_UNKNOWN;
 
-	if (fl->fl_kind == FL_LEASE && !strcmp(fl_type, "BREAKING")) {
+	if (fl->fl_kind == FL_LEASE && STREQ(fl_type, "BREAKING")) {
 		fl->fl_ltype |= LEASE_BREAKING;
 	}
 
-	if (!strcmp(fl_type, "MSNFS")) {
+	if (STREQ(fl_type, "MSNFS")) {
 		fl->fl_ltype |= LOCK_MAND;
 
-		if (!strcmp(fl_option, "READ")) {
+		if (STREQ(fl_option, "READ")) {
 			fl->fl_ltype |= LOCK_READ;
-		} else if (!strcmp(fl_option, "RW")) {
+		} else if (STREQ(fl_option, "RW")) {
 			fl->fl_ltype |= LOCK_RW;
-		} else if (!strcmp(fl_option, "WRITE")) {
+		} else if (STREQ(fl_option, "WRITE")) {
 			fl->fl_ltype |= LOCK_WRITE;
 		} else {
 			pr_err("Unknown lock option!\n");
 			return -1;
 		}
 	} else {
-		if (!strcmp(fl_option, "UNLCK")) {
+		if (STREQ(fl_option, "UNLCK")) {
 			fl->fl_ltype |= F_UNLCK;
-		} else if (!strcmp(fl_option, "WRITE")) {
+		} else if (STREQ(fl_option, "WRITE")) {
 			fl->fl_ltype |= F_WRLCK;
-		} else if (!strcmp(fl_option, "READ")) {
+		} else if (STREQ(fl_option, "READ")) {
 			fl->fl_ltype |= F_RDLCK;
 		} else {
 			pr_err("Unknown lock option!\n");
@@ -2435,7 +2435,7 @@ int parse_task_cgroup(int pid, struct parasite_dump_cgroup_args *args, struct li
 			 * is no cgroup namespace relative to criu), the paths
 			 * are equal and we don't need to set a prefix.
 			 */
-			if (!strcmp(ext->path, intern->path))
+			if (STREQ(ext->path, intern->path))
 				continue;
 
 			/* +1 here to chop off the leading / */
@@ -2571,7 +2571,7 @@ int aufs_parse(struct mount_info *new)
 {
 	int ret = 0;
 
-	if (!strcmp(new->mountpoint, "./")) {
+	if (STREQ(new->mountpoint, "./")) {
 		opts.aufs = true;
 		ret = parse_aufs_branches(new);
 	}
diff --git a/criu/seize.c b/criu/seize.c
index b958d4bf9..361a94773 100644
--- a/criu/seize.c
+++ b/criu/seize.c
@@ -51,11 +51,11 @@ static const char *get_freezer_state(int fd)
 		state[ret] = 0;
 
 	pr_debug("freezer.state=%s\n", state);
-	if (strcmp(state, frozen) == 0)
+	if (STREQ(state, frozen))
 		return frozen;
-	else if (strcmp(state, freezing) == 0)
+	else if (STREQ(state, freezing))
 		return freezing;
-	else if (strcmp(state, thawed) == 0)
+	else if (STREQ(state, thawed))
 		return thawed;
 
 	pr_err("Unknown freezer state: %s\n", state);
@@ -838,4 +838,3 @@ err:
 	alarm(0);
 	return ret;
 }
-
diff --git a/criu/tty.c b/criu/tty.c
index ad9574858..1c042fca7 100644
--- a/criu/tty.c
+++ b/criu/tty.c
@@ -2415,7 +2415,7 @@ int devpts_check_bindmount(struct mount_info *m)
 	struct mount_info *master_mp;
 	int index;
 
-	if (strcmp(m->root, "/") == 0 || strcmp(m->root, "/ptmx") == 0)
+	if (STREQ(m->root, "/") || STREQ(m->root, "/ptmx"))
 		return 0;
 
 	if (sscanf(m->root, "/%d", &index) != 1) {
diff --git a/criu/tun.c b/criu/tun.c
index b13148b0b..e2eb9ed54 100644
--- a/criu/tun.c
+++ b/criu/tun.c
@@ -139,7 +139,7 @@ static struct tun_link *find_tun_link(char *name, unsigned int ns_id)
 	struct tun_link *tl;
 
 	list_for_each_entry(tl, &tun_links, l) {
-		if (!strcmp(tl->name, name) &&
+		if (STREQ(tl->name, name) &&
 		    tl->ns_id == ns_id)
 			return tl;
 	}
diff --git a/criu/util.c b/criu/util.c
index bf9efe509..c7257dedc 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -729,7 +729,7 @@ int is_anon_link_type(char *link, char *type)
 	char aux[32];
 
 	snprintf(aux, sizeof(aux), "anon_inode:%s", type);
-	return !strcmp(link, aux);
+	return STREQ(link, aux);
 }
 
 #define DUP_SAFE(fd, out)						\
-- 
2.20.1



More information about the CRIU mailing list