Patchwork [09/50] error: Move qemu_error() & friends from monitor.c to own file

login
register
mail settings
Submitter Markus Armbruster
Date March 4, 2010, 3:56 p.m.
Message ID <1267718231-13303-10-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/46923/
State New
Headers show

Comments

Markus Armbruster - March 4, 2010, 3:56 p.m.
They're about reporting errors, not about the monitor.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 Makefile.target |    1 +
 monitor.c       |   89 -----------------------------------------------------
 qemu-error.c    |   92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 89 deletions(-)
 create mode 100644 qemu-error.c

Patch

diff --git a/Makefile.target b/Makefile.target
index 320f807..2d85a8e 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -169,6 +169,7 @@  endif #CONFIG_BSD_USER
 ifdef CONFIG_SOFTMMU
 
 obj-y = vl.o async.o monitor.o pci.o pci_host.o pcie_host.o machine.o gdbstub.o
+obj-y += qemu-error.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-pci.o virtio-serial-bus.o
diff --git a/monitor.c b/monitor.c
index da52cb4..35b4677 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4683,92 +4683,3 @@  int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
 
     return err;
 }
-
-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;
-    }
-}
diff --git a/qemu-error.c b/qemu-error.c
new file mode 100644
index 0000000..df381f6
--- /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;
+    }
+}