diff --git a/pym/portage/_selinux.py b/pym/portage/_selinux.py index 2a7194c..1541da3 100644 --- a/pym/portage/_selinux.py +++ b/pym/portage/_selinux.py @@ -77,7 +77,20 @@ def settype(newtype): def setexec(ctx="\n"): ctx = _native_string(ctx, encoding=_encodings['content'], errors='strict') - if selinux.setexeccon(ctx) < 0: + rc = 0 + try: + rc = selinux.setexeccon(ctx) + except: + if selinux.security_getenforce() == 1: + raise OSError(_("Failed to set new SELinux execution context. " + \ + "Is your current SELinux context allowed to run Portage?\n")) + else: + portage.writemsg("!!! " + \ + _("Failed to set new SELinux execution context. " + \ + "Is your current SELinux context allowed to run Portage?\n"), \ + noiselevel=-1) + + if rc < 0: if sys.hexversion < 0x3000000: ctx = _unicode_decode(ctx, encoding=_encodings['content'], errors='replace') if selinux.security_getenforce() == 1: