]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
namespaces: allow a pathname to a nsfd for namespace to share 2971/head
authorSerge Hallyn <shallyn@cisco.com>
Thu, 2 May 2019 01:17:23 +0000 (18:17 -0700)
committerSerge Hallyn <shallyn@cisco.com>
Thu, 2 May 2019 13:10:15 +0000 (06:10 -0700)
Signed-off-by: Serge Hallyn <shallyn@cisco.com>
src/lxc/confile_utils.c

index 5bceb96bdc6b836090076190f05433e2eae05558..a43b165ba1f607d2870ceb64a2d60066f85f3021 100644 (file)
@@ -859,23 +859,27 @@ static int lxc_container_name_to_pid(const char *lxcname_or_pid,
        return pid;
 }
 
-int lxc_inherit_namespace(const char *lxcname_or_pid, const char *lxcpath,
+int lxc_inherit_namespace(const char *nsfd_path, const char *lxcpath,
                          const char *namespace)
 {
        int fd, pid;
        char *dup, *lastslash;
 
-       lastslash = strrchr(lxcname_or_pid, '/');
+       if (nsfd_path[0] == '/') {
+               return open(nsfd_path, O_RDONLY | O_CLOEXEC);
+       }
+
+       lastslash = strrchr(nsfd_path, '/');
        if (lastslash) {
-               dup = strdup(lxcname_or_pid);
+               dup = strdup(nsfd_path);
                if (!dup)
                        return -1;
 
-               dup[lastslash - lxcname_or_pid] = '\0';
+               dup[lastslash - nsfd_path] = '\0';
                pid = lxc_container_name_to_pid(lastslash + 1, dup);
                free(dup);
        } else {
-               pid = lxc_container_name_to_pid(lxcname_or_pid, lxcpath);
+               pid = lxc_container_name_to_pid(nsfd_path, lxcpath);
        }
 
        if (pid < 0)