From: Christian Brauner Date: Mon, 4 Dec 2017 11:26:55 +0000 (+0100) Subject: attach: do not fail on non-existing namespaces X-Git-Tag: lxc-2.0.10~526 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4feff04ae3e3b885a334a737b62521a4fe8db113;p=thirdparty%2Flxc.git attach: do not fail on non-existing namespaces Closes #1993. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/attach.c b/src/lxc/attach.c index 611432416..4ccf5c4a5 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -273,8 +273,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) diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 936603d82..148f23429 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -1964,8 +1964,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); }