lxccontainer: convert to strequal()

parent 925f4773
...@@ -663,7 +663,7 @@ static bool do_lxcapi_load_config(struct lxc_container *c, const char *alt_file) ...@@ -663,7 +663,7 @@ static bool do_lxcapi_load_config(struct lxc_container *c, const char *alt_file)
* need to lock the in-memory container. If loading the container's * need to lock the in-memory container. If loading the container's
* config file, take the disk lock. * config file, take the disk lock.
*/ */
if (strcmp(fname, c->configfile) == 0) if (strequal(fname, c->configfile))
need_disklock = true; need_disklock = true;
if (need_disklock) if (need_disklock)
...@@ -744,10 +744,10 @@ static bool am_single_threaded(void) ...@@ -744,10 +744,10 @@ static bool am_single_threaded(void)
return false; return false;
while ((direntp = readdir(dir))) { while ((direntp = readdir(dir))) {
if (strcmp(direntp->d_name, ".") == 0) if (strequal(direntp->d_name, "."))
continue; continue;
if (strcmp(direntp->d_name, "..") == 0) if (strequal(direntp->d_name, ".."))
continue; continue;
count++; count++;
...@@ -1363,15 +1363,15 @@ static bool create_run_template(struct lxc_container *c, char *tpath, ...@@ -1363,15 +1363,15 @@ static bool create_run_template(struct lxc_container *c, char *tpath,
SYSERROR("Failed to recursively turn root mount tree into dependent mount. Continuing..."); SYSERROR("Failed to recursively turn root mount tree into dependent mount. Continuing...");
} }
if (strcmp(bdev->type, "dir") != 0 && strcmp(bdev->type, "btrfs") != 0) { if (!strequal(bdev->type, "dir") && !strequal(bdev->type, "btrfs")) {
if (euid != 0) { if (euid != 0) {
ERROR("Unprivileged users can only create " ERROR("Unprivileged users can only create "
"btrfs and directory-backed containers"); "btrfs and directory-backed containers");
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
if (strcmp(bdev->type, "overlay") == 0 || if (strequal(bdev->type, "overlay") ||
strcmp(bdev->type, "overlayfs") == 0) { strequal(bdev->type, "overlayfs")) {
/* If we create an overlay container we need to /* If we create an overlay container we need to
* rsync the contents into * rsync the contents into
* <container-path>/<container-name>/rootfs. * <container-path>/<container-name>/rootfs.
...@@ -2191,13 +2191,13 @@ out: ...@@ -2191,13 +2191,13 @@ out:
static void do_clear_unexp_config_line(struct lxc_conf *conf, const char *key) static void do_clear_unexp_config_line(struct lxc_conf *conf, const char *key)
{ {
if (!strcmp(key, "lxc.cgroup")) if (strequal(key, "lxc.cgroup"))
return clear_unexp_config_line(conf, key, true); return clear_unexp_config_line(conf, key, true);
if (!strcmp(key, "lxc.network")) if (strequal(key, "lxc.network"))
return clear_unexp_config_line(conf, key, true); return clear_unexp_config_line(conf, key, true);
if (!strcmp(key, "lxc.net")) if (strequal(key, "lxc.net"))
return clear_unexp_config_line(conf, key, true); return clear_unexp_config_line(conf, key, true);
/* Clear a network with a specific index. */ /* Clear a network with a specific index. */
...@@ -2211,7 +2211,7 @@ static void do_clear_unexp_config_line(struct lxc_conf *conf, const char *key) ...@@ -2211,7 +2211,7 @@ static void do_clear_unexp_config_line(struct lxc_conf *conf, const char *key)
return clear_unexp_config_line(conf, key, true); return clear_unexp_config_line(conf, key, true);
} }
if (!strcmp(key, "lxc.hook")) if (strequal(key, "lxc.hook"))
return clear_unexp_config_line(conf, key, true); return clear_unexp_config_line(conf, key, true);
return clear_unexp_config_line(conf, key, false); return clear_unexp_config_line(conf, key, false);
...@@ -2480,12 +2480,12 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface, ...@@ -2480,12 +2480,12 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface,
#pragma GCC diagnostic ignored "-Wcast-align" #pragma GCC diagnostic ignored "-Wcast-align"
if (ifa->ifa_addr->sa_family == AF_INET) { if (ifa->ifa_addr->sa_family == AF_INET) {
if (family && strcmp(family, "inet")) if (family && !strequal(family, "inet"))
continue; continue;
address_ptr_tmp = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; address_ptr_tmp = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
} else { } else {
if (family && strcmp(family, "inet6")) if (family && !strequal(family, "inet6"))
continue; continue;
if (((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_scope_id != scope) if (((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_scope_id != scope)
...@@ -2496,9 +2496,9 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface, ...@@ -2496,9 +2496,9 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface,
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
if (interface && strcmp(interface, ifa->ifa_name)) if (interface && !strequal(interface, ifa->ifa_name))
continue; continue;
else if (!interface && strcmp("lo", ifa->ifa_name) == 0) else if (!interface && strequal("lo", ifa->ifa_name))
continue; continue;
address_ptr = (char *)inet_ntop(ifa->ifa_addr->sa_family, address_ptr_tmp, address_ptr = (char *)inet_ntop(ifa->ifa_addr->sa_family, address_ptr_tmp,
...@@ -2655,7 +2655,7 @@ static bool do_lxcapi_save_config(struct lxc_container *c, const char *alt_file) ...@@ -2655,7 +2655,7 @@ static bool do_lxcapi_save_config(struct lxc_container *c, const char *alt_file)
* Otherwise just take the memlock to protect the struct lxc_container * Otherwise just take the memlock to protect the struct lxc_container
* while we're traversing it. * while we're traversing it.
*/ */
if (strcmp(c->configfile, alt_file) == 0) if (strequal(c->configfile, alt_file))
need_disklock = true; need_disklock = true;
if (need_disklock) if (need_disklock)
...@@ -2905,10 +2905,10 @@ static bool has_snapshots(struct lxc_container *c) ...@@ -2905,10 +2905,10 @@ static bool has_snapshots(struct lxc_container *c)
return false; return false;
while ((direntp = readdir(dir))) { while ((direntp = readdir(dir))) {
if (!strcmp(direntp->d_name, ".")) if (strequal(direntp->d_name, "."))
continue; continue;
if (!strcmp(direntp->d_name, "..")) if (strequal(direntp->d_name, ".."))
continue; continue;
count++; count++;
break; break;
...@@ -3040,8 +3040,8 @@ static bool container_destroy(struct lxc_container *c, ...@@ -3040,8 +3040,8 @@ static bool container_destroy(struct lxc_container *c,
/* For an overlay container the rootfs is considered immutable and /* For an overlay container the rootfs is considered immutable and
* cannot be removed when restoring from a snapshot. * cannot be removed when restoring from a snapshot.
*/ */
if (storage && (!strcmp(storage->type, "overlay") || if (storage && (strequal(storage->type, "overlay") ||
!strcmp(storage->type, "overlayfs")) && strequal(storage->type, "overlayfs")) &&
(storage->flags & LXC_STORAGE_INTERNAL_OVERLAY_RESTORE)) { (storage->flags & LXC_STORAGE_INTERNAL_OVERLAY_RESTORE)) {
ret = strnprintf(path, len, "%s/%s/%s", p1, c->name, LXC_CONFIG_FNAME); ret = strnprintf(path, len, "%s/%s/%s", p1, c->name, LXC_CONFIG_FNAME);
if (ret < 0) if (ret < 0)
...@@ -3674,7 +3674,7 @@ static int clone_update_rootfs(struct clone_update_data *data) ...@@ -3674,7 +3674,7 @@ static int clone_update_rootfs(struct clone_update_data *data)
if (!bdev) if (!bdev)
return -1; return -1;
if (strcmp(bdev->type, "dir") != 0) { if (!strequal(bdev->type, "dir")) {
if (unshare(CLONE_NEWNS) < 0) { if (unshare(CLONE_NEWNS) < 0) {
ERROR("error unsharing mounts"); ERROR("error unsharing mounts");
storage_put(bdev); storage_put(bdev);
...@@ -4322,10 +4322,10 @@ static int do_lxcapi_snapshot_list(struct lxc_container *c, struct lxc_snapshot ...@@ -4322,10 +4322,10 @@ static int do_lxcapi_snapshot_list(struct lxc_container *c, struct lxc_snapshot
} }
while ((direntp = readdir(dir))) { while ((direntp = readdir(dir))) {
if (!strcmp(direntp->d_name, ".")) if (strequal(direntp->d_name, "."))
continue; continue;
if (!strcmp(direntp->d_name, "..")) if (strequal(direntp->d_name, ".."))
continue; continue;
ret = strnprintf(path2, sizeof(path2), "%s/%s/%s", snappath, direntp->d_name, LXC_CONFIG_FNAME); ret = strnprintf(path2, sizeof(path2), "%s/%s/%s", snappath, direntp->d_name, LXC_CONFIG_FNAME);
...@@ -4403,7 +4403,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap ...@@ -4403,7 +4403,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
* internal flag along to communicate this to various parts of the * internal flag along to communicate this to various parts of the
* codebase. * codebase.
*/ */
if (!strcmp(bdev->type, "overlay") || !strcmp(bdev->type, "overlayfs")) if (strequal(bdev->type, "overlay") || strequal(bdev->type, "overlayfs"))
bdev->flags |= LXC_STORAGE_INTERNAL_OVERLAY_RESTORE; bdev->flags |= LXC_STORAGE_INTERNAL_OVERLAY_RESTORE;
if (!newname) if (!newname)
...@@ -4426,7 +4426,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap ...@@ -4426,7 +4426,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
return false; return false;
} }
if (!strcmp(c->name, newname)) { if (strequal(c->name, newname)) {
if (!container_destroy(c, bdev)) { if (!container_destroy(c, bdev)) {
ERROR("Could not destroy existing container %s", newname); ERROR("Could not destroy existing container %s", newname);
lxc_container_put(snap); lxc_container_put(snap);
...@@ -4435,10 +4435,10 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap ...@@ -4435,10 +4435,10 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
} }
} }
if (strcmp(bdev->type, "dir") != 0 && strcmp(bdev->type, "loop") != 0) if (!strequal(bdev->type, "dir") && !strequal(bdev->type, "loop"))
flags = LXC_CLONE_SNAPSHOT | LXC_CLONE_MAYBE_SNAPSHOT; flags = LXC_CLONE_SNAPSHOT | LXC_CLONE_MAYBE_SNAPSHOT;
if (!strcmp(bdev->type, "overlay") || !strcmp(bdev->type, "overlayfs")) if (strequal(bdev->type, "overlay") || strequal(bdev->type, "overlayfs"))
flags |= LXC_STORAGE_INTERNAL_OVERLAY_RESTORE; flags |= LXC_STORAGE_INTERNAL_OVERLAY_RESTORE;
rest = lxcapi_clone(snap, newname, c->config_path, flags, bdev->type, rest = lxcapi_clone(snap, newname, c->config_path, flags, bdev->type,
...@@ -4494,10 +4494,10 @@ static bool remove_all_snapshots(const char *path) ...@@ -4494,10 +4494,10 @@ static bool remove_all_snapshots(const char *path)
} }
while ((direntp = readdir(dir))) { while ((direntp = readdir(dir))) {
if (!strcmp(direntp->d_name, ".")) if (strequal(direntp->d_name, "."))
continue; continue;
if (!strcmp(direntp->d_name, "..")) if (strequal(direntp->d_name, ".."))
continue; continue;
if (!do_snapshot_destroy(direntp->d_name, path)) { if (!do_snapshot_destroy(direntp->d_name, path)) {
...@@ -5033,7 +5033,7 @@ static int do_lxcapi_mount(struct lxc_container *c, const char *source, ...@@ -5033,7 +5033,7 @@ static int do_lxcapi_mount(struct lxc_container *c, const char *source,
} }
/* Create a temporary file / dir under the shared mountpoint */ /* Create a temporary file / dir under the shared mountpoint */
if (!source || strcmp(source, "") == 0) { if (!source || strequal(source, "")) {
/* If source is not specified, maybe we want to mount a filesystem? */ /* If source is not specified, maybe we want to mount a filesystem? */
sb.st_mode = S_IFDIR; sb.st_mode = S_IFDIR;
} else { } else {
...@@ -5767,7 +5767,7 @@ bool lxc_has_api_extension(const char *extension) ...@@ -5767,7 +5767,7 @@ bool lxc_has_api_extension(const char *extension)
return true; return true;
for (size_t i = 0; i < nr_api_extensions; i++) for (size_t i = 0; i < nr_api_extensions; i++)
if (strcmp(api_extensions[i], extension) == 0) if (strequal(api_extensions[i], extension))
return true; return true;
return false; return false;
......
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