From 58a9a5c50ebd8415162251ce9235835dca3f6a37 Mon Sep 17 00:00:00 2001 From: Colin Walters <walters@verbum.org> Date: Tue, 28 Jul 2015 16:40:29 -0400 Subject: [PATCH] libcontainer: Fall back to noop if / is not a mountpoint Trying to change the mount namespace was breaking in mock, which just uses plain chroot. --- glnx-libcontainer.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/glnx-libcontainer.c b/glnx-libcontainer.c index 49fa0955b..3f500073f 100644 --- a/glnx-libcontainer.c +++ b/glnx-libcontainer.c @@ -212,10 +212,24 @@ glnx_libcontainer_run_in_root (const char *dest, if (container_available) { if (mount (NULL, "/", "none", MS_PRIVATE | MS_REC, NULL) != 0) - _perror_fatal ("mount: "); + { + if (errno == EINVAL) + { + /* Ok, we may be inside a mock chroot or the like. In + * that case, let's just fall back to not + * containerizing. + */ + container_available = FALSE; + } + else + _perror_fatal ("mount: "); + } - if (mount (NULL, "/", "none", MS_PRIVATE | MS_REMOUNT | MS_NOSUID, NULL) != 0) - _perror_fatal ("mount (MS_NOSUID): "); + if (container_available) + { + if (mount (NULL, "/", "none", MS_PRIVATE | MS_REMOUNT | MS_NOSUID, NULL) != 0) + _perror_fatal ("mount (MS_NOSUID): "); + } } if (chdir (dest) != 0) -- GitLab