[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 4/5] Add a qemuDomainAppendLog method for writing to the domain logfile



The qemuDomainAppendLog method allows writing a formatted string
to the end of the domain logfile, optionally opening it if needed.

* src/qemu/qemu_domain.c, src/qemu/qemu_domain.h: Add
  qemuDomainAppendLog
---
 src/qemu/qemu_domain.c |   37 +++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_domain.h |    4 ++++
 2 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 204a628..694c637 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -888,3 +888,40 @@ qemuDomainOpenLog(struct qemud_driver *driver, virDomainObjPtr vm, off_t pos)
 }
 
 
+ATTRIBUTE_FMT_PRINTF(4, 5)
+int qemuDomainAppendLog(struct qemud_driver *driver,
+                        virDomainObjPtr obj,
+                        int logFD,
+                        const char *fmt, ...)
+{
+    int fd = logFD;
+    va_list argptr;
+    char *message = NULL;
+    int ret = -1;
+
+    va_start(argptr, fmt);
+
+    if ((fd == -1) &&
+        (fd = qemuDomainCreateLog(driver, obj, true)) < 0)
+        goto cleanup;
+
+    if (virVasprintf(&message, fmt, argptr) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+    if (safewrite(logFD, message, strlen(message)) < 0) {
+        virReportSystemError(errno, _("Unable to write to domain logfile %s"),
+                             obj->def->name);
+        goto cleanup;
+    }
+
+    ret = 0;
+
+cleanup:
+    va_end(argptr);
+
+    if (fd != logFD)
+        VIR_FORCE_CLOSE(fd);
+
+    return ret;
+}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index dfb25fb..3e4d1ec 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -131,5 +131,9 @@ void qemuDomainObjCheckNetTaint(struct qemud_driver *driver,
 
 int qemuDomainCreateLog(struct qemud_driver *driver, virDomainObjPtr vm, bool append);
 int qemuDomainOpenLog(struct qemud_driver *driver, virDomainObjPtr vm, off_t pos);
+int qemuDomainAppendLog(struct qemud_driver *driver,
+                        virDomainObjPtr vm,
+                        int logFD,
+                        const char *fmt, ...);
 
 #endif /* __QEMU_DOMAIN_H__ */
-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]