1 |
Use /proc/self/mountinfo which only contains the relevant chroot mounts. |
2 |
Mountinfo changes are thanks to jcallen for the valuable info he provided. |
3 |
--- |
4 |
pym/portage/util/writeable_check.py | 31 +++++++++++++++++++------------ |
5 |
1 file changed, 19 insertions(+), 12 deletions(-) |
6 |
|
7 |
diff --git a/pym/portage/util/writeable_check.py b/pym/portage/util/writeable_check.py |
8 |
index e6ddce6..745fbf0 100644 |
9 |
--- a/pym/portage/util/writeable_check.py |
10 |
+++ b/pym/portage/util/writeable_check.py |
11 |
@@ -13,7 +13,6 @@ from __future__ import unicode_literals |
12 |
|
13 |
import io |
14 |
import logging |
15 |
-import re |
16 |
|
17 |
from portage import _encodings |
18 |
from portage.util import writemsg_level |
19 |
@@ -34,8 +33,8 @@ def get_ro_checker(): |
20 |
|
21 |
def linux_ro_checker(dir_list): |
22 |
""" |
23 |
- Use /proc/mounts to check that no directories installed by the ebuild are set |
24 |
- to be installed to a read-only filesystem. |
25 |
+ Use /proc/self/mountinfo to check that no directories installed by the |
26 |
+ ebuild are set to be installed to a read-only filesystem. |
27 |
|
28 |
@param dir_list: A list of directories installed by the ebuild. |
29 |
@type dir_list: List |
30 |
@@ -46,18 +45,26 @@ def linux_ro_checker(dir_list): |
31 |
ro_filesystems = set() |
32 |
|
33 |
try: |
34 |
- with io.open("/proc/mounts", mode='r', encoding=_encodings['content'], |
35 |
- errors='replace') as f: |
36 |
- roregex = re.compile(r'(\A|,)ro(\Z|,)') |
37 |
- for line in f: |
38 |
- if roregex.search(line.split(" ")[3].strip()) is not None: |
39 |
- romount = line.split(" ")[1].strip() |
40 |
- ro_filesystems.add(romount) |
41 |
+ with io.open("/proc/self/mountinfo", mode='r', |
42 |
+ encoding=_encodings['content'], errors='replace') as f: |
43 |
+ for line in f.readlines(): |
44 |
+ # we're interested in dir and both attr fileds which always |
45 |
+ # start with either 'ro' or 'rw' |
46 |
+ # example line: |
47 |
+ # 14 1 8:3 / / rw,noatime - ext3 /dev/root rw,errors=continue,commit=5,barrier=1,data=writeback |
48 |
+ # dir ^ ^ attr ^ attr |
49 |
+ # there can be a variable number of fields |
50 |
+ # to the left of the ' - ', after the attr's, so split it there |
51 |
+ mount = line.split(' - ') |
52 |
+ mountl = mount[0].split() |
53 |
+ mountr = mount[1].split() |
54 |
+ if mountl[5].startswith('ro') or mountr[2].startswith('ro'): |
55 |
+ ro_filesystems.add(mountl[4]) |
56 |
|
57 |
- # If /proc/mounts can't be read, assume that there are no RO |
58 |
+ # If /proc/self/mountinfo can't be read, assume that there are no RO |
59 |
# filesystems and return. |
60 |
except EnvironmentError: |
61 |
- writemsg_level(_("!!! /proc/mounts cannot be read"), |
62 |
+ writemsg_level(_("!!! /proc/self/mountinfo cannot be read"), |
63 |
level=logging.WARNING, noiselevel=-1) |
64 |
return [] |
65 |
|
66 |
-- |
67 |
1.8.5.3 |