2010-02-19 00:14:17 +08:00
|
|
|
/*
|
|
|
|
* Error reporting
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Markus Armbruster <armbru@redhat.com>,
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
2010-02-17 17:55:46 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "monitor.h"
|
|
|
|
#include "sysemu.h"
|
|
|
|
|
2010-02-19 00:14:17 +08:00
|
|
|
/*
|
|
|
|
* Print to current monitor if we have one, else to stderr.
|
|
|
|
* TODO should return int, so callers can calculate width, but that
|
|
|
|
* requires surgery to monitor_vprintf(). Left for another day.
|
|
|
|
*/
|
|
|
|
void error_vprintf(const char *fmt, va_list ap)
|
2010-02-17 17:55:46 +08:00
|
|
|
{
|
error: Simplify error sink setup
qemu_error_sink can either point to a monitor or a file. In practice,
it always points to the current monitor if we have one, else to
stderr. Simply route errors to the current monitor or else to stderr,
and remove qemu_error_sink along with the functions to control it.
Actually, the old code switches the sink slightly later, in
handle_user_command() and handle_qmp_command(), than it gets switched
now, implicitly, by setting the current monitor in monitor_read() and
monitor_control_read(). Likewise, it switches back slightly earlier
(same places). Doesn't make a difference, because there are no calls
of qemu_error() in between.
2010-02-18 20:16:02 +08:00
|
|
|
if (cur_mon) {
|
2010-02-19 00:14:17 +08:00
|
|
|
monitor_vprintf(cur_mon, fmt, ap);
|
error: Simplify error sink setup
qemu_error_sink can either point to a monitor or a file. In practice,
it always points to the current monitor if we have one, else to
stderr. Simply route errors to the current monitor or else to stderr,
and remove qemu_error_sink along with the functions to control it.
Actually, the old code switches the sink slightly later, in
handle_user_command() and handle_qmp_command(), than it gets switched
now, implicitly, by setting the current monitor in monitor_read() and
monitor_control_read(). Likewise, it switches back slightly earlier
(same places). Doesn't make a difference, because there are no calls
of qemu_error() in between.
2010-02-18 20:16:02 +08:00
|
|
|
} else {
|
2010-02-19 00:14:17 +08:00
|
|
|
vfprintf(stderr, fmt, ap);
|
2010-02-17 17:55:46 +08:00
|
|
|
}
|
2010-02-19 00:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print to current monitor if we have one, else to stderr.
|
|
|
|
* TODO just like error_vprintf()
|
|
|
|
*/
|
|
|
|
void error_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
error_vprintf(fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2010-02-19 00:25:24 +08:00
|
|
|
/*
|
|
|
|
* Print an error message to current monitor if we have one, else to stderr.
|
|
|
|
* Appends a newline to the message.
|
2010-03-03 01:15:09 +08:00
|
|
|
* It's wrong to call this in a QMP monitor. Use qerror_report() there.
|
2010-02-19 00:25:24 +08:00
|
|
|
*/
|
|
|
|
void error_report(const char *fmt, ...)
|
2010-02-19 00:14:17 +08:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
error_vprintf(fmt, ap);
|
|
|
|
va_end(ap);
|
2010-02-19 00:25:24 +08:00
|
|
|
error_printf("\n");
|
2010-02-17 17:55:46 +08:00
|
|
|
}
|
|
|
|
|
2010-03-03 01:15:09 +08:00
|
|
|
void qerror_report_internal(const char *file, int linenr, const char *func,
|
|
|
|
const char *fmt, ...)
|
2010-02-17 17:55:46 +08:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
QError *qerror;
|
|
|
|
|
|
|
|
va_start(va, fmt);
|
|
|
|
qerror = qerror_from_info(file, linenr, func, fmt, &va);
|
|
|
|
va_end(va);
|
|
|
|
|
error: Simplify error sink setup
qemu_error_sink can either point to a monitor or a file. In practice,
it always points to the current monitor if we have one, else to
stderr. Simply route errors to the current monitor or else to stderr,
and remove qemu_error_sink along with the functions to control it.
Actually, the old code switches the sink slightly later, in
handle_user_command() and handle_qmp_command(), than it gets switched
now, implicitly, by setting the current monitor in monitor_read() and
monitor_control_read(). Likewise, it switches back slightly earlier
(same places). Doesn't make a difference, because there are no calls
of qemu_error() in between.
2010-02-18 20:16:02 +08:00
|
|
|
if (cur_mon) {
|
|
|
|
monitor_set_error(cur_mon, qerror);
|
|
|
|
} else {
|
2010-02-17 17:55:46 +08:00
|
|
|
qerror_print(qerror);
|
|
|
|
QDECREF(qerror);
|
|
|
|
}
|
|
|
|
}
|