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 C873D138359 for ; Thu, 29 Oct 2020 16:16:54 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2300EE09BD; Thu, 29 Oct 2020 16:16:54 +0000 (UTC) Received: from mail-qv1-f67.google.com (mail-qv1-f67.google.com [209.85.219.67]) (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 1BBC9E09BD for ; Thu, 29 Oct 2020 16:16:54 +0000 (UTC) Received: by mail-qv1-f67.google.com with SMTP id ev17so1558028qvb.3 for ; Thu, 29 Oct 2020 09:16:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wpXDrYWISMUa0gxpCzXyXtaq9jHcEoKBXYBTt1y9EMw=; b=L9hcwrATMv7jGTJunZuc2b+Ntpx9eIH/o+DQaZQRNX4VFavF3cxiEB4+eekvUm+do3 v6BLrJ09ffwWRgbSocD2sVWyAohCJKO6JhyFt8BdcM0NGJ969xhbKIUfkhlGETQhg0rX hBT54sK5rsRRjhS6tn2xlbIjvStq1d5y+oH7M2wvBQJqqS0hG2toESdjlXzaQvyM1JEk sKi1xLdUNsJ3QxhjwkVnHIrsLg7838czfFTRnGqlnlvh2EVM3Z4ZC4MDgzvCLPnTKEvL M+s7z4xAfrxTLHrW1y11Zw0Ua2nY/l1yjH2EfJyMTaLDCAgf8F2bLxj1Lz1vFcAmlR3e 7HeQ== X-Gm-Message-State: AOAM532cZwKmgOznskzlYnW+P3fG97Y4lm5wQuCShtpIUTpttMALYdVv 0k5YvFQwA2p+22j1VRRZ+wYMLNG1YSM= X-Google-Smtp-Source: ABdhPJxTjnki97lgW3ir8eH4BwxRaZFvd9brmpHOeYmklDj1ByeGZ4zJdKJV4kiP86rP+3s9xg0ZHw== X-Received: by 2002:ad4:50a2:: with SMTP id d2mr3648369qvq.21.1603988213030; Thu, 29 Oct 2020 09:16:53 -0700 (PDT) Received: from localhost (2606-a000-131c-10bb-0000-0000-0000-1fc3.inf6.spectrum.com. [2606:a000:131c:10bb::1fc3]) by smtp.gmail.com with ESMTPSA id 67sm1317768qkd.14.2020.10.29.09.16.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 09:16:52 -0700 (PDT) From: Matt Turner To: gentoo-catalyst@lists.gentoo.org Cc: Matt Turner Subject: [gentoo-catalyst] [PATCH 10/12] catalyst: Remove kill_support_pids() Date: Thu, 29 Oct 2020 12:16:30 -0400 Message-Id: <20201029161632.146732-10-mattst88@gentoo.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029161632.146732-1-mattst88@gentoo.org> References: <20201029161632.146732-1-mattst88@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-catalyst@lists.gentoo.org Reply-to: gentoo-catalyst@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archives-Salt: c4e7b871-54c3-4720-92df-9e039ea3b2d5 X-Archives-Hash: 33cddcf8f2809065c5ff09307bdcced3 mount_namespaces(7) says A mount ceases to be a member of a peer group when either the mount is explicitly unmounted, or when the mount is implicitly unmounted because a mount namespace is removed (because it has no more member processes). Now that the build sequence is executed in its own mount namespace, the mounts are implicitly unmounted when the last process in the namespace dies, meaning we don't need to try any funny business around cleaning up processes in order to unmount. Signed-off-by: Matt Turner --- catalyst/base/stagebase.py | 30 ++------------ targets/support/kill-chroot-pids.sh | 62 ----------------------------- 2 files changed, 4 insertions(+), 88 deletions(-) delete mode 100755 targets/support/kill-chroot-pids.sh diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py index ec9a8f06..5fc11eae 100644 --- a/catalyst/base/stagebase.py +++ b/catalyst/base/stagebase.py @@ -638,17 +638,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 @@ -920,18 +909,10 @@ class StageBase(TargetBase, ClearBase, GenBase): try: cxt = libmount.Context(target=str(target)) cxt.umount() - except OSError: - log.warning('First attempt to unmount failed: %s', target) - log.warning('Killing any pids still running in the chroot') - - self.kill_chroot_pids() - - try: - cxt.umount() - except OSError as e: - umount_failed = True - log.warning("Couldn't umount: %s, %s", target, - e.strerror) + except OSError as e: + log.warning("Couldn't umount: %s, %s", target, + e.strerror) + umount_failed = True if umount_failed: # if any bind mounts really failed, then we need to raise @@ -1382,9 +1363,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 -- 2.26.2