diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 9373f45fab..24eb456635 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -891,3 +891,39 @@ qemuDomainOpenLog(struct qemud_driver *driver, virDomainObjPtr vm, off_t pos) } +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(fd, 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 dfb25fb31c..286fdb2814 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, ...) ATTRIBUTE_FMT_PRINTF(4, 5); #endif /* __QEMU_DOMAIN_H__ */