1 |
From: Sven Vermeulen <swift@g.o> |
2 |
|
3 |
This converts "OSError: [Errno 22] Invalid argument" into a more |
4 |
meaningful error message that is to designed to guide users in the |
5 |
right direction. Also, add an import that was missing for the "sys" |
6 |
module, since is referenced in the error paths of many functions in |
7 |
this module. |
8 |
|
9 |
X-Gentoo-Bug: 525726 |
10 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=525726 |
11 |
--- |
12 |
pym/portage/_selinux.py | 14 +++++++++++++- |
13 |
1 file changed, 13 insertions(+), 1 deletion(-) |
14 |
|
15 |
diff --git a/pym/portage/_selinux.py b/pym/portage/_selinux.py |
16 |
index 2a7194c..c5e8b2c 100644 |
17 |
--- a/pym/portage/_selinux.py |
18 |
+++ b/pym/portage/_selinux.py |
19 |
@@ -5,6 +5,7 @@ |
20 |
# the whole _selinux module itself will be wrapped. |
21 |
import os |
22 |
import shutil |
23 |
+import sys |
24 |
|
25 |
import portage |
26 |
from portage import _encodings |
27 |
@@ -77,7 +78,18 @@ def settype(newtype): |
28 |
|
29 |
def setexec(ctx="\n"): |
30 |
ctx = _native_string(ctx, encoding=_encodings['content'], errors='strict') |
31 |
- if selinux.setexeccon(ctx) < 0: |
32 |
+ rc = 0 |
33 |
+ try: |
34 |
+ rc = selinux.setexeccon(ctx) |
35 |
+ except OSError: |
36 |
+ msg = _("Failed to set new SELinux execution context. " + \ |
37 |
+ "Is your current SELinux context allowed to run Portage?") |
38 |
+ if selinux.security_getenforce() == 1: |
39 |
+ raise OSError(msg) |
40 |
+ else: |
41 |
+ portage.writemsg("!!! %s\n" % msg, noiselevel=-1) |
42 |
+ |
43 |
+ if rc < 0: |
44 |
if sys.hexversion < 0x3000000: |
45 |
ctx = _unicode_decode(ctx, encoding=_encodings['content'], errors='replace') |
46 |
if selinux.security_getenforce() == 1: |
47 |
-- |
48 |
2.0.4 |