blob: 0a175d82092fcc2fafb2edd0a60d4ca43f4ed57e [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 Armbruster1ecda022010-02-18 17:25:24 +010044/*
45 * Print an error message to current monitor if we have one, else to stderr.
46 * Appends a newline to the message.
Markus Armbrusterab5b0272010-03-02 18:15:09 +010047 * It's wrong to call this in a QMP monitor. Use qerror_report() there.
Markus Armbruster1ecda022010-02-18 17:25:24 +010048 */
49void error_report(const char *fmt, ...)
Markus Armbrusterb4a51f72010-02-17 10:55:46 +010050{
Markus Armbrusterba0fe872010-02-18 17:14:17 +010051 va_list ap;
Markus Armbrusterb4a51f72010-02-17 10:55:46 +010052
Markus Armbrusterba0fe872010-02-18 17:14:17 +010053 va_start(ap, fmt);
54 error_vprintf(fmt, ap);
55 va_end(ap);
Markus Armbruster1ecda022010-02-18 17:25:24 +010056 error_printf("\n");
Markus Armbrusterb4a51f72010-02-17 10:55:46 +010057}
58
Markus Armbrusterab5b0272010-03-02 18:15:09 +010059void qerror_report_internal(const char *file, int linenr, const char *func,
60 const char *fmt, ...)
Markus Armbrusterb4a51f72010-02-17 10:55:46 +010061{
62 va_list va;
63 QError *qerror;
64
Markus Armbrusterb4a51f72010-02-17 10:55:46 +010065 va_start(va, fmt);
66 qerror = qerror_from_info(file, linenr, func, fmt, &va);
67 va_end(va);
68
Markus Armbruster6e4f9842010-02-18 13:16:02 +010069 if (cur_mon) {
70 monitor_set_error(cur_mon, qerror);
71 } else {
Markus Armbrusterb4a51f72010-02-17 10:55:46 +010072 qerror_print(qerror);
73 QDECREF(qerror);
Markus Armbrusterb4a51f72010-02-17 10:55:46 +010074 }
75}