]> git.proxmox.com Git - mirror_qemu.git/blame - qemu-error.c
error: Don't abuse qemu_error() for non-error in scsi_hot_add()
[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
44void 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);
b4a51f7f
MA
51}
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
b4a51f7f
MA
59 va_start(va, fmt);
60 qerror = qerror_from_info(file, linenr, func, fmt, &va);
61 va_end(va);
62
6e4f984c
MA
63 if (cur_mon) {
64 monitor_set_error(cur_mon, qerror);
65 } else {
b4a51f7f
MA
66 qerror_print(qerror);
67 QDECREF(qerror);
b4a51f7f
MA
68 }
69}