mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
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
This commit is contained in:
parent
ce1b1f4186
commit
1f1db0b52f
@ -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;
|
||||
}
|
||||
|
@ -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__ */
|
||||
|
Loading…
Reference in New Issue
Block a user