]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: cast -1 for uid_t|gid_t
authorPhilipp Hahn <hahn@univention.de>
Fri, 22 Feb 2013 16:41:32 +0000 (17:41 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 25 Feb 2013 14:46:32 +0000 (15:46 +0100)
uid_t and gid_t are opaque types, ranging from s32 to u32 to u64.

Explicitly cast the magic -1 to the appropriate type.

Signed-off-by: Philipp Hahn <hahn@univention.de>
src/conf/storage_conf.c
src/storage/storage_backend.c
src/util/virutil.c

index 7a3999863ff7b6be65ebf7b975c1c4b41f0fae41..9134a22b06de73bf393c08d994f3a8683b01f156 100644 (file)
@@ -674,8 +674,8 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
     if (node == NULL) {
         /* Set default values if there is not <permissions> element */
         perms->mode = defaultmode;
-        perms->uid = -1;
-        perms->gid = -1;
+        perms->uid = (uid_t) -1;
+        perms->gid = (gid_t) -1;
         perms->label = NULL;
         return 0;
     }
@@ -700,7 +700,7 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
     }
 
     if (virXPathNode("./owner", ctxt) == NULL) {
-        perms->uid = -1;
+        perms->uid = (uid_t) -1;
     } else {
         if (virXPathLong("number(./owner)", ctxt, &v) < 0) {
             virReportError(VIR_ERR_XML_ERROR,
@@ -711,7 +711,7 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
     }
 
     if (virXPathNode("./group", ctxt) == NULL) {
-        perms->gid = -1;
+        perms->gid = (gid_t) -1;
     } else {
         if (virXPathLong("number(./group)", ctxt, &v) < 0) {
             virReportError(VIR_ERR_XML_ERROR,
index 70bb48ae998145bfe2578701f060852a1f2b6cb4..bb58d4a6177c90ed857a7b94b93d6107c8a3f6a9 100644 (file)
@@ -277,9 +277,9 @@ virStorageBackendCreateBlockFrom(virConnectPtr conn ATTRIBUTE_UNUSED,
                              vol->target.path);
         goto cleanup;
     }
-    uid = (vol->target.perms.uid != st.st_uid) ? vol->target.perms.uid : -1;
-    gid = (vol->target.perms.gid != st.st_gid) ? vol->target.perms.gid : -1;
-    if (((uid != -1) || (gid != -1))
+    uid = (vol->target.perms.uid != st.st_uid) ? vol->target.perms.uid : (uid_t) -1;
+    gid = (vol->target.perms.gid != st.st_gid) ? vol->target.perms.gid : (gid_t) -1;
+    if (((uid != (uid_t) -1) || (gid != (gid_t) -1))
         && (fchown(fd, uid, gid) < 0)) {
         virReportSystemError(errno,
                              _("cannot chown '%s' to (%u, %u)"),
@@ -542,9 +542,9 @@ static int virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool,
 
     if ((pool->def->type == VIR_STORAGE_POOL_NETFS)
         && (((getuid() == 0)
-             && (vol->target.perms.uid != -1)
+             && (vol->target.perms.uid != (uid_t) -1)
              && (vol->target.perms.uid != 0))
-            || ((vol->target.perms.gid != -1)
+            || ((vol->target.perms.gid != (gid_t) -1)
                 && (vol->target.perms.gid != getgid())))) {
 
         virCommandSetUID(cmd, vol->target.perms.uid);
@@ -572,9 +572,9 @@ static int virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool,
         }
     }
 
-    uid = (vol->target.perms.uid != st.st_uid) ? vol->target.perms.uid : -1;
-    gid = (vol->target.perms.gid != st.st_gid) ? vol->target.perms.gid : -1;
-    if (((uid != -1) || (gid != -1))
+    uid = (vol->target.perms.uid != st.st_uid) ? vol->target.perms.uid : (uid_t) -1;
+    gid = (vol->target.perms.gid != st.st_gid) ? vol->target.perms.gid : (gid_t) -1;
+    if (((uid != (uid_t) -1) || (gid != (gid_t) -1))
         && (chown(vol->target.path, uid, gid) < 0)) {
         virReportSystemError(errno,
                              _("cannot chown %s to (%u, %u)"),
index 563f684c803b1ccab6b88034330c9debb209e082..4af2599c55b61e0ad16ccbddeb3a098675a5d1cd 100644 (file)
@@ -1206,7 +1206,7 @@ parenterror:
                              _("stat of '%s' failed"), path);
         goto childerror;
     }
-    if ((st.st_gid != gid) && (chown(path, -1, gid) < 0)) {
+    if ((st.st_gid != gid) && (chown(path, (uid_t) -1, gid) < 0)) {
         ret = -errno;
         virReportSystemError(errno,
                              _("cannot chown '%s' to group %u"),