]> xenbits.xensource.com Git - libvirt.git/commitdiff
virFileResolveLink: fix return value
authorEric Blake <eblake@redhat.com>
Fri, 14 May 2010 20:50:27 +0000 (14:50 -0600)
committerEric Blake <eblake@redhat.com>
Mon, 17 May 2010 20:48:27 +0000 (14:48 -0600)
virFileResolveLink was returning a positive value on error,
thus confusing callers that assumed failure was < 0.  The
confusion is further evidenced by callers that would have
ended up calling virReportSystemError with a negative value
instead of a valid errno.

Fixes Red Hat BZ #591363.

* src/util/util.c (virFileResolveLink): Live up to documentation.
* src/qemu/qemu_security_dac.c
(qemuSecurityDACRestoreSecurityFileLabel): Adjust callers.
* src/security/security_selinux.c
(SELinuxRestoreSecurityFileLabel): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskDeleteVol): Likewise.

src/qemu/qemu_security_dac.c
src/security/security_selinux.c
src/storage/storage_backend_disk.c
src/util/util.c

index 364227da57be8627c7d6c26ed958a35d252e6720..a816441e84d78d62d90b5f7808827cea1ecaf63f 100644 (file)
@@ -75,13 +75,12 @@ qemuSecurityDACRestoreSecurityFileLabel(const char *path)
 {
     struct stat buf;
     int rc = -1;
-    int err;
     char *newpath = NULL;
 
     VIR_INFO("Restoring DAC user and group on '%s'", path);
 
-    if ((err = virFileResolveLink(path, &newpath)) < 0) {
-        virReportSystemError(err,
+    if (virFileResolveLink(path, &newpath) < 0) {
+        virReportSystemError(errno,
                              _("cannot resolve symlink %s"), path);
         goto err;
     }
index 47534dfc42c20a6a47fc811a932be4c99bc66d4f..669ef421cc7cb497fb4d8db3867db6eb69649501 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008,2009 Red Hat, Inc.
+ * Copyright (C) 2008-2010 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -353,13 +353,12 @@ SELinuxRestoreSecurityFileLabel(const char *path)
     struct stat buf;
     security_context_t fcon = NULL;
     int rc = -1;
-    int err;
     char *newpath = NULL;
 
     VIR_INFO("Restoring SELinux context on '%s'", path);
 
-    if ((err = virFileResolveLink(path, &newpath)) < 0) {
-        virReportSystemError(err,
+    if (virFileResolveLink(path, &newpath) < 0) {
+        virReportSystemError(errno,
                              _("cannot resolve symlink %s"), path);
         goto err;
     }
index 836d1caf3c62db2c60216cb8728159ffcbe92e18..71883866b028e8edb0fabb435c0e4e589a7616d6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * storage_backend_disk.c: storage backend for disk handling
  *
- * Copyright (C) 2007-2008 Red Hat, Inc.
+ * Copyright (C) 2007-2008, 2010 Red Hat, Inc.
  * Copyright (C) 2007-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -612,13 +612,12 @@ virStorageBackendDiskDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
                                unsigned int flags ATTRIBUTE_UNUSED)
 {
     char *part_num = NULL;
-    int err;
     char *devpath = NULL;
     char *devname, *srcname;
     int rc = -1;
 
-    if ((err = virFileResolveLink(vol->target.path, &devpath)) < 0) {
-        virReportSystemError(err,
+    if (virFileResolveLink(vol->target.path, &devpath) < 0) {
+        virReportSystemError(errno,
                              _("Couldn't read volume target path '%s'"),
                              vol->target.path);
         goto cleanup;
index 26ac6baeeae5b45b609062d638ef8e90ecd966a7..e937d39254b028eb5f48e9640fb312a0e78ec083 100644 (file)
@@ -1182,7 +1182,7 @@ int virFileLinkPointsTo(const char *checkLink,
  * real path
  *
  * Return 0 if path was not a symbolic, or the link was
- * resolved. Return -1 upon error
+ * resolved. Return -1 with errno set upon error
  */
 int virFileResolveLink(const char *linkpath,
                        char **resultpath)
@@ -1192,11 +1192,11 @@ int virFileResolveLink(const char *linkpath,
     *resultpath = NULL;
 
     if (lstat(linkpath, &st) < 0)
-        return errno;
+        return -1;
 
     if (!S_ISLNK(st.st_mode)) {
         if (!(*resultpath = strdup(linkpath)))
-            return -ENOMEM;
+            return -1;
         return 0;
     }