diff options
author | Eamon Walsh <ewalsh@tycho.nsa.gov> | 2011-06-01 18:40:23 -0400 |
---|---|---|
committer | Eamon Walsh <ewalsh@tycho.nsa.gov> | 2011-06-01 18:43:00 -0400 |
commit | 16bd63704f341720f4d5a8264f987e0124d942d0 (patch) | |
tree | c3028c040359a8ae325007b6f212556d6fa3900a /src | |
parent | 4960035d9cec1eff71242a4ffd4b761140adf989 (diff) |
Log to files in /var/log/xen and add compile-time loglevel.
Diffstat (limited to 'src')
-rw-r--r-- | src/comm.c | 7 | ||||
-rw-r--r-- | src/common.h | 4 | ||||
-rw-r--r-- | src/display.h | 17 | ||||
-rw-r--r-- | src/fd.c | 60 | ||||
-rw-r--r-- | src/fd.h | 19 | ||||
-rw-r--r-- | src/input.c | 10 | ||||
-rw-r--r-- | src/local.c | 6 | ||||
-rw-r--r-- | src/monitor.c | 9 | ||||
-rw-r--r-- | src/server.c | 9 | ||||
-rw-r--r-- | src/xen_backend.c | 91 | ||||
-rw-r--r-- | src/xen_backend.h | 4 | ||||
-rw-r--r-- | src/xen_console.c | 10 | ||||
-rw-r--r-- | src/xen_linpicker.h | 8 | ||||
-rw-r--r-- | src/xen_monitor.c | 2 | ||||
-rw-r--r-- | src/xen_server.c | 6 | ||||
-rw-r--r-- | src/xenfb_monitor.c | 4 | ||||
-rw-r--r-- | src/xenfb_server.c | 32 |
17 files changed, 186 insertions, 112 deletions
@@ -3,6 +3,7 @@ #include <stdio.h> #include <string.h> +#include "fd.h" #include "comm.h" #include "view.h" #include "buffer.h" @@ -69,11 +70,11 @@ comm_create(struct client *c, struct buffer *b, struct lin_message *m) { struct view *v = view_lookup(c, m->view); if (v) - fprintf(stderr, "Warning: view %x already exists.\n", m->view); + FD_LOG(1, "Warning: view %x already exists.\n", m->view); else { v = view_new(c, b, m->view, 0); if (!v) { - fprintf(stderr, "Failed to create view!\n"); + FD_LOG(0, "Failed to create view!\n"); return; } v->mapped = 0; @@ -87,7 +88,7 @@ comm_update(struct client *c, struct buffer *b, struct lin_message *m) { struct view *v = view_lookup(c, m->view); if (!v) { - fprintf(stderr, "Warning: view %x does not exist.\n", m->view); + FD_LOG(1, "Warning: view %x does not exist.\n", m->view); return; } diff --git a/src/common.h b/src/common.h index 95bb849..1677148 100644 --- a/src/common.h +++ b/src/common.h @@ -5,6 +5,10 @@ #define LINPICKER_TOKEN "@i" #define LINPICKER_VPORT 6000 +/* Log files */ +#define SERVER_LOG "/var/log/xen/linpicker-server.log" +#define MONITOR_LOG "/var/log/xen/linpicker-monitor.log" + /* Security label dimensions */ #define FONT_FILE PKGDATADIR "/decker.ttf" #define SERVER_BG_FILE PKGDATADIR "/serverbg.rgb" diff --git a/src/display.h b/src/display.h index 6cc5be5..1248ad2 100644 --- a/src/display.h +++ b/src/display.h @@ -20,6 +20,7 @@ #include <directfb.h> #include "common.h" +#include "fd.h" #include "view.h" #include "buffer.h" #include "client.h" @@ -113,13 +114,13 @@ display_get_width(void); int display_get_height(void); -#define DFBCHECK(x...) \ - { \ - int ret = x; \ - if (ret != DFB_OK) { \ - fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \ - DirectFBErrorFatal( #x, ret ); \ - } \ - } +#define DFBCHECK(x...) \ + { \ + int ret = x; \ + if (ret != DFB_OK) { \ + FD_LOG(0, "%s <%d>:\n\t", __FILE__, __LINE__ ); \ + DirectFBErrorFatal( #x, ret ); \ + } \ + } #endif /* _LINPICKER_DISPLAY_H_ */ @@ -1,14 +1,70 @@ +#define _GNU_SOURCE #include <sys/types.h> #include <sys/select.h> #include <stdlib.h> #include <stdio.h> +#include <stdarg.h> #include <string.h> +#include <unistd.h> +#include <fcntl.h> #include <errno.h> #include "common.h" #include "sys-queue.h" #include "fd.h" +void +fd_vlog(const char *fmt, va_list args) +{ + vfprintf(stderr, fmt, args); +} + +void +fd_log(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vfprintf(stderr, fmt, args); + va_end(args); +} + +int +fd_open_logfile(const char *path) +{ + int nullfd, logfd; + char *oldpath; + + /* Redirect stdin and stdout to /dev/null */ + nullfd = open("/dev/null", O_RDWR); + if (nullfd < 0) { + perror("Failed to open /dev/null"); + return -1; + } + dup2(nullfd, 0); + dup2(nullfd, 1); + + /* Attempt to save the old logfile */ + if (asprintf(&oldpath, "%s.1", path) > 0) { + rename(path, oldpath); + free(oldpath); + } + + /* Attempt to redirect stderr to the logfile */ + logfd = open(path, O_WRONLY|O_CREAT|O_TRUNC); + if (logfd < 0) { + fprintf(stderr, "Warning: failed to open logfile '%s': %m\n", path); + dup2(nullfd, 2); + } else { + dup2(logfd, 2); + close(logfd); + } + + close(nullfd); + return 0; +} + +/* -------------------------------------------------------------------- */ + struct listener { LIST_ENTRY(listener) next; int fd; @@ -63,7 +119,7 @@ fd_run_select(void) if (rc < 0) { if (errno == EAGAIN || errno == EINTR) return 0; - perror("select"); + FD_LOG(0, "select() failed: %m\n"); return -1; } @@ -84,7 +140,7 @@ loop: } void -fd_free_handlers(void) +fd_shutdown(void) { struct listener *l; @@ -1,8 +1,25 @@ #ifndef _LINPICKER_FD_H_ #define _LINPICKER_FD_H_ +#include "config.h" + typedef void (*fd_handler)(void *closure); +#define FD_LOG(lvl, msg...) \ + do { \ + if (lvl <= LOGLEVEL) \ + fd_log(msg); \ + } while (0) + +void +fd_vlog(const char *fmt, va_list args); + +void +fd_log(const char *fmt, ...); + +int +fd_open_logfile(const char *path); + int fd_set_handler(int fd, fd_handler callback, void *closure); @@ -10,6 +27,6 @@ int fd_run_select(void); void -fd_free_handlers(void); +fd_shutdown(void); #endif /* _LINPICKER_FD_H_ */ diff --git a/src/input.c b/src/input.c index 7d7a3b8..cb45d79 100644 --- a/src/input.c +++ b/src/input.c @@ -194,7 +194,7 @@ configure_absolute_device(int fd) ai.maximum = display_get_width() - 1; if (ioctl(fd, EVIOCSABS(ABS_X), &ai) < 0) { - perror("EVIOCSABS"); + FD_LOG(0, "ioctl EVIOCSABS failed: %m\n"); return -1; } @@ -205,7 +205,7 @@ configure_absolute_device(int fd) ai.maximum = display_get_height() - 1; if (ioctl(fd, EVIOCSABS(ABS_Y), &ai) < 0) { - perror("EVIOCSABS"); + FD_LOG(0, "ioctl EVIOCSABS failed: %m\n"); return -1; } @@ -252,7 +252,7 @@ open_device(const char *path) TAILQ_INSERT_TAIL(&devices, d, next); return 0; err: - fprintf(stderr, "Warning: failed to open device '%s' on %s\n", name, path); + FD_LOG(1, "Warning: failed to open device '%s' on %s\n", name, path); free(d); if (fd >= 0) { ioctl(fd, EVIOCGRAB, 0); @@ -331,7 +331,7 @@ device_removed(struct udev_device *udev_device) return; } - fprintf(stderr, "Warning: failed to close device %s\n", path); + FD_LOG(2, "Warning: failed to close device %s\n", path); } static void @@ -389,7 +389,7 @@ input_initialize(int argc, char *argv[]) return 0; err: - fprintf(stderr, "Failed to set up udev.\n"); + FD_LOG(0, "Failed to set up udev.\n"); return -1; } diff --git a/src/local.c b/src/local.c index a32b955..f22eaa0 100644 --- a/src/local.c +++ b/src/local.c @@ -27,7 +27,7 @@ local_process(void *closure) if (rc < 0) { if (errno == EAGAIN || errno == EINTR) return; - perror("recv"); + FD_LOG(0, "recv() failed: %m\n"); return; } else if (rc == 1) { switch (msg) { @@ -49,7 +49,7 @@ local_init(int argc, char **argv) /* Listen on a local socket */ sd = socket(AF_UNIX, SOCK_DGRAM, 0); if (sd < 0) { - perror("socket"); + FD_LOG(0, "socket() failed: %m\n"); return -1; } @@ -59,7 +59,7 @@ local_init(int argc, char **argv) rc = bind(sd, (struct sockaddr *)&addr, sizeof(addr)); if (rc < 0) { - perror("bind"); + FD_LOG(0, "bind() failed: %m\n"); return -1; } diff --git a/src/monitor.c b/src/monitor.c index 17253ac..c129b63 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -7,9 +7,10 @@ #include <signal.h> #include <errno.h> +#include "common.h" +#include "fd.h" #include "xen_backend.h" #include "sys-queue.h" -#include "fd.h" extern int xenfb_monitor_init(void); @@ -35,6 +36,10 @@ int main (int argc, char *argv[]) sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); + /* Open logfile */ + if (fd_open_logfile(MONITOR_LOG) < 0) + return 1; + /* Initialize subsystems */ if (xen_be_init() < 0) return 1; @@ -45,6 +50,6 @@ int main (int argc, char *argv[]) while (!timetodie && fd_run_select() == 0); /* Shut down */ - fd_free_handlers(); + fd_shutdown(); return 0; } diff --git a/src/server.c b/src/server.c index 1ba43be..033bbe4 100644 --- a/src/server.c +++ b/src/server.c @@ -17,12 +17,13 @@ #include <signal.h> #include <errno.h> +#include "common.h" +#include "fd.h" #include "xen_backend.h" #include "sys-queue.h" #include "display.h" #include "input.h" #include "local.h" -#include "fd.h" static int timetodie; @@ -46,6 +47,10 @@ int main (int argc, char *argv[]) sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); + /* Open logfile */ + if (fd_open_logfile(SERVER_LOG) < 0) + return 1; + /* Initialize subsystems */ if (local_init(argc, argv) < 0) return 1; @@ -62,6 +67,6 @@ int main (int argc, char *argv[]) /* Shut down */ input_shutdown(); display_shutdown(); - fd_free_handlers(); + fd_shutdown(); return 0; } diff --git a/src/xen_backend.c b/src/xen_backend.c index d6fca41..73f1a0b 100644 --- a/src/xen_backend.c +++ b/src/xen_backend.c @@ -44,7 +44,6 @@ const char *xen_protocol; /* private */ static TAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = TAILQ_HEAD_INITIALIZER(xendevs); -static int debug = 0; /* ------------------------------------------------------------- */ @@ -140,7 +139,7 @@ int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state) rc = xen_linpicker_be_set_state(xendev, state); if (rc < 0) return rc; - xen_be_printf(xendev, 1, "backend state: %s -> %s\n", + XEN_BE_LOG(xendev, 1, "backend state: %s -> %s\n", xenbus_strstate(xendev->be_state), xenbus_strstate(state)); xendev->be_state = state; return 0; @@ -201,19 +200,18 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, xendev->dom, xendev->type, xendev->dev); free(dom0); - xendev->debug = debug; xendev->local_port = -1; xendev->evtchndev = xc_evtchn_open(NULL, 0); if (xendev->evtchndev < 0) { - xen_be_printf(NULL, 0, "can't open evtchn device\n"); + XEN_BE_LOG(NULL, 0, "can't open evtchn device\n"); goto out_err1; } fcntl(xc_evtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC); xendev->gnttabdev = xc_gnttab_open(NULL, 0); if (xendev->gnttabdev < 0) { - xen_be_printf(NULL, 0, "can't open gnttab device\n"); + XEN_BE_LOG(NULL, 0, "can't open gnttab device\n"); goto out_err2; } @@ -285,7 +283,7 @@ static void xen_be_backend_changed(struct XenDevice *xendev, const char *node) } if (node) { - xen_be_printf(xendev, 2, "backend update: %s\n", node); + XEN_BE_LOG(xendev, 2, "backend update: %s\n", node); if (xendev->ops->backend_changed) xendev->ops->backend_changed(xendev, node); } @@ -299,7 +297,7 @@ static void xen_be_frontend_changed(struct XenDevice *xendev, const char *node) if (xenstore_read_fe_int(xendev, "state", &fe_state) == -1) fe_state = XenbusStateUnknown; if (xendev->fe_state != fe_state) - xen_be_printf(xendev, 1, "frontend state: %s -> %s\n", + XEN_BE_LOG(xendev, 1, "frontend state: %s -> %s\n", xenbus_strstate(xendev->fe_state), xenbus_strstate(fe_state)); xendev->fe_state = fe_state; @@ -308,11 +306,11 @@ static void xen_be_frontend_changed(struct XenDevice *xendev, const char *node) free(xendev->protocol); xendev->protocol = xenstore_read_fe_str(xendev, "protocol"); if (xendev->protocol) - xen_be_printf(xendev, 1, "frontend protocol: %s\n", xendev->protocol); + XEN_BE_LOG(xendev, 1, "frontend protocol: %s\n", xendev->protocol); } if (node) { - xen_be_printf(xendev, 2, "frontend update: %s\n", node); + XEN_BE_LOG(xendev, 2, "frontend update: %s\n", node); if (xendev->ops->frontend_changed) xendev->ops->frontend_changed(xendev, node); } @@ -335,14 +333,14 @@ static int xen_be_try_setup(struct XenDevice *xendev) xendev->fe = xenstore_read_be_str(xendev, "frontend"); if (xendev->fe == NULL) { - xen_be_printf(xendev, 0, "reading frontend path failed\n"); + XEN_BE_LOG(xendev, 0, "reading frontend path failed\n"); return -1; } /* setup frontend watch */ snprintf(token, sizeof(token), "fe:%p", xendev); if (!xs_watch(xenstore, xendev->fe, token)) { - xen_be_printf(xendev, 0, "watching frontend path (%s) failed\n", + XEN_BE_LOG(xendev, 0, "watching frontend path (%s) failed\n", xendev->fe); return -1; } @@ -366,14 +364,14 @@ static int xen_be_try_init(struct XenDevice *xendev) int rc = 0; if (!xendev->online) { - xen_be_printf(xendev, 1, "not online\n"); + XEN_BE_LOG(xendev, 1, "not online\n"); return -1; } if (xendev->ops->init) rc = xendev->ops->init(xendev); if (rc != 0) { - xen_be_printf(xendev, 1, "init() failed\n"); + XEN_BE_LOG(xendev, 1, "init() failed\n"); return rc; } @@ -396,9 +394,9 @@ static int xen_be_try_initialise(struct XenDevice *xendev) if (xendev->fe_state != XenbusStateInitialised && xendev->fe_state != XenbusStateConnected) { if (xendev->ops->flags & DEVOPS_FLAG_IGNORE_STATE) { - xen_be_printf(xendev, 2, "frontend not ready, ignoring\n"); + XEN_BE_LOG(xendev, 2, "frontend not ready, ignoring\n"); } else { - xen_be_printf(xendev, 2, "frontend not ready (yet)\n"); + XEN_BE_LOG(xendev, 2, "frontend not ready (yet)\n"); return -1; } } @@ -406,7 +404,7 @@ static int xen_be_try_initialise(struct XenDevice *xendev) if (xendev->ops->initialise) rc = xendev->ops->initialise(xendev); if (rc != 0) { - xen_be_printf(xendev, 0, "initialise() failed\n"); + XEN_BE_LOG(xendev, 0, "initialise() failed\n"); return rc; } @@ -426,9 +424,9 @@ static void xen_be_try_connected(struct XenDevice *xendev) if (xendev->fe_state != XenbusStateConnected) { if (xendev->ops->flags & DEVOPS_FLAG_IGNORE_STATE) { - xen_be_printf(xendev, 2, "frontend not ready, ignoring\n"); + XEN_BE_LOG(xendev, 2, "frontend not ready, ignoring\n"); } else { - xen_be_printf(xendev, 2, "frontend not ready (yet)\n"); + XEN_BE_LOG(xendev, 2, "frontend not ready (yet)\n"); return; } } @@ -459,7 +457,7 @@ static int xen_be_try_reset(struct XenDevice *xendev) if (xendev->fe_state != XenbusStateInitialising) return -1; - xen_be_printf(xendev, 1, "device reset (for re-connect)\n"); + XEN_BE_LOG(xendev, 1, "device reset (for re-connect)\n"); xen_be_set_state(xendev, XenbusStateInitialising); return 0; } @@ -520,7 +518,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)) { - xen_be_printf(NULL, 0, "xen be: watching backend path (%s) failed\n", path); + XEN_BE_LOG(NULL, 0, "xen be: watching backend path (%s) failed\n", path); return -1; } @@ -616,7 +614,7 @@ static void xen_be_evtchn_event(void *opaque) port = xc_evtchn_pending(xendev->evtchndev); if (port != xendev->local_port) { - xen_be_printf(xendev, 0, "xc_evtchn_pending returned %d (expected %d)\n", + XEN_BE_LOG(xendev, 0, "xc_evtchn_pending returned %d (expected %d)\n", port, xendev->local_port); return; } @@ -637,7 +635,7 @@ int xen_be_init(void) if (!xenstore) xenstore = xs_domain_open(); if (!xenstore) { - xen_be_printf(NULL, 0, "can't connect to xenstored\n"); + XEN_BE_LOG(NULL, 0, "can't connect to xenstored\n"); return -1; } @@ -646,12 +644,12 @@ int xen_be_init(void) xen_xc = xc_interface_open(0,0,0); if (!xen_xc) { - xen_be_printf(NULL, 0, "can't open xen interface\n"); + XEN_BE_LOG(NULL, 0, "can't open xen interface\n"); goto err; } if (xen_linpicker_init(xenstore, xen_xc) != 0) { - xen_be_printf(NULL, 0, "intro/release watch setup failed\n"); + XEN_BE_LOG(NULL, 0, "intro/release watch setup failed\n"); goto err2; } @@ -679,10 +677,10 @@ int xen_be_bind_evtchn(struct XenDevice *xendev) xendev->local_port = xc_evtchn_bind_interdomain (xendev->evtchndev, xendev->dom, xendev->remote_port); if (xendev->local_port == -1) { - xen_be_printf(xendev, 0, "xc_evtchn_bind_interdomain failed\n"); + XEN_BE_LOG(xendev, 0, "xc_evtchn_bind_interdomain failed\n"); return -1; } - xen_be_printf(xendev, 2, "bind evtchn port %d\n", xendev->local_port); + XEN_BE_LOG(xendev, 2, "bind evtchn port %d\n", xendev->local_port); fd_set_handler(xc_evtchn_fd(xendev->evtchndev), xen_be_evtchn_event, xendev); return 0; @@ -694,7 +692,7 @@ void xen_be_unbind_evtchn(struct XenDevice *xendev) return; fd_set_handler(xc_evtchn_fd(xendev->evtchndev), NULL, NULL); xc_evtchn_unbind(xendev->evtchndev, xendev->local_port); - xen_be_printf(xendev, 2, "unbind evtchn port %d\n", xendev->local_port); + XEN_BE_LOG(xendev, 2, "unbind evtchn port %d\n", xendev->local_port); xendev->local_port = -1; } @@ -703,37 +701,16 @@ int xen_be_send_notify(struct XenDevice *xendev) return xc_evtchn_notify(xendev->evtchndev, xendev->local_port); } -/* - * msg_level: - * 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, ...) +void xen_be_printf(struct XenDevice *xendev, const char *fmt, ...) { va_list args; - if (xendev) { -// if (msg_level > xendev->debug) -// return; -// qemu_log("xen be: %s: ", xendev->name); - if (msg_level <= 2) - fprintf(stderr, "xen be: %s: ", xendev->name); - } else { -// if (msg_level > debug) -// return; -// qemu_log("xen be core: "); - if (msg_level <= 2) - fprintf(stderr, "xen be core: "); - } -// va_start(args, fmt); -// qemu_log_vprintf(fmt, args); -// va_end(args); - if (msg_level <= 2) { - va_start(args, fmt); - vfprintf(stderr, fmt, args); - va_end(args); - } -// qemu_log_flush(); + if (xendev) + fd_log("xen be: %s: ", xendev->name); + else + fd_log("xen be core: "); + + va_start(args, fmt); + fd_vlog(fmt, args); + va_end(args); } diff --git a/src/xen_backend.h b/src/xen_backend.h index 91255a2..8a36c75 100644 --- a/src/xen_backend.h +++ b/src/xen_backend.h @@ -89,8 +89,8 @@ int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state); int xen_be_bind_evtchn(struct XenDevice *xendev); void xen_be_unbind_evtchn(struct XenDevice *xendev); int xen_be_send_notify(struct XenDevice *xendev); -void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...) - __attribute__ ((format(printf, 3, 4))); +void xen_be_printf(struct XenDevice *xendev, const char *fmt, ...) + __attribute__ ((format(printf, 2, 3))); /* actual backend drivers */ extern struct XenDevOps xen_console_ops; /* xen_console.c */ diff --git a/src/xen_console.c b/src/xen_console.c index 045b388..8f486a4 100644 --- a/src/xen_console.c +++ b/src/xen_console.c @@ -166,13 +166,13 @@ static void xencons_send(struct XenConsole *con) if (len < 1) { if (!con->backlog) { con->backlog = 1; - xen_be_printf(&con->xendev, 1, "backlog piling up, nobody listening?\n"); + XEN_BE_LOG(&con->xendev, 1, "backlog piling up, nobody listening?\n"); } } else { buffer_advance(&con->buffer, len); if (con->backlog && len == size) { con->backlog = 0; - xen_be_printf(&con->xendev, 1, "backlog is gone\n"); + XEN_BE_LOG(&con->xendev, 1, "backlog is gone\n"); } } } @@ -194,7 +194,7 @@ static int con_init(struct XenDevice *xendev) type = xenstore_read_str(con->console, "type"); if (!type || 0 != strcmp(type, "ioemu")) { - xen_be_printf(xendev, 1, "not for me (type=%s)\n", type); + XEN_BE_LOG(xendev, 1, "not for me (type=%s)\n", type); if (type) qemu_free(type); return -1; @@ -202,7 +202,7 @@ static int con_init(struct XenDevice *xendev) qemu_free(type); if (!serial_hds[con->xendev.dev]) - xen_be_printf(xendev, 1, "WARNING: serial line %d not configured\n", + XEN_BE_LOG(xendev, 1, "WARNING: serial line %d not configured\n", con->xendev.dev); else con->chr = serial_hds[con->xendev.dev]; @@ -239,7 +239,7 @@ static int con_initialise(struct XenDevice *xendev) qemu_chr_add_handlers(con->chr, xencons_can_receive, xencons_receive, NULL, con); - xen_be_printf(xendev, 1, "ring mfn %d, remote port %d, local port %d, limit %zd\n", + XEN_BE_LOG(xendev, 1, "ring mfn %d, remote port %d, local port %d, limit %zd\n", con->ring_ref, con->xendev.remote_port, con->xendev.local_port, diff --git a/src/xen_linpicker.h b/src/xen_linpicker.h index a5e1d18..ce56883 100644 --- a/src/xen_linpicker.h +++ b/src/xen_linpicker.h @@ -5,6 +5,7 @@ #include <xs.h> #include <xen/io/xenbus.h> +#include "config.h" #include "common.h" #include "xen_backend.h" #include "fd.h" @@ -12,6 +13,13 @@ #include "display.h" #include "input.h" +/* logging */ +#define XEN_BE_LOG(xendev, lvl, msg...) \ + do { \ + if (lvl <= LOGLEVEL) \ + xen_be_printf(xendev, msg); \ + } while (0) + /* domain creation watch */ int xen_linpicker_init(struct xs_handle *, xc_interface*); int xen_linpicker_update(struct xs_handle *, xc_interface*, const char *); diff --git a/src/xen_monitor.c b/src/xen_monitor.c index 60f60e3..a2ce7d3 100644 --- a/src/xen_monitor.c +++ b/src/xen_monitor.c @@ -92,7 +92,7 @@ xen_linpicker_scan_domains(struct xs_handle *xenstore, int newdom) e = xs_directory(xenstore, XBT_NULL, "/local/domain", &n); if (!e) { - xen_be_printf(NULL, 0, "cannot list domains\n"); + XEN_BE_LOG(NULL, 0, "cannot list domains\n"); return; } diff --git a/src/xen_server.c b/src/xen_server.c index 2cff419..8025c04 100644 --- a/src/xen_server.c +++ b/src/xen_server.c @@ -45,7 +45,7 @@ vchan_shutdown(struct dominfo *d) TAILQ_REMOVE(&vchans, d, next); fd_set_handler(d->fd, NULL, NULL); libvchan_close(d->ctrl); - fprintf(stderr, "Tore down vchan for domain %d\n", d->domid); + XEN_BE_LOG(NULL, 1, "Tore down vchan for domain %d\n", d->domid); free(d); } @@ -128,7 +128,7 @@ vchan_setup(struct xs_handle *xenstore, xc_interface* xen_xc, const char *path) vchan_queue(d); TAILQ_INSERT_TAIL(&vchans, d, next); - fprintf(stderr, "Set up vchan for domain %d\n", domid); + XEN_BE_LOG(NULL, 1, "Set up vchan for domain %d\n", domid); return 0; err: free(d); @@ -235,7 +235,7 @@ xen_linpicker_scan_domains(struct xs_handle *xenstore, int newdom) e = xs_directory(xenstore, XBT_NULL, "/local/domain", &n); if (!e) { - xen_be_printf(NULL, 0, "cannot list domains\n"); + XEN_BE_LOG(NULL, 0, "cannot list domains\n"); return; } diff --git a/src/xenfb_monitor.c b/src/xenfb_monitor.c index c1a33fa..3a163f1 100644 --- a/src/xenfb_monitor.c +++ b/src/xenfb_monitor.c @@ -100,7 +100,7 @@ static int fb_initialise(struct XenDevice *xendev) if (update) xenstore_write_be_int(xendev, "request-update", 1); - xen_be_printf(xendev, 1, "feature-update=%d, videoram=%d\n", + XEN_BE_LOG(xendev, 1, "feature-update=%d, videoram=%d\n", update, videoram); return 0; } @@ -117,7 +117,7 @@ static void fb_frontend_changed(struct XenDevice *xendev, const char *node) if (fb->bug_trigger == 0 && strcmp(node, "state") == 0 && xendev->fe_state == XenbusStateConnected && xendev->be_state == XenbusStateConnected) { - xen_be_printf(xendev, 2, "re-trigger connected (frontend bug)\n"); + XEN_BE_LOG(xendev, 2, "re-trigger connected (frontend bug)\n"); xen_be_set_state(xendev, XenbusStateConnected); fb->bug_trigger = 1; /* only once */ } diff --git a/src/xenfb_server.c b/src/xenfb_server.c index 536c5ae..9aee8c4 100644 --- a/src/xenfb_server.c +++ b/src/xenfb_server.c @@ -70,7 +70,7 @@ static int common_bind(struct common *c) return -1; xen_be_bind_evtchn(&c->xendev); - xen_be_printf(&c->xendev, 1, "ring ref %d, remote-port %d, local-port %d\n", + XEN_BE_LOG(&c->xendev, 1, "ring ref %d, remote-port %d, local-port %d\n", ref, c->xendev.remote_port, c->xendev.local_port); return 0; @@ -350,38 +350,38 @@ static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, int max_width, max_height; if (fb_len_lim > fb_len_max) { - xen_be_printf(&xenfb->c.xendev, 0, "fb size limit %zu exceeds %zu, corrected\n", + XEN_BE_LOG(&xenfb->c.xendev, 0, "fb size limit %zu exceeds %zu, corrected\n", fb_len_lim, fb_len_max); fb_len_lim = fb_len_max; } if (fb_len_lim && fb_len > fb_len_lim) { - xen_be_printf(&xenfb->c.xendev, 0, "frontend fb size %zu limited to %zu\n", + XEN_BE_LOG(&xenfb->c.xendev, 0, "frontend fb size %zu limited to %zu\n", fb_len, fb_len_lim); fb_len = fb_len_lim; } if (depth != 32) { - xen_be_printf(&xenfb->c.xendev, 0, "can't handle frontend fb depth %d\n", + XEN_BE_LOG(&xenfb->c.xendev, 0, "can't handle frontend fb depth %d\n", depth); return -1; } if (row_stride <= 0 || row_stride > fb_len) { - xen_be_printf(&xenfb->c.xendev, 0, "invalid frontend stride %d\n", row_stride); + XEN_BE_LOG(&xenfb->c.xendev, 0, "invalid frontend stride %d\n", row_stride); return -1; } max_width = row_stride / (depth / 8); if (width < 0 || width > max_width) { - xen_be_printf(&xenfb->c.xendev, 0, "invalid frontend width %d limited to %d\n", + XEN_BE_LOG(&xenfb->c.xendev, 0, "invalid frontend width %d limited to %d\n", width, max_width); width = max_width; } if (offset < 0 || offset >= fb_len) { - xen_be_printf(&xenfb->c.xendev, 0, "invalid frontend offset %d (max %zu)\n", + XEN_BE_LOG(&xenfb->c.xendev, 0, "invalid frontend offset %d (max %zu)\n", offset, fb_len - 1); return -1; } max_height = (fb_len - offset) / row_stride; if (height < 0 || height > max_height) { - xen_be_printf(&xenfb->c.xendev, 0, "invalid frontend height %d limited to %d\n", + XEN_BE_LOG(&xenfb->c.xendev, 0, "invalid frontend height %d limited to %d\n", height, max_height); height = max_height; } @@ -393,7 +393,7 @@ static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, xenfb->offset = offset; xenfb->up_fullscreen = 1; xenfb->do_resize = 1; - xen_be_printf(&xenfb->c.xendev, 1, "framebuffer %dx%dx%d offset %d stride %d\n", + XEN_BE_LOG(&xenfb->c.xendev, 1, "framebuffer %dx%dx%d offset %d stride %d\n", width, height, depth, offset, row_stride); return 0; } @@ -469,7 +469,7 @@ static void xenfb_update(void *opaque) if (xenfb->refresh_period != period) { xenfb_send_refresh_period(xenfb, period); xenfb->refresh_period = period; - xen_be_printf(&xenfb->c.xendev, 1, "refresh period: %d\n", period); + XEN_BE_LOG(&xenfb->c.xendev, 1, "refresh period: %d\n", period); } #else ; /* nothing */ @@ -489,10 +489,10 @@ static void xenfb_update(void *opaque) /* run queued updates */ if (xenfb->up_fullscreen) { - xen_be_printf(&xenfb->c.xendev, 3, "update: fullscreen\n"); + XEN_BE_LOG(&xenfb->c.xendev, 3, "update: fullscreen\n"); xen_linpicker_fb_update(xenfb, 0, 0, xenfb->width, xenfb->height); } else if (xenfb->up_count) { - xen_be_printf(&xenfb->c.xendev, 3, "update: %d rects\n", xenfb->up_count); + XEN_BE_LOG(&xenfb->c.xendev, 3, "update: %d rects\n", xenfb->up_count); for (i = 0; i < xenfb->up_count; i++) xen_linpicker_fb_update(xenfb, xenfb->up_rects[i].x, @@ -500,7 +500,7 @@ static void xenfb_update(void *opaque) xenfb->up_rects[i].w, xenfb->up_rects[i].h); } else { - xen_be_printf(&xenfb->c.xendev, 3, "update: nothing\n"); + XEN_BE_LOG(&xenfb->c.xendev, 3, "update: nothing\n"); } xenfb->up_count = 0; xenfb->up_fullscreen = 0; @@ -537,14 +537,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) { - xen_be_printf(&xenfb->c.xendev, 1, "bogus update ignored\n"); + XEN_BE_LOG(&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) { - xen_be_printf(&xenfb->c.xendev, 1, "bogus update clipped\n"); + XEN_BE_LOG(&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, @@ -626,7 +626,7 @@ static int fb_initialise(struct XenDevice *xendev) if (xenstore_read_fe_int(xendev, "feature-update", &fb->feature_update) == -1) fb->feature_update = 0; - xen_be_printf(xendev, 1, "feature-update=%d, videoram=%d\n", + XEN_BE_LOG(xendev, 1, "feature-update=%d, videoram=%d\n", fb->feature_update, videoram); return xen_linpicker_fb_connect(fb); } |