From: Christian Brauner Date: Wed, 20 Feb 2019 23:18:59 +0000 (+0100) Subject: attach: cleanup macros in_same_namespace X-Git-Tag: lxc-3.2.0~132^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3cc629fe9f703d867106de59c2d3b7e2ec84e0bb;p=thirdparty%2Flxc.git attach: cleanup macros in_same_namespace Signed-off-by: Christian Brauner --- diff --git a/src/lxc/attach.c b/src/lxc/attach.c index 202b15d07..199bf3876 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -157,7 +157,8 @@ static void lxc_proc_put_context_info(struct lxc_proc_context_info *ctx) */ static int in_same_namespace(pid_t pid1, pid_t pid2, const char *ns) { - int ns_fd1 = -1, ns_fd2 = -1, ret = -1; + __do_close_prot_errno int ns_fd1 = -1, ns_fd2 = -1; + int ret = -1; int saved_errno; struct stat ns_st1, ns_st2; @@ -169,42 +170,27 @@ static int in_same_namespace(pid_t pid1, pid_t pid2, const char *ns) if (errno == ENOENT) return -EINVAL; - goto out; + return -1; } ns_fd2 = lxc_preserve_ns(pid2, ns); if (ns_fd2 < 0) - goto out; + return -1; ret = fstat(ns_fd1, &ns_st1); if (ret < 0) - goto out; + return -1; ret = fstat(ns_fd2, &ns_st2); if (ret < 0) - goto out; + return -1; /* processes are in the same namespace */ - if ((ns_st1.st_dev == ns_st2.st_dev ) && (ns_st1.st_ino == ns_st2.st_ino)) { - ret = -EINVAL; - goto out; - } + if ((ns_st1.st_dev == ns_st2.st_dev) && (ns_st1.st_ino == ns_st2.st_ino)) + return -EINVAL; /* processes are in different namespaces */ - ret = ns_fd2; - ns_fd2 = -1; - -out: - saved_errno = errno; - - if (ns_fd1 >= 0) - close(ns_fd1); - - if (ns_fd2 >= 0) - close(ns_fd2); - - errno = saved_errno; - return ret; + return move_fd(ns_fd2); } static int lxc_attach_to_ns(pid_t pid, struct lxc_proc_context_info *ctx)