Skip to content

Commit

Permalink
Automatically kill processes in bootstrap inner mount
Browse files Browse the repository at this point in the history
Minimal bug reproducer for this issue is:

$ mock --postinstall --isolation=simple https://github.com/rpm-software-management/mock-test-data/raw/main/daemontest-1-0.src.rpm
... successful build, mock exists ...
$ pgrep daemontest -a
41652 daemontest PID=41652

Fixes: #1165
Closes: #1166
  • Loading branch information
praiskup committed Aug 4, 2023
1 parent 5140394 commit bd38f5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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
15 changes: 15 additions & 0 deletions mock/py/mockbuild/mounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit bd38f5c

Please sign in to comment.