virFileResolveLink: fix return value

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.
This commit is contained in:
Eric Blake 2010-05-14 14:50:27 -06:00
parent df5944ff02
commit d533a98ed6
4 changed files with 11 additions and 14 deletions

View File

@ -75,13 +75,12 @@ qemuSecurityDACRestoreSecurityFileLabel(const char *path)
{ {
struct stat buf; struct stat buf;
int rc = -1; int rc = -1;
int err;
char *newpath = NULL; char *newpath = NULL;
VIR_INFO("Restoring DAC user and group on '%s'", path); VIR_INFO("Restoring DAC user and group on '%s'", path);
if ((err = virFileResolveLink(path, &newpath)) < 0) { if (virFileResolveLink(path, &newpath) < 0) {
virReportSystemError(err, virReportSystemError(errno,
_("cannot resolve symlink %s"), path); _("cannot resolve symlink %s"), path);
goto err; goto err;
} }

View 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 * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -353,13 +353,12 @@ SELinuxRestoreSecurityFileLabel(const char *path)
struct stat buf; struct stat buf;
security_context_t fcon = NULL; security_context_t fcon = NULL;
int rc = -1; int rc = -1;
int err;
char *newpath = NULL; char *newpath = NULL;
VIR_INFO("Restoring SELinux context on '%s'", path); VIR_INFO("Restoring SELinux context on '%s'", path);
if ((err = virFileResolveLink(path, &newpath)) < 0) { if (virFileResolveLink(path, &newpath) < 0) {
virReportSystemError(err, virReportSystemError(errno,
_("cannot resolve symlink %s"), path); _("cannot resolve symlink %s"), path);
goto err; goto err;
} }

View File

@ -1,7 +1,7 @@
/* /*
* storage_backend_disk.c: storage backend for disk handling * 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 * Copyright (C) 2007-2008 Daniel P. Berrange
* *
* This library is free software; you can redistribute it and/or * 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) unsigned int flags ATTRIBUTE_UNUSED)
{ {
char *part_num = NULL; char *part_num = NULL;
int err;
char *devpath = NULL; char *devpath = NULL;
char *devname, *srcname; char *devname, *srcname;
int rc = -1; int rc = -1;
if ((err = virFileResolveLink(vol->target.path, &devpath)) < 0) { if (virFileResolveLink(vol->target.path, &devpath) < 0) {
virReportSystemError(err, virReportSystemError(errno,
_("Couldn't read volume target path '%s'"), _("Couldn't read volume target path '%s'"),
vol->target.path); vol->target.path);
goto cleanup; goto cleanup;

View File

@ -1182,7 +1182,7 @@ int virFileLinkPointsTo(const char *checkLink,
* real path * real path
* *
* Return 0 if path was not a symbolic, or the link was * 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, int virFileResolveLink(const char *linkpath,
char **resultpath) char **resultpath)
@ -1192,11 +1192,11 @@ int virFileResolveLink(const char *linkpath,
*resultpath = NULL; *resultpath = NULL;
if (lstat(linkpath, &st) < 0) if (lstat(linkpath, &st) < 0)
return errno; return -1;
if (!S_ISLNK(st.st_mode)) { if (!S_ISLNK(st.st_mode)) {
if (!(*resultpath = strdup(linkpath))) if (!(*resultpath = strdup(linkpath)))
return -ENOMEM; return -1;
return 0; return 0;
} }