On Monday 26 April 2010, Jesse Keating wrote:
> On Sun, 2010-04-25 at 22:06 +0300, Ville Skyttä wrote:
> > Any objections to the attached mock patch?
> 
> I welcome the bugfix, but that return statement is a little awkward from
> a pythonic view point.  I would have trouble figuring out wtf it was
> trying to do if I ran into this code without the context you gave it
> above.

Ok, do you find the attached revised version clearer?
From c1d13d46cb396bc0b1ae2dd20d0b076a0ff95e30 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ville=20Skytt=C3=A4?= <[email protected]>
Date: Sun, 25 Apr 2010 21:59:13 +0300
Subject: [PATCH] Check SELinux state from /selinux/enforce instead of /usr/sbin/getenforce.

Cleans up an error message when getenforce is not installed, and fixes wrong
outcome from selinuxEnabled() when SELinux is additionally disabled.
---
 py/mock/util.py |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/py/mock/util.py b/py/mock/util.py
index 3322cd5..764ed04 100644
--- a/py/mock/util.py
+++ b/py/mock/util.py
@@ -263,14 +263,13 @@ def logOutput(fds, logger, returnOutput=1, start=0, timeout=0):
 
 decorate(traceLog())
 def selinuxEnabled():
-    p = subprocess.Popen(["/usr/sbin/getenforce"], 
-                         shell=True, 
-                         stdout=subprocess.PIPE, 
-                         close_fds=True)
-    p.wait()
-    if p.stdout.read().strip() == "Disabled":
-        return False
-    return True
+    """Check if SELinux is enabled (enforcing or permissive)."""
+    try:
+        if open("/selinux/enforce").read().strip() in ("1", "0"):
+            return True
+    except:
+        pass
+    return False
 
 # logger =
 # output = [1|0]
-- 
1.7.0.1

--
buildsys mailing list
[email protected]
https://admin.fedoraproject.org/mailman/listinfo/buildsys

Reply via email to