namespaces: nsenter: ignore nonexistent namespaces

If a particular kernel doesn't have namespace directories that
libcontainer tries to attain during nsenter(), ignore the error (this is
consistent with the previous implementation of nsenter()).

Docker-DCO-1.1-Signed-off-by: Aleksa Sarai <cyphar@cyphar.com> (github: cyphar)
This commit is contained in:
Aleksa Sarai 2014-07-24 17:34:00 +10:00 committed by maebashi
parent 16f939a958
commit 01a7f19afe
1 changed files with 4 additions and 0 deletions

View File

@ -135,6 +135,10 @@ void nsenter() {
snprintf(buf, PATH_MAX - 1, "%s%s", ns_dir, namespaces[i]);
int fd = open(buf, O_RDONLY);
if (fd == -1) {
// Ignore nonexistent namespaces.
if (errno == ENOENT)
continue;
fprintf(stderr, "nsenter: Failed to open ns file \"%s\" for ns \"%s\" with error: \"%s\"\n", buf, namespaces[i], strerror(errno));
exit(1);
}