goto fail;
}
+ qemu_errors_to_mon(mon);
switch(nb_args) {
case 0:
handler_0 = cmd->handler;
break;
default:
monitor_printf(mon, "unsupported number of arguments: %d\n", nb_args);
- goto fail;
+ break;
}
+ qemu_errors_to_previous();
+
fail:
for(i = 0; i < MAX_ARGS; i++)
qemu_free(str_allocated[i]);
if (err && completion_cb)
completion_cb(opaque, err);
}
+
+typedef struct QemuErrorSink QemuErrorSink;
+struct QemuErrorSink {
+ enum {
+ ERR_SINK_FILE,
+ ERR_SINK_MONITOR,
+ } dest;
+ union {
+ FILE *fp;
+ Monitor *mon;
+ };
+ QemuErrorSink *previous;
+};
+
+static __thread 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;
+ }
+}
int qemu_savevm_state(QEMUFile *f);
int qemu_loadvm_state(QEMUFile *f);
+void qemu_errors_to_file(FILE *fp);
+void qemu_errors_to_mon(Monitor *mon);
+void qemu_errors_to_previous(void);
+void qemu_error(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
+
#ifdef _WIN32
/* Polling handling */