From b87ee3121b232c370742359c26d571736057cefc Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 9 Mar 2020 10:59:14 +0100 Subject: [PATCH] tree-wide: more cleanup macros Signed-off-by: Christian Brauner --- src/lxc/attach.c | 3 ++- src/lxc/conf.c | 2 +- src/lxc/start.c | 16 +++++++--------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/lxc/attach.c b/src/lxc/attach.c index 9eb794449..26fd753ec 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -92,7 +92,8 @@ static struct lxc_proc_context_info *lxc_proc_get_context_info(pid_t pid) info->lsm_label = lsm_process_label_get(pid); info->ns_inherited = 0; - memset(info->ns_fd, -1, sizeof(int) * LXC_NS_MAX); + for (int i = 0; i < LXC_NS_MAX; i++) + info->ns_fd[i] = -EBADF; return move_ptr(info); } diff --git a/src/lxc/conf.c b/src/lxc/conf.c index a8d2ffadf..41127d6bd 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -3547,7 +3547,7 @@ int lxc_setup(struct lxc_handler *handler) return -1; } - if (handler->nsfd[LXC_NS_UTS] == -1) { + if (handler->nsfd[LXC_NS_UTS] == -EBADF) { ret = setup_utsname(lxc_conf->utsname); if (ret < 0) { ERROR("Failed to setup the utsname %s", name); diff --git a/src/lxc/start.c b/src/lxc/start.c index 9e8069b2a..dad4ff984 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -122,9 +122,9 @@ static int lxc_try_preserve_ns(const int pid, const char *ns) errno, "Failed to preserve %s namespace", ns); - return log_error_errno(-EOPNOTSUPP, - errno, "Kernel does not support preserving %s namespaces", - ns); + return log_warn_errno(-EOPNOTSUPP, + errno, "Kernel does not support preserving %s namespaces", + ns); } return fd; @@ -646,7 +646,7 @@ void lxc_free_handler(struct lxc_handler *handler) if (handler->conf && handler->conf->reboot == REBOOT_NONE) if (handler->conf->maincmd_fd >= 0) - lxc_abstract_unix_close(handler->conf->maincmd_fd); + close_prot_errno_disarm(handler->conf->maincmd_fd); if (handler->monitor_status_fd >= 0) close_prot_errno_disarm(handler->monitor_status_fd); @@ -892,8 +892,7 @@ out_aborting: (void)lxc_set_state(name, handler, ABORTING); out_close_maincmd_fd: - lxc_abstract_unix_close(conf->maincmd_fd); - conf->maincmd_fd = -1; + close_prot_errno_disarm(conf->maincmd_fd); return -1; } @@ -981,8 +980,7 @@ void lxc_fini(const char *name, struct lxc_handler *handler) * the command socket causing a new process to get ECONNREFUSED * because we haven't yet closed the command socket. */ - lxc_abstract_unix_close(handler->conf->maincmd_fd); - handler->conf->maincmd_fd = -EBADF; + close_prot_errno_disarm(handler->conf->maincmd_fd); TRACE("Closed command socket"); /* This function will try to connect to the legacy lxc-monitord @@ -1641,7 +1639,7 @@ static int lxc_spawn(struct lxc_handler *handler) */ if (!wants_to_map_ids) { handler->pinfd = pin_rootfs(conf->rootfs.path); - if (handler->pinfd == -1) + if (handler->pinfd == -EBADF) INFO("Failed to pin the rootfs for container \"%s\"", handler->name); } -- 2.47.2