]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Don't unnecessarily try to change a file context
authorMark McLoughlin <markmc@redhat.com>
Fri, 3 Jul 2009 10:27:46 +0000 (10:27 +0000)
committerMark McLoughlin <markmc@redhat.com>
Fri, 3 Jul 2009 10:27:46 +0000 (10:27 +0000)
As pointed out by Tim Waugh here:

  https://bugzilla.redhat.com/507555

We shouldn't bother trying to set the context of a file if it already
matches what we want.

(Fixed to use STREQ() and not use tabs, as pointed out by danpb)

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
ChangeLog
src/security_selinux.c

index ec228e451e4157e1a43d38e714b6d7bb5607cb7d..0de7884ec3be31aac8e74c92720ae352dabfc67d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,16 @@
+Thu Jul  3 11:26:04 GMT 2009 Mark McLoughlin <markmc@redhat.com>
+
+       Patch from Tim Waugh in https://bugzilla.redhat.com/507555
+
+       * src/security_selinux.c: Don't unnecessarily try to change a
+       file context
+
 Thu Jul  3 11:24:44 GMT 2009 Mark McLoughlin <markmc@redhat.com>
 
        Patch from Dan Berrange in https://bugzilla.redhat.com/493692
 
        * src/security_selinux.c: Re-label shared and readonly images
-       
+
 Thu Jul  2 15:58:09 CEST 2009 Daniel Veillard <veillard@redhat.com>
 
        * docs/schemas/network.rng: fix the network schemas to match
index 87073d2ecdbea309592a7d130538ca4ad29a5a6b..174dd57b72a09a4261a009714bf0ca147eda96e7 100644 (file)
@@ -318,10 +318,19 @@ static int
 SELinuxSetFilecon(virConnectPtr conn, const char *path, char *tcon)
 {
     char ebuf[1024];
+    security_context_t econ;
 
     VIR_INFO("Setting SELinux context on '%s' to '%s'", path, tcon);
 
-    if(setfilecon(path, tcon) < 0) {
+    if (setfilecon(path, tcon) < 0) {
+        if (getfilecon(path, &econ) >= 0) {
+            if (STREQ(tcon, econ)) {
+                freecon(econ);
+                /* It's alright, there's nothing to change anyway. */
+                return 0;
+            }
+            freecon(econ);
+        }
         virSecurityReportError(conn, VIR_ERR_ERROR,
                                _("%s: unable to set security context "
                                  "'\%s\' on %s: %s."), __func__,