summaryrefslogtreecommitdiff
path: root/qemu-error.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2010-02-18 13:16:02 +0100
committerMarkus Armbruster <armbru@redhat.com>2010-03-16 16:55:05 +0100
commit6e4f984cb9474db99bf4e3998ff86cdb9ed02380 (patch)
tree593183a7a30cf3c5263951af410c75489de0aa3c /qemu-error.c
parentb4a51f7f5d4855d1af7eb6ce6c6f79bd24d1d5a8 (diff)
error: Simplify error sink setup
qemu_error_sink can either point to a monitor or a file. In practice, it always points to the current monitor if we have one, else to stderr. Simply route errors to the current monitor or else to stderr, and remove qemu_error_sink along with the functions to control it. Actually, the old code switches the sink slightly later, in handle_user_command() and handle_qmp_command(), than it gets switched now, implicitly, by setting the current monitor in monitor_read() and monitor_control_read(). Likewise, it switches back slightly earlier (same places). Doesn't make a difference, because there are no calls of qemu_error() in between.
Diffstat (limited to 'qemu-error.c')
-rw-r--r--qemu-error.c76
1 files changed, 9 insertions, 67 deletions
diff --git a/qemu-error.c b/qemu-error.c
index df381f679..63bcdcfa1 100644
--- a/qemu-error.c
+++ b/qemu-error.c
@@ -2,70 +2,17 @@
#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;
+ va_start(args, fmt);
+ if (cur_mon) {
+ monitor_vprintf(cur_mon, fmt, args);
+ } else {
+ vfprintf(stderr, fmt, args);
}
+ va_end(args);
}
void qemu_error_internal(const char *file, int linenr, const char *func,
@@ -74,19 +21,14 @@ void qemu_error_internal(const char *file, int linenr, const char *func,
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:
+ if (cur_mon) {
+ monitor_set_error(cur_mon, qerror);
+ } else {
qerror_print(qerror);
QDECREF(qerror);
- break;
- case ERR_SINK_MONITOR:
- monitor_set_error(qemu_error_sink->mon, qerror);
- break;
}
}