]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
attach: cleanup macros in_same_namespace
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 20 Feb 2019 23:18:59 +0000 (00:18 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 20 Feb 2019 23:19:21 +0000 (00:19 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/attach.c

index 202b15d07e88d4004afa43c449184bc65d227195..199bf3876ec008bc02b898aa7d32994a3335740b 100644 (file)
@@ -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)