Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap inner mount orphan kill #1166

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mock/py/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
44 changes: 34 additions & 10 deletions mock/py/mockbuild/mounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,38 @@ class MountPoint(object):
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
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._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
return False

def _do_umount(self):
raise NotImplementedError

@traceLog()
def ismounted(self):
Expand Down Expand Up @@ -65,17 +97,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):
Expand Down Expand Up @@ -118,9 +145,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
Expand All @@ -132,7 +157,6 @@ def umount(self):
util.do(cmd)
except exception.Error:
return False
self.mounted = False
return True

def __repr__(self):
Expand Down