Use new logging API.
Kill a few fprintf(stderr, "...") calls.
Signed-off-by: Gerd Hoffmann <kraxel@xxxxxxxxxx>
---
hw/xen_backend.c | 42 +++++++++++++++++++++++++++++-------------
hw/xen_console.c | 6 ------
hw/xenfb.c | 15 +++++++--------
3 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/hw/xen_backend.c b/hw/xen_backend.c
index bb02634..2f2ec7f 100644
--- a/hw/xen_backend.c
+++ b/hw/xen_backend.c
@@ -209,7 +209,7 @@ static struct XenDevice *xen_be_get_xendev(const char
*type, int dom, int dev,
xendev->evtchndev = xc_evtchn_open();
if (xendev->evtchndev < 0) {
- fprintf(stderr, "can't open evtchn device\n");
+ xen_be_printf(NULL, 0, "can't open evtchn device\n");
qemu_free(xendev);
return NULL;
}
@@ -218,7 +218,7 @@ static struct XenDevice *xen_be_get_xendev(const char
*type, int dom, int dev,
if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
xendev->gnttabdev = xc_gnttab_open();
if (xendev->gnttabdev < 0) {
- fprintf(stderr, "can't open gnttab device\n");
+ xen_be_printf(NULL, 0, "can't open gnttab device\n");
xc_evtchn_close(xendev->evtchndev);
qemu_free(xendev);
return NULL;
@@ -511,7 +511,7 @@ static int xenstore_scan(const char *type, int dom, struct
XenDevOps *ops)
snprintf(path, sizeof(path), "%s/backend/%s/%d", dom0, type, dom);
free(dom0);
if (!xs_watch(xenstore, path, token)) {
- fprintf(stderr, "xen be: watching backend path (%s) failed\n", path);
+ xen_be_printf(NULL, 0, "xen be: watching backend path (%s) failed\n",
path);
return -1;
}
@@ -620,7 +620,7 @@ int xen_be_init(void)
{
xenstore = xs_daemon_open();
if (!xenstore) {
- fprintf(stderr, "can't connect to xenstored\n");
+ xen_be_printf(NULL, 0, "can't connect to xenstored\n");
return -1;
}
@@ -629,7 +629,7 @@ int xen_be_init(void)
xen_xc = xc_interface_open();
if (xen_xc == -1) {
- fprintf(stderr, "can't open xen interface\n");
+ xen_be_printf(NULL, 0, "can't open xen interface\n");
goto err;
}
return 0;
@@ -680,19 +680,35 @@ int xen_be_send_notify(struct XenDevice *xendev)
/*
* msg_level:
- * 0 == errors.
- * 1 == informative debug messages.
- * 2 == noisy debug messages.
- * 3 == will flood your log.
+ * 0 == errors (stderr + logfile).
+ * 1 == informative debug messages (logfile only).
+ * 2 == noisy debug messages (logfile only).
+ * 3 == will flood your log (logfile only).
*/
void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt,
...)
{
va_list args;
- if (msg_level > xendev->debug)
- return;
- fprintf(stderr, "xen be: %s: ", xendev->name);
+ if (xendev) {
+ if (msg_level > xendev->debug)
+ return;
+ qemu_log("xen be: %s: ", xendev->name);
+ if (msg_level == 0)
+ fprintf(stderr, "xen be: %s: ", xendev->name);
+ } else {
+ if (msg_level > debug)
+ return;
+ qemu_log("xen be core: ");
+ if (msg_level == 0)
+ fprintf(stderr, "xen be core: ");
+ }
va_start(args, fmt);
- vfprintf(stderr, fmt, args);
+ qemu_log_vprintf(fmt, args);
va_end(args);
+ if (msg_level == 0) {
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ va_end(args);
+ }
+ qemu_log_flush();
}
diff --git a/hw/xen_console.c b/hw/xen_console.c
index 707075e..27f809d 100644
--- a/hw/xen_console.c
+++ b/hw/xen_console.c
@@ -38,8 +38,6 @@
#include "qemu-char.h"
#include "xen_backend.h"
-#define dolog(val, fmt, ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
-
struct buffer {
uint8_t *data;
size_t consumed;
@@ -75,10 +73,6 @@ static void buffer_append(struct XenConsole *con)
if ((buffer->capacity - buffer->size) < size) {
buffer->capacity += (size + 1024);
buffer->data = qemu_realloc(buffer->data, buffer->capacity);
- if (buffer->data == NULL) {
- dolog(LOG_ERR, "Memory allocation failed");
- exit(ENOMEM);
- }
}
while (cons != prod)
diff --git a/hw/xenfb.c b/hw/xenfb.c
index 1764ac2..d9e5c33 100644
--- a/hw/xenfb.c
+++ b/hw/xenfb.c
@@ -813,15 +813,14 @@ static void xenfb_handle_events(struct XenFB *xenfb)
w = MIN(event->update.width, xenfb->width - x);
h = MIN(event->update.height, xenfb->height - y);
if (w < 0 || h < 0) {
- fprintf(stderr, "xen be: %s: bogus update ignored\n",
- xenfb->c.xendev.name);
+ xen_be_printf(&xenfb->c.xendev, 1, "bogus update ignored\n");
break;
}
- if (x != event->update.x || y != event->update.y
- || w != event->update.width
- || h != event->update.height) {
- fprintf(stderr, "xen be: %s: bogus update clipped\n",
- xenfb->c.xendev.name);
+ if (x != event->update.x ||
+ y != event->update.y ||
+ w != event->update.width ||
+ h != event->update.height) {
+ xen_be_printf(&xenfb->c.xendev, 1, "bogus update clipped\n");
}
if (w == xenfb->width && h > xenfb->height / 2) {
/* scroll detector: updated more than 50% of the lines,
@@ -993,7 +992,7 @@ wait_more:
if (!xfb || !xin) {
if (i < 256)
goto wait_more;
- fprintf(stderr, "%s: displaystate setup failed\n", __FUNCTION__);
+ xen_be_printf(NULL, 1, "displaystate setup failed\n");
return;
}
--
1.6.2.2
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|