confile_utils: cleanup lxc_inherit_namespace()

parent 60e7645a
...@@ -878,8 +878,9 @@ static int lxc_container_name_to_pid(const char *lxcname_or_pid, ...@@ -878,8 +878,9 @@ static int lxc_container_name_to_pid(const char *lxcname_or_pid,
int lxc_inherit_namespace(const char *nsfd_path, const char *lxcpath, int lxc_inherit_namespace(const char *nsfd_path, const char *lxcpath,
const char *namespace) const char *namespace)
{ {
__do_free char *dup = NULL;
int fd, pid; int fd, pid;
char *dup, *lastslash; char *lastslash;
if (nsfd_path[0] == '/') { if (nsfd_path[0] == '/') {
return open(nsfd_path, O_RDONLY | O_CLOEXEC); return open(nsfd_path, O_RDONLY | O_CLOEXEC);
...@@ -889,21 +890,20 @@ int lxc_inherit_namespace(const char *nsfd_path, const char *lxcpath, ...@@ -889,21 +890,20 @@ int lxc_inherit_namespace(const char *nsfd_path, const char *lxcpath,
if (lastslash) { if (lastslash) {
dup = strdup(nsfd_path); dup = strdup(nsfd_path);
if (!dup) if (!dup)
return -1; return ret_errno(ENOMEM);
dup[lastslash - nsfd_path] = '\0'; dup[lastslash - nsfd_path] = '\0';
pid = lxc_container_name_to_pid(lastslash + 1, dup); lxcpath = lastslash + 1;
free(dup); nsfd_path = lastslash + 1;
} else {
pid = lxc_container_name_to_pid(nsfd_path, lxcpath);
} }
pid = lxc_container_name_to_pid(nsfd_path, lxcpath);
if (pid < 0) if (pid < 0)
return -1; return pid;
fd = lxc_preserve_ns(pid, namespace); fd = lxc_preserve_ns(pid, namespace);
if (fd < 0) if (fd < 0)
return -1; return -errno;
return fd; return fd;
} }
......
...@@ -1372,10 +1372,8 @@ int lxc_preserve_ns(const int pid, const char *ns) ...@@ -1372,10 +1372,8 @@ int lxc_preserve_ns(const int pid, const char *ns)
ret = snprintf(path, __NS_PATH_LEN, "/proc/%d/ns%s%s", pid, ret = snprintf(path, __NS_PATH_LEN, "/proc/%d/ns%s%s", pid,
!ns || strcmp(ns, "") == 0 ? "" : "/", !ns || strcmp(ns, "") == 0 ? "" : "/",
!ns || strcmp(ns, "") == 0 ? "" : ns); !ns || strcmp(ns, "") == 0 ? "" : ns);
if (ret < 0 || (size_t)ret >= __NS_PATH_LEN) { if (ret < 0 || (size_t)ret >= __NS_PATH_LEN)
errno = EFBIG; return ret_errno(EIO);
return -1;
}
return open(path, O_RDONLY | O_CLOEXEC); return open(path, O_RDONLY | O_CLOEXEC);
} }
......
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