summaryrefslogtreecommitdiff
path: root/qemu-error.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2010-02-17 10:55:46 +0100
committerMarkus Armbruster <armbru@redhat.com>2010-03-16 16:55:05 +0100
commitb4a51f7f5d4855d1af7eb6ce6c6f79bd24d1d5a8 (patch)
treea24e61583d010d72d8a081722578e4986e4eb0e5 /qemu-error.c
parentd6f468337aba7eeeab0c7a772eda7491eb432cca (diff)
downloadqemu-b4a51f7f5d4855d1af7eb6ce6c6f79bd24d1d5a8.tar.gz
qemu-b4a51f7f5d4855d1af7eb6ce6c6f79bd24d1d5a8.tar.bz2
qemu-b4a51f7f5d4855d1af7eb6ce6c6f79bd24d1d5a8.zip
error: Move qemu_error() & friends from monitor.c to own file
They're about reporting errors, not about the monitor.
Diffstat (limited to 'qemu-error.c')
-rw-r--r--qemu-error.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/qemu-error.c b/qemu-error.c
new file mode 100644
index 0000000000..df381f679e
--- /dev/null
+++ b/qemu-error.c
@@ -0,0 +1,92 @@
+#include <stdio.h>
+#include "monitor.h"
+#include "sysemu.h"
+
+typedef struct QemuErrorSink QemuErrorSink;
+struct QemuErrorSink {
+ enum {
+ ERR_SINK_FILE,
+ ERR_SINK_MONITOR,
+ } dest;
+ union {
+ FILE *fp;
+ Monitor *mon;
+ };
+ QemuErrorSink *previous;
+};
+
+static QemuErrorSink *qemu_error_sink;
+
+void qemu_errors_to_file(FILE *fp)
+{
+ QemuErrorSink *sink;
+
+ sink = qemu_mallocz(sizeof(*sink));
+ sink->dest = ERR_SINK_FILE;
+ sink->fp = fp;
+ sink->previous = qemu_error_sink;
+ qemu_error_sink = sink;
+}
+
+void qemu_errors_to_mon(Monitor *mon)
+{
+ QemuErrorSink *sink;
+
+ sink = qemu_mallocz(sizeof(*sink));
+ sink->dest = ERR_SINK_MONITOR;
+ sink->mon = mon;
+ sink->previous = qemu_error_sink;
+ qemu_error_sink = sink;
+}
+
+void qemu_errors_to_previous(void)
+{
+ QemuErrorSink *sink;
+
+ assert(qemu_error_sink != NULL);
+ sink = qemu_error_sink;
+ qemu_error_sink = sink->previous;
+ qemu_free(sink);
+}
+
+void qemu_error(const char *fmt, ...)
+{
+ va_list args;
+
+ assert(qemu_error_sink != NULL);
+ switch (qemu_error_sink->dest) {
+ case ERR_SINK_FILE:
+ va_start(args, fmt);
+ vfprintf(qemu_error_sink->fp, fmt, args);
+ va_end(args);
+ break;
+ case ERR_SINK_MONITOR:
+ va_start(args, fmt);
+ monitor_vprintf(qemu_error_sink->mon, fmt, args);
+ va_end(args);
+ break;
+ }
+}
+
+void qemu_error_internal(const char *file, int linenr, const char *func,
+ const char *fmt, ...)
+{
+ va_list va;
+ QError *qerror;
+
+ assert(qemu_error_sink != NULL);
+
+ va_start(va, fmt);
+ qerror = qerror_from_info(file, linenr, func, fmt, &va);
+ va_end(va);
+
+ switch (qemu_error_sink->dest) {
+ case ERR_SINK_FILE:
+ qerror_print(qerror);
+ QDECREF(qerror);
+ break;
+ case ERR_SINK_MONITOR:
+ monitor_set_error(qemu_error_sink->mon, qerror);
+ break;
+ }
+}