When qemuMonitorCloseFileHandle is called in error path, we need to
preserve the original error since a possible further error when running
closefd monitor command is not very useful to users.
---
src/qemu/qemu_monitor.c | 14 ++++++++++++--
src/qemu/qemu_monitor.h | 3 +++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index cff7220..3a30a15 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1964,20 +1964,30 @@ int qemuMonitorSendFileHandle(qemuMonitorPtr mon,
int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
const char *fdname)
{
- int ret;
+ int ret = -1;
+ virErrorPtr error;
+
VIR_DEBUG("mon=%p fdname=%s",
mon, fdname);
+ error = virSaveLastError();
+
if (!mon) {
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
_("monitor must not be NULL"));
- return -1;
+ goto cleanup;
}
if (mon->json)
ret = qemuMonitorJSONCloseFileHandle(mon, fdname);
else
ret = qemuMonitorTextCloseFileHandle(mon, fdname);
+
+cleanup:
+ if (error) {
+ virSetError(error);
+ virFreeError(error);
+ }
return ret;
}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 893f3e9..f246d21 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -362,6 +362,9 @@ int qemuMonitorSendFileHandle(qemuMonitorPtr mon,
const char *fdname,
int fd);
+/* The function preserves previous error and only sets it's own error if no
+ * error was set before.
+ */
int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
const char *fdname);
--
1.7.6