|
|
7a3408 |
From c144a563ea6f31e82026009dc03ba8f1b5caba84 Mon Sep 17 00:00:00 2001
|
|
|
7a3408 |
Message-Id: <c144a563ea6f31e82026009dc03ba8f1b5caba84@dist-git>
|
|
|
7a3408 |
From: John Ferlan <jferlan@redhat.com>
|
|
|
7a3408 |
Date: Thu, 17 Sep 2015 11:47:21 +0200
|
|
|
7a3408 |
Subject: [PATCH] virfile: Check for existence of dir in virFileDeleteTree
|
|
|
7a3408 |
|
|
|
7a3408 |
https://bugzilla.redhat.com/show_bug.cgi?id=1146886
|
|
|
7a3408 |
|
|
|
7a3408 |
Commit id 'f1f68ca33' added code to remove the directory paths for
|
|
|
7a3408 |
auto-generated sockets, but that code could be called before the
|
|
|
7a3408 |
paths were created resulting in generating error messages from
|
|
|
7a3408 |
virFileDeleteTree indicating that the file doesn't exist.
|
|
|
7a3408 |
|
|
|
7a3408 |
Rather than "enforce" all callers to make the non-NULL and existence
|
|
|
7a3408 |
checks, modify the virFileDeleteTree API to silently ignore NULL on
|
|
|
7a3408 |
input and non-existent directory trees.
|
|
|
7a3408 |
|
|
|
7a3408 |
(cherry picked from commit b421a70811b15a2d1853ee7e47069fdef83f7f22)
|
|
|
7a3408 |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
7a3408 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
7a3408 |
---
|
|
|
7a3408 |
src/qemu/qemu_process.c | 6 ++----
|
|
|
7a3408 |
src/util/virfile.c | 8 ++++++--
|
|
|
7a3408 |
tests/virhostdevtest.c | 2 +-
|
|
|
7a3408 |
tests/virscsitest.c | 2 +-
|
|
|
7a3408 |
4 files changed, 10 insertions(+), 8 deletions(-)
|
|
|
7a3408 |
|
|
|
7a3408 |
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
|
|
|
7a3408 |
index ee1d6b2..301b9bf 100644
|
|
|
7a3408 |
--- a/src/qemu/qemu_process.c
|
|
|
7a3408 |
+++ b/src/qemu/qemu_process.c
|
|
|
7a3408 |
@@ -5272,14 +5272,12 @@ void qemuProcessStop(virQEMUDriverPtr driver,
|
|
|
7a3408 |
|
|
|
7a3408 |
ignore_value(virAsprintf(&tmppath, "%s/domain-%s",
|
|
|
7a3408 |
cfg->libDir, vm->def->name));
|
|
|
7a3408 |
- if (tmppath)
|
|
|
7a3408 |
- virFileDeleteTree(tmppath);
|
|
|
7a3408 |
+ virFileDeleteTree(tmppath);
|
|
|
7a3408 |
VIR_FREE(tmppath);
|
|
|
7a3408 |
|
|
|
7a3408 |
ignore_value(virAsprintf(&tmppath, "%s/domain-%s",
|
|
|
7a3408 |
cfg->channelTargetDir, vm->def->name));
|
|
|
7a3408 |
- if (tmppath)
|
|
|
7a3408 |
- virFileDeleteTree(tmppath);
|
|
|
7a3408 |
+ virFileDeleteTree(tmppath);
|
|
|
7a3408 |
VIR_FREE(tmppath);
|
|
|
7a3408 |
|
|
|
7a3408 |
ignore_value(virDomainChrDefForeach(vm->def,
|
|
|
7a3408 |
diff --git a/src/util/virfile.c b/src/util/virfile.c
|
|
|
7a3408 |
index 7c6e72c..53d4639 100644
|
|
|
7a3408 |
--- a/src/util/virfile.c
|
|
|
7a3408 |
+++ b/src/util/virfile.c
|
|
|
7a3408 |
@@ -909,13 +909,17 @@ int virFileNBDDeviceAssociate(const char *file,
|
|
|
7a3408 |
*/
|
|
|
7a3408 |
int virFileDeleteTree(const char *dir)
|
|
|
7a3408 |
{
|
|
|
7a3408 |
- DIR *dh = opendir(dir);
|
|
|
7a3408 |
+ DIR *dh;
|
|
|
7a3408 |
struct dirent *de;
|
|
|
7a3408 |
char *filepath = NULL;
|
|
|
7a3408 |
int ret = -1;
|
|
|
7a3408 |
int direrr;
|
|
|
7a3408 |
|
|
|
7a3408 |
- if (!dh) {
|
|
|
7a3408 |
+ /* Silently return 0 if passed NULL or directory doesn't exist */
|
|
|
7a3408 |
+ if (!dir || !virFileExists(dir))
|
|
|
7a3408 |
+ return 0;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ if (!(dh = opendir(dir))) {
|
|
|
7a3408 |
virReportSystemError(errno, _("Cannot open dir '%s'"),
|
|
|
7a3408 |
dir);
|
|
|
7a3408 |
return -1;
|
|
|
7a3408 |
diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c
|
|
|
7a3408 |
index 1e93819..065b825 100644
|
|
|
7a3408 |
--- a/tests/virhostdevtest.c
|
|
|
7a3408 |
+++ b/tests/virhostdevtest.c
|
|
|
7a3408 |
@@ -65,7 +65,7 @@ myCleanup(void)
|
|
|
7a3408 |
}
|
|
|
7a3408 |
|
|
|
7a3408 |
if (mgr) {
|
|
|
7a3408 |
- if (mgr->stateDir && !getenv("LIBVIRT_SKIP_CLEANUP"))
|
|
|
7a3408 |
+ if (!getenv("LIBVIRT_SKIP_CLEANUP"))
|
|
|
7a3408 |
virFileDeleteTree(mgr->stateDir);
|
|
|
7a3408 |
|
|
|
7a3408 |
virObjectUnref(mgr->activePCIHostdevs);
|
|
|
7a3408 |
diff --git a/tests/virscsitest.c b/tests/virscsitest.c
|
|
|
7a3408 |
index a86ca28..88286f1 100644
|
|
|
7a3408 |
--- a/tests/virscsitest.c
|
|
|
7a3408 |
+++ b/tests/virscsitest.c
|
|
|
7a3408 |
@@ -241,7 +241,7 @@ mymain(void)
|
|
|
7a3408 |
ret = -1;
|
|
|
7a3408 |
|
|
|
7a3408 |
cleanup:
|
|
|
7a3408 |
- if (tmpdir && getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
|
|
|
7a3408 |
+ if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
|
|
|
7a3408 |
virFileDeleteTree(tmpdir);
|
|
|
7a3408 |
VIR_FREE(virscsi_prefix);
|
|
|
7a3408 |
return ret;
|
|
|
7a3408 |
--
|
|
|
7a3408 |
2.5.3
|
|
|
7a3408 |
|