1 |
commit: d62e0bec798c9fb404da306f464e77b8dd0bf293 |
2 |
Author: Matt Turner <mattst88 <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu May 21 22:37:29 2020 +0000 |
4 |
Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed May 27 06:19:55 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=d62e0bec |
7 |
|
8 |
catalyst: Clean up unbind() function |
9 |
|
10 |
Does a couple of things: |
11 |
- drops log.notice -> log.warning |
12 |
- Removes the kill_chroot_pids support code since .... |
13 |
namespaces? |
14 |
|
15 |
Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org> |
16 |
|
17 |
catalyst/base/stagebase.py | 45 +++++++-------------------- |
18 |
targets/support/kill-chroot-pids.sh | 62 ------------------------------------- |
19 |
2 files changed, 12 insertions(+), 95 deletions(-) |
20 |
|
21 |
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py |
22 |
index aa5cafd0..d92f3ffb 100644 |
23 |
--- a/catalyst/base/stagebase.py |
24 |
+++ b/catalyst/base/stagebase.py |
25 |
@@ -625,17 +625,6 @@ class StageBase(TargetBase, ClearBase, GenBase): |
26 |
assert self.settings[verify] == "blake2" |
27 |
self.settings.setdefault("gk_mainargs", []).append("--b2sum") |
28 |
|
29 |
- def kill_chroot_pids(self): |
30 |
- log.info('Checking for processes running in chroot and killing them.') |
31 |
- |
32 |
- # Force environment variables to be exported so script can see them |
33 |
- self.setup_environment() |
34 |
- |
35 |
- killcmd = normpath(self.settings["sharedir"] + |
36 |
- self.settings["shdir"] + "/support/kill-chroot-pids.sh") |
37 |
- if os.path.exists(killcmd): |
38 |
- cmd([killcmd], env=self.env) |
39 |
- |
40 |
def mount_safety_check(self): |
41 |
""" |
42 |
Check and verify that none of our paths in mypath are mounted. We don't |
43 |
@@ -886,35 +875,28 @@ class StageBase(TargetBase, ClearBase, GenBase): |
44 |
raise CatalystError |
45 |
|
46 |
def unbind(self): |
47 |
- ouch = 0 |
48 |
- mypath = self.settings["chroot_path"] |
49 |
+ chroot_path = self.settings["chroot_path"] |
50 |
+ umount_failed = False |
51 |
|
52 |
# Unmount in reverse order |
53 |
- for x in [x for x in reversed(self.mount) if self.mount[x]['enable']]: |
54 |
- target = normpath(mypath + self.mount[x]['target']) |
55 |
- if not os.path.exists(target): |
56 |
- log.notice('%s does not exist. Skipping', target) |
57 |
+ for target in [Path(chroot_path + self.mount[x]['target']) |
58 |
+ for x in reversed(self.mount) |
59 |
+ if self.mount[x]['enable']]: |
60 |
+ if not target.exists(): |
61 |
+ log.debug('%s does not exist. Skipping', target) |
62 |
continue |
63 |
|
64 |
if not ismount(target): |
65 |
- log.notice('%s is not a mount point. Skipping', target) |
66 |
+ log.debug('%s is not a mount point. Skipping', target) |
67 |
continue |
68 |
|
69 |
try: |
70 |
umount(target) |
71 |
- except CatalystError: |
72 |
- log.warning('First attempt to unmount failed: %s', target) |
73 |
- log.warning('Killing any pids still running in the chroot') |
74 |
- |
75 |
- self.kill_chroot_pids() |
76 |
- |
77 |
- try: |
78 |
- umount(target) |
79 |
- except CatalystError: |
80 |
- ouch = 1 |
81 |
- log.warning("Couldn't umount bind mount: %s", target) |
82 |
+ except OSError as e: |
83 |
+ log.warning("Couldn't umount bind mount: %s", target) |
84 |
+ umount_failed = True |
85 |
|
86 |
- if ouch: |
87 |
+ if umount_failed: |
88 |
# if any bind mounts really failed, then we need to raise |
89 |
# this to potentially prevent an upcoming bash stage cleanup script |
90 |
# from wiping our bind mounts. |
91 |
@@ -1307,9 +1289,6 @@ class StageBase(TargetBase, ClearBase, GenBase): |
92 |
def run(self): |
93 |
self.chroot_lock.write_lock() |
94 |
|
95 |
- # Kill any pids in the chroot |
96 |
- self.kill_chroot_pids() |
97 |
- |
98 |
# Check for mounts right away and abort if we cannot unmount them |
99 |
self.mount_safety_check() |
100 |
|
101 |
|
102 |
diff --git a/targets/support/kill-chroot-pids.sh b/targets/support/kill-chroot-pids.sh |
103 |
deleted file mode 100755 |
104 |
index ea8ee402..00000000 |
105 |
--- a/targets/support/kill-chroot-pids.sh |
106 |
+++ /dev/null |
107 |
@@ -1,62 +0,0 @@ |
108 |
-#!/bin/bash |
109 |
-# Script to kill processes found running in the chroot. |
110 |
- |
111 |
-if [ "${clst_chroot_path}" == "/" ] |
112 |
-then |
113 |
- echo "Aborting .... clst_chroot_path is set to /" |
114 |
- echo "This is very dangerous" |
115 |
- exit 1 |
116 |
-fi |
117 |
- |
118 |
-if [ "${clst_chroot_path}" == "" ] |
119 |
-then |
120 |
- echo "Aborting .... clst_chroot_path is NOT set" |
121 |
- echo "This is very dangerous" |
122 |
- exit 1 |
123 |
-fi |
124 |
- |
125 |
-j=0 |
126 |
-declare -a pids |
127 |
-# Get files and dirs in /proc |
128 |
-for i in `ls /proc` |
129 |
-do |
130 |
- # Test for directories |
131 |
- if [ -d /proc/$i ] |
132 |
- then |
133 |
- # Search for exe containing string inside ${clst_chroot_path} |
134 |
- ls -la --color=never /proc/$i 2>&1 |grep exe|grep ${clst_chroot_path} > /dev/null |
135 |
- |
136 |
- # If found |
137 |
- if [ $? == 0 ] |
138 |
- then |
139 |
- # Assign the pid into the pids array |
140 |
- pids[$j]=$i |
141 |
- j=$(($j+1)) |
142 |
- fi |
143 |
- fi |
144 |
-done |
145 |
- |
146 |
-if [ ${j} -gt 0 ] |
147 |
-then |
148 |
- echo |
149 |
- echo "Killing process(es)" |
150 |
- echo "pid: process name" |
151 |
- for pid in ${pids[@]} |
152 |
- do |
153 |
- P_NAME=$(ls -la --color=never /proc/${pid} 2>&1 |grep exe|grep ${clst_chroot_path}|awk '{print $11}') |
154 |
- echo ${pid}: ${P_NAME} |
155 |
- done |
156 |
- echo |
157 |
- echo "Press Ctrl-C within 10 seconds to abort" |
158 |
- |
159 |
- sleep 10 |
160 |
- |
161 |
- for pid in ${pids[@]} |
162 |
- do |
163 |
- kill -9 ${pid} |
164 |
- done |
165 |
- |
166 |
- # Small sleep here to give the process(es) a chance to die before running unbind again. |
167 |
- sleep 5 |
168 |
- |
169 |
-fi |