Skip to content

Commit

Permalink
attach: do not fail on non-existing namespaces
Browse files Browse the repository at this point in the history
Closes #1993.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Dec 4, 2017
1 parent 223e30c commit 134284c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/lxc/attach.c
Expand Up @@ -281,8 +281,15 @@ static int in_same_namespace(pid_t pid1, pid_t pid2, const char *ns)
struct stat ns_st1, ns_st2;

ns_fd1 = lxc_preserve_ns(pid1, ns);
if (ns_fd1 < 0)
if (ns_fd1 < 0) {
/* The kernel does not support this namespace. This is not an
* error.
*/
if (errno == ENOENT)
return -EINVAL;

goto out;
}

ns_fd2 = lxc_preserve_ns(pid2, ns);
if (ns_fd2 < 0)
Expand Down
3 changes: 2 additions & 1 deletion src/lxc/utils.c
Expand Up @@ -1906,8 +1906,9 @@ int lxc_preserve_ns(const int pid, const char *ns)
ret = snprintf(path, __NS_PATH_LEN, "/proc/%d/ns%s%s", pid,
!ns || strcmp(ns, "") == 0 ? "" : "/",
!ns || strcmp(ns, "") == 0 ? "" : ns);
errno = EFBIG;
if (ret < 0 || (size_t)ret >= __NS_PATH_LEN)
return -1;
return -EFBIG;

return open(path, O_RDONLY | O_CLOEXEC);
}
Expand Down

0 comments on commit 134284c

Please sign in to comment.