]> git.proxmox.com Git - mirror_qemu.git/blame - qemu-error.c
error: Rename qemu_error_new() to qerror_report()
[mirror_qemu.git] / qemu-error.c
CommitLineData
ba0fe87a
MA
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
b4a51f7f
MA
13#include <stdio.h>
14#include "monitor.h"
15#include "sysemu.h"
16
ba0fe87a
MA
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 */
22void error_vprintf(const char *fmt, va_list ap)
b4a51f7f 23{
6e4f984c 24 if (cur_mon) {
ba0fe87a 25 monitor_vprintf(cur_mon, fmt, ap);
6e4f984c 26 } else {
ba0fe87a 27 vfprintf(stderr, fmt, ap);
b4a51f7f 28 }
ba0fe87a
MA
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
1ecda02b
MA
44/*
45 * Print an error message to current monitor if we have one, else to stderr.
46 * Appends a newline to the message.
ab5b027e 47 * It's wrong to call this in a QMP monitor. Use qerror_report() there.
1ecda02b
MA
48 */
49void error_report(const char *fmt, ...)
ba0fe87a
MA
50{
51 va_list ap;
52
53 va_start(ap, fmt);
54 error_vprintf(fmt, ap);
55 va_end(ap);
1ecda02b 56 error_printf("\n");
b4a51f7f
MA
57}
58
ab5b027e
MA
59void qerror_report_internal(const char *file, int linenr, const char *func,
60 const char *fmt, ...)
b4a51f7f
MA
61{
62 va_list va;
63 QError *qerror;
64
b4a51f7f
MA
65 va_start(va, fmt);
66 qerror = qerror_from_info(file, linenr, func, fmt, &va);
67 va_end(va);
68
6e4f984c
MA
69 if (cur_mon) {
70 monitor_set_error(cur_mon, qerror);
71 } else {
b4a51f7f
MA
72 qerror_print(qerror);
73 QDECREF(qerror);
b4a51f7f
MA
74 }
75}