From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 8788A13835A for ; Wed, 27 May 2020 06:23:02 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BC6E4E0990; Wed, 27 May 2020 06:23:01 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 9155BE0990 for ; Wed, 27 May 2020 06:23:01 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6CCD334EE76 for ; Wed, 27 May 2020 06:23:00 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 151D721E for ; Wed, 27 May 2020 06:22:59 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1590560571.d11d5eb2cf32fc09c323871c2ca6fcb6b468f822.mattst88@gentoo> Subject: [gentoo-commits] proj/catalyst:wip/mattst88 commit in: targets/support/, catalyst/base/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/base/stagebase.py targets/support/kill-chroot-pids.sh X-VCS-Directories: catalyst/base/ targets/support/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: d11d5eb2cf32fc09c323871c2ca6fcb6b468f822 X-VCS-Branch: wip/mattst88 Date: Wed, 27 May 2020 06:22:59 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 00f02948-f969-477c-873d-918da67782f1 X-Archives-Hash: 32f43ee049ef0dad50324eb8ab60f8f1 commit: d11d5eb2cf32fc09c323871c2ca6fcb6b468f822 Author: Matt Turner gentoo org> AuthorDate: Thu May 21 22:37:29 2020 +0000 Commit: Matt Turner gentoo org> CommitDate: Wed May 27 06:22:51 2020 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=d11d5eb2 catalyst: Clean up unbind() function Does a couple of things: - drops log.notice -> log.warning - Removes the kill_chroot_pids support code since .... namespaces? Signed-off-by: Matt Turner gentoo.org> catalyst/base/stagebase.py | 45 +++++++-------------------- targets/support/kill-chroot-pids.sh | 62 ------------------------------------- 2 files changed, 12 insertions(+), 95 deletions(-) diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py index aa5cafd0..d92f3ffb 100644 --- a/catalyst/base/stagebase.py +++ b/catalyst/base/stagebase.py @@ -625,17 +625,6 @@ class StageBase(TargetBase, ClearBase, GenBase): assert self.settings[verify] == "blake2" self.settings.setdefault("gk_mainargs", []).append("--b2sum") - def kill_chroot_pids(self): - log.info('Checking for processes running in chroot and killing them.') - - # Force environment variables to be exported so script can see them - self.setup_environment() - - killcmd = normpath(self.settings["sharedir"] + - self.settings["shdir"] + "/support/kill-chroot-pids.sh") - if os.path.exists(killcmd): - cmd([killcmd], env=self.env) - def mount_safety_check(self): """ Check and verify that none of our paths in mypath are mounted. We don't @@ -886,35 +875,28 @@ class StageBase(TargetBase, ClearBase, GenBase): raise CatalystError def unbind(self): - ouch = 0 - mypath = self.settings["chroot_path"] + chroot_path = self.settings["chroot_path"] + umount_failed = False # Unmount in reverse order - for x in [x for x in reversed(self.mount) if self.mount[x]['enable']]: - target = normpath(mypath + self.mount[x]['target']) - if not os.path.exists(target): - log.notice('%s does not exist. Skipping', target) + for target in [Path(chroot_path + self.mount[x]['target']) + for x in reversed(self.mount) + if self.mount[x]['enable']]: + if not target.exists(): + log.debug('%s does not exist. Skipping', target) continue if not ismount(target): - log.notice('%s is not a mount point. Skipping', target) + log.debug('%s is not a mount point. Skipping', target) continue try: umount(target) - except CatalystError: - log.warning('First attempt to unmount failed: %s', target) - log.warning('Killing any pids still running in the chroot') - - self.kill_chroot_pids() - - try: - umount(target) - except CatalystError: - ouch = 1 - log.warning("Couldn't umount bind mount: %s", target) + except OSError as e: + log.warning("Couldn't umount bind mount: %s", target) + umount_failed = True - if ouch: + if umount_failed: # if any bind mounts really failed, then we need to raise # this to potentially prevent an upcoming bash stage cleanup script # from wiping our bind mounts. @@ -1307,9 +1289,6 @@ class StageBase(TargetBase, ClearBase, GenBase): def run(self): self.chroot_lock.write_lock() - # Kill any pids in the chroot - self.kill_chroot_pids() - # Check for mounts right away and abort if we cannot unmount them self.mount_safety_check() diff --git a/targets/support/kill-chroot-pids.sh b/targets/support/kill-chroot-pids.sh deleted file mode 100755 index ea8ee402..00000000 --- a/targets/support/kill-chroot-pids.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash -# Script to kill processes found running in the chroot. - -if [ "${clst_chroot_path}" == "/" ] -then - echo "Aborting .... clst_chroot_path is set to /" - echo "This is very dangerous" - exit 1 -fi - -if [ "${clst_chroot_path}" == "" ] -then - echo "Aborting .... clst_chroot_path is NOT set" - echo "This is very dangerous" - exit 1 -fi - -j=0 -declare -a pids -# Get files and dirs in /proc -for i in `ls /proc` -do - # Test for directories - if [ -d /proc/$i ] - then - # Search for exe containing string inside ${clst_chroot_path} - ls -la --color=never /proc/$i 2>&1 |grep exe|grep ${clst_chroot_path} > /dev/null - - # If found - if [ $? == 0 ] - then - # Assign the pid into the pids array - pids[$j]=$i - j=$(($j+1)) - fi - fi -done - -if [ ${j} -gt 0 ] -then - echo - echo "Killing process(es)" - echo "pid: process name" - for pid in ${pids[@]} - do - P_NAME=$(ls -la --color=never /proc/${pid} 2>&1 |grep exe|grep ${clst_chroot_path}|awk '{print $11}') - echo ${pid}: ${P_NAME} - done - echo - echo "Press Ctrl-C within 10 seconds to abort" - - sleep 10 - - for pid in ${pids[@]} - do - kill -9 ${pid} - done - - # Small sleep here to give the process(es) a chance to die before running unbind again. - sleep 5 - -fi