1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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;
}
}
|