PATCH: Fix dir/fs storage pool when SELinux is disabled

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When SELinux is disabled  fgetfilecon() may well return -1, if a file has no
extended attribute with security context data. This causes the storage pool
to skip that file. The fix is to check whether errno is ENODATA and treat
that as an expected error case & ignore it.

Dan.

Index: src/storage_backend.c
===================================================================
RCS file: /data/cvs/libvirt/src/storage_backend.c,v
retrieving revision 1.8
diff -u -p -r1.8 storage_backend.c
--- src/storage_backend.c	27 Feb 2008 10:37:19 -0000	1.8
+++ src/storage_backend.c	14 Mar 2008 21:21:05 -0000
@@ -240,17 +240,22 @@ virStorageBackendUpdateVolInfoFD(virConn
 
 #if HAVE_SELINUX
     if (fgetfilecon(fd, &filecon) == -1) {
-        virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
-                              _("cannot get file context of %s: %s"),
-                              vol->target.path, strerror(errno));
-        return -1;
-    }
-    vol->target.perms.label = strdup(filecon);
-    if (vol->target.perms.label == NULL) {
-        virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("context"));
-        return -1;
+        if (errno != ENODATA) {
+            virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
+                                  _("cannot get file context of %s: %s"),
+                                  vol->target.path, strerror(errno));
+            return -1;
+        } else {
+            vol->target.perms.label = NULL;
+        }
+    } else {
+        vol->target.perms.label = strdup(filecon);
+        if (vol->target.perms.label == NULL) {
+            virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("context"));
+            return -1;
+        }
+        freecon(filecon);
     }
-    freecon(filecon);
 #else
     vol->target.perms.label = NULL;
 #endif


-- 
|: Red Hat, Engineering, Boston   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]