blob: d20fd0f4d2868417974f6ab31d54f4f0cc6b307a [file] [log] [blame]
Markus Armbrusterba0fe872010-02-18 17:14:17 +01001/*
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
Markus Armbrusterb4a51f72010-02-17 10:55:46 +010013#include <stdio.h>
14#include "monitor.h"
15#include "sysemu.h"
16
Markus Armbrusterba0fe872010-02-18 17:14:17 +010017/*
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 */
22void 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 */
35void 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
Markus Armbrusterb4a51f72010-02-17 10:55:46 +010044void qemu_error(const char *fmt, ...)
45{
Markus Armbrusterba0fe872010-02-18 17:14:17 +010046 va_list ap;
Markus Armbrusterb4a51f72010-02-17 10:55:46 +010047
Markus Armbrusterba0fe872010-02-18 17:14:17 +010048 va_start(ap, fmt);
49 error_vprintf(fmt, ap);
50 va_end(ap);
Markus Armbrusterb4a51f72010-02-17 10:55:46 +010051}
52
53void qemu_error_internal(const char *file, int linenr, const char *func,
54 const char *fmt, ...)
55{
56 va_list va;
57 QError *qerror;
58
Markus Armbrusterb4a51f72010-02-17 10:55:46 +010059 va_start(va, fmt);
60 qerror = qerror_from_info(file, linenr, func, fmt, &va);
61 va_end(va);
62
Markus Armbruster6e4f9842010-02-18 13:16:02 +010063 if (cur_mon) {
64 monitor_set_error(cur_mon, qerror);
65 } else {
Markus Armbrusterb4a51f72010-02-17 10:55:46 +010066 qerror_print(qerror);
67 QDECREF(qerror);
Markus Armbrusterb4a51f72010-02-17 10:55:46 +010068 }
69}