]> git.proxmox.com Git - qemu.git/blob - qemu-error.c
d20fd0f4d2868417974f6ab31d54f4f0cc6b307a
[qemu.git] / qemu-error.c
1 /*
2 * Error reporting
3 *
4 * Copyright (C) 2010 Red Hat Inc.
5 *
6 * Authors:
7 * Markus Armbruster <armbru@redhat.com>,
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
11 */
12
13 #include <stdio.h>
14 #include "monitor.h"
15 #include "sysemu.h"
16
17 /*
18 * Print to current monitor if we have one, else to stderr.
19 * TODO should return int, so callers can calculate width, but that
20 * requires surgery to monitor_vprintf(). Left for another day.
21 */
22 void error_vprintf(const char *fmt, va_list ap)
23 {
24 if (cur_mon) {
25 monitor_vprintf(cur_mon, fmt, ap);
26 } else {
27 vfprintf(stderr, fmt, ap);
28 }
29 }
30
31 /*
32 * Print to current monitor if we have one, else to stderr.
33 * TODO just like error_vprintf()
34 */
35 void error_printf(const char *fmt, ...)
36 {
37 va_list ap;
38
39 va_start(ap, fmt);
40 error_vprintf(fmt, ap);
41 va_end(ap);
42 }
43
44 void qemu_error(const char *fmt, ...)
45 {
46 va_list ap;
47
48 va_start(ap, fmt);
49 error_vprintf(fmt, ap);
50 va_end(ap);
51 }
52
53 void qemu_error_internal(const char *file, int linenr, const char *func,
54 const char *fmt, ...)
55 {
56 va_list va;
57 QError *qerror;
58
59 va_start(va, fmt);
60 qerror = qerror_from_info(file, linenr, func, fmt, &va);
61 va_end(va);
62
63 if (cur_mon) {
64 monitor_set_error(cur_mon, qerror);
65 } else {
66 qerror_print(qerror);
67 QDECREF(qerror);
68 }
69 }