summaryrefslogtreecommitdiffstats
path: root/py/mock/backend.py
diff options
context:
space:
mode:
authorClark Williams <williams@redhat.com>2010-02-19 17:01:14 -0600
committerClark Williams <williams@redhat.com>2010-02-19 17:01:14 -0600
commitb37d385e0f4e41b27a413162c0404e588724743f (patch)
tree9cf569d711d07be6b66d9a9639e4e5bfaaed734e /py/mock/backend.py
parent553470d25de81387086e7a8ce2a107d25c7968e9 (diff)
downloadmock-b37d385e0f4e41b27a413162c0404e588724743f.tar.gz
mock-b37d385e0f4e41b27a413162c0404e588724743f.tar.xz
mock-b37d385e0f4e41b27a413162c0404e588724743f.zip
add utility function to detect SELinux status and use it
Add a utility function selinuxEnabled() that returns true if SELinux is enabled on the host and false otherwise. Use this in _setupDev() method of the Root object to avoid shelling out unnecessarily to 'chcon'. Signed-off-by: Clark Williams <williams@redhat.com>
Diffstat (limited to 'py/mock/backend.py')
-rw-r--r--py/mock/backend.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/py/mock/backend.py b/py/mock/backend.py
index bcadc3e..7ca6a1d 100644
--- a/py/mock/backend.py
+++ b/py/mock/backend.py
@@ -101,6 +101,9 @@ class Root(object):
self.state("init plugins")
self._initPlugins()
+ # figure out if SELinux is enabled on the host
+ self.selinux = mock.util.selinuxEnabled()
+
# officially set state so it is logged
self.state("start")
@@ -322,9 +325,10 @@ class Root(object):
os.mknod( self.makeChrootPath(i[2]), i[0], i[1])
# set context. (only necessary if host running selinux enabled.)
# fails gracefully if chcon not installed.
- mock.util.do(
- ["chcon", "--reference=/%s"% i[2], self.makeChrootPath(i[2])]
- , raiseExc=0, shell=False)
+ if self.selinux:
+ mock.util.do(
+ ["chcon", "--reference=/%s"% i[2], self.makeChrootPath(i[2])]
+ , raiseExc=0, shell=False)
os.symlink("/proc/self/fd/0", self.makeChrootPath("dev/stdin"))
os.symlink("/proc/self/fd/1", self.makeChrootPath("dev/stdout"))