[CRIU] [PATCH 3/3] Replace strcmp() with STRNEQ()

Radostin Stoyanov rstoyanov1 at gmail.com
Mon Jan 28 01:18:59 MSK 2019


Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
---
 criu/cgroup-props.c |  2 +-
 criu/cgroup.c       |  8 ++++----
 criu/config.c       |  2 +-
 criu/cr-check.c     |  2 +-
 criu/cr-service.c   |  2 +-
 criu/crtools.c      |  8 ++++----
 criu/file-lock.c    |  4 ++--
 criu/files.c        |  2 +-
 criu/filesystems.c  |  7 +++----
 criu/lsm.c          |  2 +-
 criu/mount.c        | 11 +++++------
 criu/net.c          |  8 ++++----
 criu/proc_parse.c   |  6 +++---
 13 files changed, 31 insertions(+), 33 deletions(-)

diff --git a/criu/cgroup-props.c b/criu/cgroup-props.c
index 21f0ddea4..f2feb2ad7 100644
--- a/criu/cgroup-props.c
+++ b/criu/cgroup-props.c
@@ -88,7 +88,7 @@ static int cgp_handle_props(cgp_list_entry_t **p, int strategy)
 	cgp_list_entry_t *t;
 
 	list_for_each_entry(t, &cgp_list, list) {
-		if (strcmp(t->cgp.name, s->cgp.name))
+		if (STRNEQ(t->cgp.name, s->cgp.name))
 			continue;
 
 		pr_debug("%s \"%s\" controller properties\n",
diff --git a/criu/cgroup.c b/criu/cgroup.c
index 9d460188d..1699e8676 100644
--- a/criu/cgroup.c
+++ b/criu/cgroup.c
@@ -81,7 +81,7 @@ static bool cg_set_compare(struct cg_set *set, struct list_head *ctls, int what)
 		if (!c1 || !c2) /* Nowhere to move next */
 			return !c1 && !c2; /* Both lists scanned -- match */
 
-		if (strcmp(c1->name, c2->name))
+		if (STRNEQ(c1->name, c2->name))
 			return false;
 
 		switch (what) {
@@ -90,7 +90,7 @@ static bool cg_set_compare(struct cg_set *set, struct list_head *ctls, int what)
 			if (c1->cgns_prefix != c2->cgns_prefix)
 				return false;
 
-			if (strcmp(c1->path, c2->path))
+			if (STRNEQ(c1->path, c2->path))
 				return false;
 
 			break;
@@ -677,7 +677,7 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id, struct parasite_dump_
 			 */
 			list_for_each_entry(root, &root_cgset->ctls, l) {
 				list_for_each_entry(stray, &cs->ctls, l) {
-					if (strcmp(root->name, stray->name))
+					if (STRNEQ(root->name, stray->name))
 						continue;
 
 					if (strlen(stray->path) < root->cgns_prefix) {
@@ -1828,7 +1828,7 @@ static int rewrite_cgroup_roots(CgroupEntry *cge)
 			cgroup_contains(ctrl->cnames, ctrl->n_cnames,
 					o->controller, &ctrl_mask);
 			if (old_mask != ctrl_mask) {
-				if (newroot && strcmp(newroot, o->newroot)) {
+				if (newroot && STRNEQ(newroot, o->newroot)) {
 					pr_err("CG paths mismatch: %s %s\n",
 							newroot, o->newroot);
 					return -1;
diff --git a/criu/config.c b/criu/config.c
index 304fcb5f2..9590a67e9 100644
--- a/criu/config.c
+++ b/criu/config.c
@@ -781,7 +781,7 @@ int parse_options(int argc, char **argv, bool *usage_error,
 			break;
 		case 'V':
 			pr_msg("Version: %s\n", CRIU_VERSION);
-			if (strcmp(CRIU_GITID, "0"))
+			if (STRNEQ(CRIU_GITID, "0"))
 				pr_msg("GitID: %s\n", CRIU_GITID);
 			exit(0);
 		case 'h':
diff --git a/criu/cr-check.c b/criu/cr-check.c
index 1574099cd..d4dd47779 100644
--- a/criu/cr-check.c
+++ b/criu/cr-check.c
@@ -716,7 +716,7 @@ static unsigned long get_ring_len(unsigned long addr)
 
 		if (start == addr) {
 			fclose(maps);
-			if (strcmp(buf + tail, "/[aio] (deleted)\n"))
+			if (STRNEQ(buf + tail, "/[aio] (deleted)\n"))
 				goto notfound;
 
 			return end - start;
diff --git a/criu/cr-service.c b/criu/cr-service.c
index 231a37f30..09ac2e0fd 100644
--- a/criu/cr-service.c
+++ b/criu/cr-service.c
@@ -967,7 +967,7 @@ static int handle_version(int sk, CriuReq * msg)
 	/* This assumes we will always have a major and minor version */
 	version.major = CRIU_VERSION_MAJOR;
 	version.minor = CRIU_VERSION_MINOR;
-	if (strcmp(CRIU_GITID, "0")) {
+	if (STRNEQ(CRIU_GITID, "0")) {
 		version.gitid = CRIU_GITID;
 	}
 #ifdef CRIU_VERSION_SUBLEVEL
diff --git a/criu/crtools.c b/criu/crtools.c
index ecdc0a207..e47f2f2a6 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -138,7 +138,7 @@ int main(int argc, char *argv[], char *envp[])
 			goto usage;
 		}
 
-		if (strcmp(argv[optind], "restore")) {
+		if (STRNEQ(argv[optind], "restore")) {
 			pr_msg("Error: --exec-cmd is available for the restore command only\n");
 			goto usage;
 		}
@@ -155,7 +155,7 @@ int main(int argc, char *argv[], char *envp[])
 		opts.exec_cmd[argc - optind - 1] = NULL;
 	} else {
 		/* No subcommands except for cpuinfo and restore --exec-cmd */
-		if (strcmp(argv[optind], "cpuinfo") && has_sub_command) {
+		if (STRNEQ(argv[optind], "cpuinfo") && has_sub_command) {
 			pr_msg("Error: excessive parameter%s for command %s\n",
 				(argc - optind) > 2 ? "s" : "", argv[optind]);
 			goto usage;
@@ -163,7 +163,7 @@ int main(int argc, char *argv[], char *envp[])
 	}
 
 	/* We must not open imgs dir, if service is called */
-	if (strcmp(argv[optind], "service")) {
+	if (STRNEQ(argv[optind], "service")) {
 		ret = open_image_dir(opts.imgs_dir);
 		if (ret < 0)
 			return 1;
@@ -194,7 +194,7 @@ int main(int argc, char *argv[], char *envp[])
 		pr_debug("DEPRECATED ON\n");
 
 	if (!list_empty(&opts.inherit_fds)) {
-		if (strcmp(argv[optind], "restore")) {
+		if (STRNEQ(argv[optind], "restore")) {
 			pr_err("--inherit-fd is restore-only option\n");
 			return 1;
 		}
diff --git a/criu/file-lock.c b/criu/file-lock.c
index 8be7589df..9a9930d0f 100644
--- a/criu/file-lock.c
+++ b/criu/file-lock.c
@@ -195,7 +195,7 @@ static int lock_check_fd(int lfd, struct file_lock *fl)
 	} else {
 		/*
 		 * The ret == 0 means, that new lock doesn't conflict
-		 * with any others on the file. But since we do know, 
+		 * with any others on the file. But since we do know,
 		 * that there should be some other one (file is found
 		 * in /proc/locks), it means that the lock is already
 		 * on file pointed by fd.
@@ -223,7 +223,7 @@ static int lock_ofd_check_fd(int lfd, struct file_lock *fl)
 		.l_type   = F_WRLCK,
 		.l_start  = fl->start
 	};
-	if (strcmp(fl->end, "EOF")) {
+	if (STRNEQ(fl->end, "EOF")) {
 		unsigned long end;
 
 		ret = sscanf(fl->end, "%lu", &end);
diff --git a/criu/files.c b/criu/files.c
index 5124a50ad..0f024f96a 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -286,7 +286,7 @@ static int fixup_overlayfs(struct fd_parms *p, struct fd_link *link)
 	 * If the bug is present, the file path from /proc/<pid>/fd
 	 * does not include the mountpoint, so we prepend it ourselves.
 	 */
-	if (strcmp("./", m->mountpoint) != 0) {
+	if (STRNEQ("./", m->mountpoint) != 0) {
 		char buf[PATH_MAX];
 		int n;
 
diff --git a/criu/filesystems.c b/criu/filesystems.c
index d99cf3bf7..a371ada42 100644
--- a/criu/filesystems.c
+++ b/criu/filesystems.c
@@ -591,10 +591,9 @@ static int tracefs_parse(struct mount_info *pm)
 
 static bool cgroup_sb_equal(struct mount_info *a, struct mount_info *b)
 {
-	if (a->private && b->private &&
-			strcmp(a->private, b->private))
+	if (a->private && b->private && STRNEQ(a->private, b->private))
 		return false;
-	if (strcmp(a->options, b->options))
+	if (STRNEQ(a->options, b->options))
 		return false;
 
 	return true;
@@ -644,7 +643,7 @@ static bool btrfs_sb_equal(struct mount_info *a, struct mount_info *b)
 	if ((posa && !posb) || (!posa && posb))
 		return false;
 
-	if (posa && strcmp(posa, posb))
+	if (posa && STRNEQ(posa, posb))
 		return false;
 
 	return true;
diff --git a/criu/lsm.c b/criu/lsm.c
index c6e4e1b8f..a2e19ca86 100644
--- a/criu/lsm.c
+++ b/criu/lsm.c
@@ -188,7 +188,7 @@ int render_lsm_profile(char *profile, char **val)
 
 	switch (kdat.lsm) {
 	case LSMTYPE__APPARMOR:
-		if (strcmp(profile, "unconfined") != 0 && asprintf(val, "changeprofile %s", profile) < 0) {
+		if (STRNEQ(profile, "unconfined") && asprintf(val, "changeprofile %s", profile) < 0) {
 			pr_err("allocating lsm profile failed\n");
 			*val = NULL;
 			return -1;
diff --git a/criu/mount.c b/criu/mount.c
index 4a2169e9b..f6467ffef 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -275,7 +275,7 @@ dev_t phys_stat_resolve_dev(struct ns_id *ns, dev_t st_dev, const char *path)
 	 * superblock dev-id, in such case return device
 	 * obtained from mountinfo (ie subvolume0).
 	 */
-	return strcmp(m->fstype->name, "btrfs") ?
+	return STRNEQ(m->fstype->name, "btrfs") ?
 		MKKDEV(major(st_dev), minor(st_dev)) : m->s_dev;
 }
 
@@ -299,13 +299,13 @@ static bool mounts_sb_equal(struct mount_info *a, struct mount_info *b)
 	if (a->s_dev != b->s_dev)
 		return false;
 
-	if (strcmp(a->source, b->source) != 0)
+	if (STRNEQ(a->source, b->source) != 0)
 		return false;
 
 	if (a->fstype->sb_equal) /* :) */
 		return b->fstype->sb_equal(a, b);
 
-	if (strcmp(a->options, b->options))
+	if (STRNEQ(a->options, b->options))
 		return false;
 
 	return true;
@@ -318,7 +318,7 @@ static bool mounts_equal(struct mount_info *a, struct mount_info *b)
 {
 	if (!mounts_sb_equal(a, b))
 		return false;
-	if (strcmp(a->root, b->root))
+	if (STRNEQ(a->root, b->root))
 		return false;
 
 	return true;
@@ -366,8 +366,7 @@ static struct mount_info *mnt_build_ids_tree(struct mount_info *list, struct mou
 			pr_debug("Mountpoint %d (@%s) w/o parent %d\n",
 				 m->mnt_id, m->mountpoint, m->parent_mnt_id);
 
-			if (!mounts_sb_equal(root, m) ||
-			    strcmp(root->root, m->root)) {
+			if (!mounts_sb_equal(root, m) || STRNEQ(root->root, m->root)) {
 				pr_err("Nested mount namespaces with different "
 				       "roots %d (@%s %s) %d (@%s %s) are not supported yet\n",
 				       root->mnt_id, root->mountpoint, root->root,
diff --git a/criu/net.c b/criu/net.c
index 827c5eee8..a8868b667 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -234,7 +234,7 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto
 		 * it's restore
 		 */
 		if (def_conf && sysctl_entries_equal(conf[i], def_conf[i])
-				&& strcmp(devconfs[i], "mtu")) {
+				&& STRNEQ(devconfs[i], "mtu")) {
 			pr_debug("Skip %s/%s, coincides with default\n", tgt, devconfs[i]);
 			continue;
 		}
@@ -499,7 +499,7 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi,
 	for (i = 0; i < size6; i++) {
 		sysctl_entry__init(&confs6[i]);
 		netdev.conf6[i] = &confs6[i];
-		if (strcmp(devconfs6[i], "stable_secret")) {
+		if (STRNEQ(devconfs6[i], "stable_secret")) {
 			netdev.conf6[i]->type = SYSCTL_TYPE__CTL_32;
 		} else {
 			netdev.conf6[i]->type = SYSCTL_TYPE__CTL_STR;
@@ -786,7 +786,7 @@ static int dump_one_sit(struct ifinfomsg *ifi, char *kind,
 {
 	char *name;
 
-	if (strcmp(kind, "sit")) {
+	if (STRNEQ(kind, "sit")) {
 		pr_err("SIT device with %s kind\n", kind);
 		return -1;
 	}
@@ -1880,7 +1880,7 @@ static int dump_netns_conf(struct ns_id *ns, struct cr_imgset *fds)
 		sysctl_entry__init(&all_confs6[i]);
 		netns.def_conf6[i] = &def_confs6[i];
 		netns.all_conf6[i] = &all_confs6[i];
-		if (strcmp(devconfs6[i], "stable_secret")) {
+		if (STRNEQ(devconfs6[i], "stable_secret")) {
 			netns.def_conf6[i]->type = SYSCTL_TYPE__CTL_32;
 			netns.all_conf6[i]->type = SYSCTL_TYPE__CTL_32;
 		} else {
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 03debf622..9dd8574d4 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -2212,7 +2212,7 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
 
 			timer->spt.sival_ptr = NULL;
 			if (sscanf(pbuf, "%p", &timer->spt.sival_ptr) != 1 &&
-			    strcmp(pbuf, "(null)")) {
+			    STRNEQ(pbuf, "(null)")) {
 				pr_err("Unable to parse '%s'\n", pbuf);
 				goto err;
 			}
@@ -2428,7 +2428,7 @@ int parse_task_cgroup(int pid, struct parasite_dump_cgroup_args *args, struct li
 		list_for_each_entry(ext, retl, l) {
 			char *pos;
 
-			if (strcmp(ext->name, intern->name))
+			if (STRNEQ(ext->name, intern->name))
 				continue;
 
 			/* If the cgroup namespace was unshared at / (or there
@@ -2440,7 +2440,7 @@ int parse_task_cgroup(int pid, struct parasite_dump_cgroup_args *args, struct li
 
 			/* +1 here to chop off the leading / */
 			pos = ext->path + strlen(ext->path) - strlen(intern->path+1);
-			if (strcmp(pos, intern->path+1)) {
+			if (STRNEQ(pos, intern->path+1)) {
 				pr_err("invalid cgroup configuration, %s is not a suffix of %s\n", intern->path, ext->path);
 				ret = -1;
 				goto out;
-- 
2.20.1



More information about the CRIU mailing list