Gentoo Archives: gentoo-commits

From: Matt Turner <mattst88@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/catalyst:pending/mattst88 commit in: targets/support/, catalyst/base/
Date: Thu, 29 Oct 2020 16:14:31
Message-Id: 1603988027.f948f1bd0665f98cd29e33b3da6f15c0b12435b2.mattst88@gentoo
1 commit: f948f1bd0665f98cd29e33b3da6f15c0b12435b2
2 Author: Matt Turner <mattst88 <AT> gentoo <DOT> org>
3 AuthorDate: Thu Oct 22 18:19:09 2020 +0000
4 Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org>
5 CommitDate: Thu Oct 29 16:13:47 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=f948f1bd
7
8 catalyst: Remove kill_support_pids()
9
10 mount_namespaces(7) says
11
12 A mount ceases to be a member of a peer group when either the
13 mount is explicitly unmounted, or when the mount is implicitly
14 unmounted because a mount namespace is removed (because it has
15 no more member processes).
16
17 Now that the build sequence is executed in its own mount namespace, the
18 mounts are implicitly unmounted when the last process in the namespace
19 dies, meaning we don't need to try any funny business around cleaning up
20 processes in order to unmount.
21
22 Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>
23
24 catalyst/base/stagebase.py | 30 +++---------------
25 targets/support/kill-chroot-pids.sh | 62 -------------------------------------
26 2 files changed, 4 insertions(+), 88 deletions(-)
27
28 diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
29 index ec9a8f06..5fc11eae 100644
30 --- a/catalyst/base/stagebase.py
31 +++ b/catalyst/base/stagebase.py
32 @@ -638,17 +638,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
33 assert self.settings[verify] == "blake2"
34 self.settings.setdefault("gk_mainargs", []).append("--b2sum")
35
36 - def kill_chroot_pids(self):
37 - log.info('Checking for processes running in chroot and killing them.')
38 -
39 - # Force environment variables to be exported so script can see them
40 - self.setup_environment()
41 -
42 - killcmd = normpath(self.settings["sharedir"] +
43 - self.settings["shdir"] + "/support/kill-chroot-pids.sh")
44 - if os.path.exists(killcmd):
45 - cmd([killcmd], env=self.env)
46 -
47 def mount_safety_check(self):
48 """
49 Check and verify that none of our paths in mypath are mounted. We don't
50 @@ -920,18 +909,10 @@ class StageBase(TargetBase, ClearBase, GenBase):
51 try:
52 cxt = libmount.Context(target=str(target))
53 cxt.umount()
54 - except OSError:
55 - log.warning('First attempt to unmount failed: %s', target)
56 - log.warning('Killing any pids still running in the chroot')
57 -
58 - self.kill_chroot_pids()
59 -
60 - try:
61 - cxt.umount()
62 - except OSError as e:
63 - umount_failed = True
64 - log.warning("Couldn't umount: %s, %s", target,
65 - e.strerror)
66 + except OSError as e:
67 + log.warning("Couldn't umount: %s, %s", target,
68 + e.strerror)
69 + umount_failed = True
70
71 if umount_failed:
72 # if any bind mounts really failed, then we need to raise
73 @@ -1382,9 +1363,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
74 def run(self):
75 self.chroot_lock.write_lock()
76
77 - # Kill any pids in the chroot
78 - self.kill_chroot_pids()
79 -
80 # Check for mounts right away and abort if we cannot unmount them
81 self.mount_safety_check()
82
83
84 diff --git a/targets/support/kill-chroot-pids.sh b/targets/support/kill-chroot-pids.sh
85 deleted file mode 100755
86 index ea8ee402..00000000
87 --- a/targets/support/kill-chroot-pids.sh
88 +++ /dev/null
89 @@ -1,62 +0,0 @@
90 -#!/bin/bash
91 -# Script to kill processes found running in the chroot.
92 -
93 -if [ "${clst_chroot_path}" == "/" ]
94 -then
95 - echo "Aborting .... clst_chroot_path is set to /"
96 - echo "This is very dangerous"
97 - exit 1
98 -fi
99 -
100 -if [ "${clst_chroot_path}" == "" ]
101 -then
102 - echo "Aborting .... clst_chroot_path is NOT set"
103 - echo "This is very dangerous"
104 - exit 1
105 -fi
106 -
107 -j=0
108 -declare -a pids
109 -# Get files and dirs in /proc
110 -for i in `ls /proc`
111 -do
112 - # Test for directories
113 - if [ -d /proc/$i ]
114 - then
115 - # Search for exe containing string inside ${clst_chroot_path}
116 - ls -la --color=never /proc/$i 2>&1 |grep exe|grep ${clst_chroot_path} > /dev/null
117 -
118 - # If found
119 - if [ $? == 0 ]
120 - then
121 - # Assign the pid into the pids array
122 - pids[$j]=$i
123 - j=$(($j+1))
124 - fi
125 - fi
126 -done
127 -
128 -if [ ${j} -gt 0 ]
129 -then
130 - echo
131 - echo "Killing process(es)"
132 - echo "pid: process name"
133 - for pid in ${pids[@]}
134 - do
135 - P_NAME=$(ls -la --color=never /proc/${pid} 2>&1 |grep exe|grep ${clst_chroot_path}|awk '{print $11}')
136 - echo ${pid}: ${P_NAME}
137 - done
138 - echo
139 - echo "Press Ctrl-C within 10 seconds to abort"
140 -
141 - sleep 10
142 -
143 - for pid in ${pids[@]}
144 - do
145 - kill -9 ${pid}
146 - done
147 -
148 - # Small sleep here to give the process(es) a chance to die before running unbind again.
149 - sleep 5
150 -
151 -fi