An old virLogDump() function was left in the logging code but commented
out, this resurrects it, fixes the callback function used and the
internal code
* src/util/logging.c src/util/logging.h: provide and expose virLogDump()
* src/libvirt_private.syms: exports it as a private symbol
Signed-off-by: Daniel Veillard <[email protected]>
---
src/libvirt_private.syms | 1 +
src/util/logging.c | 64 ++++++++++++++++++++++++---------------------
src/util/logging.h | 12 ++++++++
3 files changed, 47 insertions(+), 30 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5e63a12..cec2762 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -541,6 +541,7 @@ virRegisterStorageDriver;
# logging.h
virLogDefineFilter;
virLogDefineOutput;
+virLogDump;
virLogGetDefaultPriority;
virLogGetFilters;
virLogGetNbFilters;
diff --git a/src/util/logging.c b/src/util/logging.c
index b946285..d339750 100644
--- a/src/util/logging.c
+++ b/src/util/logging.c
@@ -277,50 +277,54 @@ static void virLogStr(const char *str, int len) {
virLogUnlock();
}
-#if 0
+
/*
- * Output the ring buffer
+ * virLogDump:
+ * @data: user data passed as first argument to @f
+ * @f: function used to dump the buffer content
+ *
+ * Output the ring buffer through the given function @f, which may be
+ * called multiple times to fully emit the buffer content
+ *
+ * Returns 0 in case of success, -1 in case of error.
*/
-static int virLogDump(void *data, virLogOutputFunc f) {
- int ret = 0, tmp;
+int
+virLogDump(void *data, virLogDumpFunc f) {
+ int ret = 0, tmp, len;
if ((virLogLen == 0) || (f == NULL))
return 0;
virLogLock();
- if (virLogStart + virLogLen < LOG_BUFFER_SIZE) {
-push_end:
- virLogBuffer[virLogStart + virLogLen] = 0;
- tmp = f(data, &virLogBuffer[virLogStart], virLogLen);
- if (tmp < 0) {
- ret = -1;
- goto error;
- }
- ret += tmp;
- virLogStart += tmp;
- virLogLen -= tmp;
- } else {
- tmp = LOG_BUFFER_SIZE - virLogStart;
- ret = f(data, &virLogBuffer[virLogStart], tmp);
- if (ret < 0) {
- ret = -1;
- goto error;
- }
- if (ret < tmp) {
- virLogStart += ret;
- virLogLen -= ret;
+ while (virLogLen > 0) {
+ if (virLogStart + virLogLen < LOG_BUFFER_SIZE) {
+ virLogBuffer[virLogStart + virLogLen] = 0;
+ tmp = f(data, &virLogBuffer[virLogStart], virLogLen);
+ if (tmp <= 0) {
+ ret = -1;
+ goto error;
+ }
+ ret += tmp;
+ virLogStart += tmp;
+ virLogLen -= tmp;
} else {
- virLogStart = 0;
+ len = LOG_BUFFER_SIZE - virLogStart;
+ virLogBuffer[LOG_BUFFER_SIZE] = 0;
+ tmp = f(data, &virLogBuffer[virLogStart], len);
+ if (tmp <= 0) {
+ ret = -1;
+ goto error;
+ }
virLogLen -= tmp;
- /* dump the second part */
- if (virLogLen > 0)
- goto push_end;
+ if (tmp < len)
+ virLogStart += tmp;
+ else
+ virLogStart = 0;
}
}
error:
virLogUnlock();
return ret;
}
-#endif
/**
* virLogSetDefaultPriority:
diff --git a/src/util/logging.h b/src/util/logging.h
index 2e2734e..df70aca 100644
--- a/src/util/logging.h
+++ b/src/util/logging.h
@@ -133,5 +133,17 @@ extern int virLogParseOutputs(const char *output);
extern void virLogMessage(const char *category, int priority,
const char *funcname, long long linenr, int flags,
const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(6, 7);
+/**
+ * virLogDumpFunc:
+ * @data: user argument
+ * @buf: the buffer
+ * @len: the lenght of the buffer in bytes without the terminating zero
+ *
+ * Callback function used to dump the log buffer
+ *
+ * Returns the number of bytes written or -1 in case of error
+ */
+typedef int (*virLogDumpFunc) (void *data, const char *buf, int len);
+extern int virLogDump(void *data, virLogDumpFunc f);
#endif
--
libvir-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libvir-list