From 58f082f973a7de1742eb3fce6e1124553df86d74 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Thu, 27 Jul 2023 08:29:29 +0200 Subject: [PATCH 1/2] Move the umount() call to the parent Mount class This allows us to do some generic logic on one place, like setting the internal object state. --- mock/py/mockbuild/mounts.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/mock/py/mockbuild/mounts.py b/mock/py/mockbuild/mounts.py index 72b94a2e7..91e328045 100644 --- a/mock/py/mockbuild/mounts.py +++ b/mock/py/mockbuild/mounts.py @@ -18,6 +18,23 @@ class MountPoint(object): def __init__(self, mountsource, mountpath): self.mountpath = mountpath self.mountsource = mountsource + self.mounted = None + + @traceLog() + # pylint: disable=unused-argument + def umount(self, force=False, nowarn=False): + """ + Return None if not mounted, and True if successfully umounted + """ + if not self.mounted: + return None + if self._do_umount(): + self.mounted = False + return True + return False + + def _do_umount(self): + raise NotImplementedError @traceLog() def ismounted(self): @@ -65,17 +82,12 @@ def mount(self): self.mounted = True return True - @traceLog() - # pylint: disable=unused-argument - def umount(self, force=False, nowarn=False): - if not self.mounted: - return None + def _do_umount(self): cmd = ['/bin/umount', '-n', '-l', self.path] try: util.do(cmd) except exception.Error: return False - self.mounted = False return True def __repr__(self): @@ -118,9 +130,7 @@ def mount(self): return True @traceLog() - def umount(self): - if not self.mounted: - return None + def _do_umount(self): cmd = ['/bin/umount', '-n'] if self.recursive: # The mount is busy because of the submounts - a lazy unmount @@ -132,7 +142,6 @@ def umount(self): util.do(cmd) except exception.Error: return False - self.mounted = False return True def __repr__(self): From ae495582787e620a243edde3e2a030ce400c06d9 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Thu, 27 Jul 2023 08:40:23 +0200 Subject: [PATCH 2/2] Automatically kill processes in bootstrap inner mount Fixes: #1165 --- mock/py/mock.py | 2 +- mock/py/mockbuild/mounts.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mock/py/mock.py b/mock/py/mock.py index 9c303c67b..0f5e1a2dd 100755 --- a/mock/py/mock.py +++ b/mock/py/mock.py @@ -800,7 +800,7 @@ def main(): options="private")) buildroot.mounts.bootstrap_mounts.append( BindMountPoint(buildroot.make_chroot_path(), inner_mount, - recursive=True, options="private")) + recursive=True, options="private").treat_as_chroot()) signal.signal(signal.SIGTERM, partial(handle_signals, buildroot)) signal.signal(signal.SIGPIPE, partial(handle_signals, buildroot)) diff --git a/mock/py/mockbuild/mounts.py b/mock/py/mockbuild/mounts.py index 91e328045..40d38c657 100644 --- a/mock/py/mockbuild/mounts.py +++ b/mock/py/mockbuild/mounts.py @@ -19,6 +19,15 @@ def __init__(self, mountsource, mountpath): self.mountpath = mountpath self.mountsource = mountsource self.mounted = None + self._is_chroot = False + + def treat_as_chroot(self): + """ + If we use this directory as chroot, we might want to do special + actions while mounting and unmounting. + """ + self._is_chroot = True + return self @traceLog() # pylint: disable=unused-argument @@ -28,6 +37,12 @@ def umount(self, force=False, nowarn=False): """ if not self.mounted: return None + + if self._is_chroot: + # Don't keep background processes running with unmounted + # /proc/self/root directory. + util.orphansKill(self.mountpath) + if self._do_umount(): self.mounted = False return True