Index: qemud/qemud.c =================================================================== RCS file: /data/cvs/libxen/qemud/qemud.c,v retrieving revision 1.149 diff -u -r1.149 qemud.c --- qemud/qemud.c 12 May 2009 15:43:07 -0000 1.149 +++ qemud/qemud.c 19 May 2009 15:25:45 -0000 @@ -2673,13 +2673,13 @@ if (__init_daemon_priv (PU_RESETGROUPS | PU_CLEARLIMITSET, SYSTEM_UID, SYSTEM_UID, PRIV_XVM_CONTROL, NULL)) { - fprintf (stderr, "additional privileges are required\n"); + VIR_ERROR0(_("additional privileges are required\n")); return -1; } if (priv_set (PRIV_OFF, PRIV_ALLSETS, PRIV_FILE_LINK_ANY, PRIV_PROC_INFO, PRIV_PROC_SESSION, PRIV_PROC_EXEC, PRIV_PROC_FORK, NULL)) { - fprintf (stderr, "failed to set reduced privileges\n"); + VIR_ERROR0(_("failed to set reduced privileges\n")); return -1; } Index: src/console.c =================================================================== RCS file: /data/cvs/libxen/src/console.c,v retrieving revision 1.8 diff -u -r1.8 console.c --- src/console.c 17 Nov 2008 11:03:25 -0000 1.8 +++ src/console.c 19 May 2009 15:25:45 -0000 @@ -37,6 +37,7 @@ #include "console.h" #include "internal.h" +#include "logging.h" #include "util.h" /* ie Ctrl-] as per telnet */ @@ -72,8 +73,8 @@ /* We do not want this to become the controlling TTY */ if ((ttyfd = open(tty, O_NOCTTY | O_RDWR)) < 0) { - fprintf(stderr, _("unable to open tty %s: %s\n"), - tty, strerror(errno)); + VIR_ERROR(_("unable to open tty %s: %s\n"), + tty, strerror(errno)); return -1; } @@ -83,8 +84,8 @@ also ensure Ctrl-C, etc is blocked, and misc other bits */ if (tcgetattr(STDIN_FILENO, &ttyattr) < 0) { - fprintf(stderr, _("unable to get tty attributes: %s\n"), - strerror(errno)); + VIR_ERROR(_("unable to get tty attributes: %s\n"), + strerror(errno)); goto closetty; } @@ -92,8 +93,8 @@ cfmakeraw(&rawattr); if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &rawattr) < 0) { - fprintf(stderr, _("unable to set tty attributes: %s\n"), - strerror(errno)); + VIR_ERROR(_("unable to set tty attributes: %s\n"), + strerror(errno)); goto closetty; } @@ -127,8 +128,7 @@ if (errno == EINTR || errno == EAGAIN) continue; - fprintf(stderr, _("failure waiting for I/O: %s\n"), - strerror(errno)); + VIR_ERROR(_("failure waiting for I/O: %s\n"), strerror(errno)); goto cleanup; } @@ -142,8 +142,8 @@ int got, sent = 0, destfd; if ((got = read(fds[i].fd, buf, sizeof(buf))) < 0) { - fprintf(stderr, _("failure reading input: %s\n"), - strerror(errno)); + VIR_ERROR(_("failure reading input: %s\n"), + strerror(errno)); goto cleanup; } @@ -164,8 +164,8 @@ int done; if ((done = safewrite(destfd, buf + sent, got - sent)) <= 0) { - fprintf(stderr, _("failure writing output: %s\n"), - strerror(errno)); + VIR_ERROR(_("failure writing output: %s\n"), + strerror(errno)); goto cleanup; } sent += done; Index: src/network_driver.c =================================================================== RCS file: /data/cvs/libxen/src/network_driver.c,v retrieving revision 1.25 diff -u -r1.25 network_driver.c --- src/network_driver.c 19 May 2009 11:06:25 -0000 1.25 +++ src/network_driver.c 19 May 2009 15:25:45 -0000 @@ -56,6 +56,7 @@ #include "uuid.h" #include "iptables.h" #include "bridge.h" +#include "logging.h" #define NETWORK_PID_DIR LOCAL_STATE_DIR "/run/libvirt/network" #define NETWORK_STATE_DIR LOCAL_STATE_DIR "/lib/libvirt/network" @@ -87,10 +88,6 @@ static int networkShutdown(void); -/* networkDebug statements should be changed to use this macro instead. */ - -#define networkLog(level, msg...) fprintf(stderr, msg) - static int networkStartNetworkDaemon(virConnectPtr conn, struct network_driver *driver, virNetworkObjPtr network); @@ -174,7 +171,8 @@ !virNetworkIsActive(driver->networks.objs[i]) && networkStartNetworkDaemon(NULL, driver, driver->networks.objs[i]) < 0) { virErrorPtr err = virGetLastError(); - networkLog(NETWORK_ERR, _("Failed to autostart network '%s': %s\n"), + networkReportError(NULL, NULL, NULL, VIR_WAR_NO_NETWORK, + _("Failed to autostart network '%s': %s\n"), driver->networks.objs[i]->def->name, err ? err->message : NULL); } @@ -247,8 +245,7 @@ } if (!(driverState->iptables = iptablesContextNew())) { - virReportOOMError(NULL); - goto error; + goto out_of_memory; } @@ -266,8 +263,7 @@ return 0; out_of_memory: - networkLog (NETWORK_ERR, - "%s", _("networkStartup: out of memory\n")); + virReportOOMError(NULL); error: if (driverState) @@ -296,8 +292,7 @@ driverState->networkAutostartDir); if (driverState->iptables) { - networkLog(NETWORK_INFO, - "%s", _("Reloading iptables rules\n")); + VIR_INFO0(_("Reloading iptables rules\n")); iptablesReloadRules(driverState->iptables); } @@ -879,14 +874,14 @@ err_delbr1: if ((err = brSetInterfaceUp(driver->brctl, network->def->bridge, 0))) { char ebuf[1024]; - networkLog(NETWORK_WARN, _("Failed to bring down bridge '%s' : %s\n"), + VIR_WARN(_("Failed to bring down bridge '%s' : %s\n"), network->def->bridge, virStrerror(err, ebuf, sizeof ebuf)); } err_delbr: if ((err = brDeleteBridge(driver->brctl, network->def->bridge))) { char ebuf[1024]; - networkLog(NETWORK_WARN, _("Failed to delete bridge '%s' : %s\n"), + VIR_WARN(_("Failed to delete bridge '%s' : %s\n"), network->def->bridge, virStrerror(err, ebuf, sizeof ebuf)); } @@ -900,7 +895,7 @@ int err; char *stateFile; - networkLog(NETWORK_INFO, _("Shutting down network '%s'\n"), network->def->name); + VIR_INFO(_("Shutting down network '%s'\n"), network->def->name); if (!virNetworkIsActive(network)) return 0; @@ -919,12 +914,12 @@ char ebuf[1024]; if ((err = brSetInterfaceUp(driver->brctl, network->def->bridge, 0))) { - networkLog(NETWORK_WARN, _("Failed to bring down bridge '%s' : %s\n"), + VIR_WARN(_("Failed to bring down bridge '%s' : %s\n"), network->def->bridge, virStrerror(err, ebuf, sizeof ebuf)); } if ((err = brDeleteBridge(driver->brctl, network->def->bridge))) { - networkLog(NETWORK_WARN, _("Failed to delete bridge '%s' : %s\n"), + VIR_WARN(_("Failed to delete bridge '%s' : %s\n"), network->def->bridge, virStrerror(err, ebuf, sizeof ebuf)); } Index: src/node_device_conf.c =================================================================== RCS file: /data/cvs/libxen/src/node_device_conf.c,v retrieving revision 1.9 diff -u -r1.9 node_device_conf.c --- src/node_device_conf.c 24 Feb 2009 14:55:45 -0000 1.9 +++ src/node_device_conf.c 19 May 2009 15:25:45 -0000 @@ -53,9 +53,6 @@ "80203", "80211") - -#define virNodeDeviceLog(msg...) fprintf(stderr, msg) - virNodeDeviceObjPtr virNodeDeviceFindByName(const virNodeDeviceObjListPtr devs, const char *name) { Index: src/node_device_hal.c =================================================================== RCS file: /data/cvs/libxen/src/node_device_hal.c,v retrieving revision 1.10 diff -u -r1.10 node_device_hal.c --- src/node_device_hal.c 16 Mar 2009 10:56:01 -0000 1.10 +++ src/node_device_hal.c 19 May 2009 15:25:45 -0000 @@ -692,23 +692,22 @@ dbus_error_init(&err); hal_ctx = libhal_ctx_new(); if (hal_ctx == NULL) { - fprintf(stderr, "%s: libhal_ctx_new returned NULL\n", __FUNCTION__); + VIR_ERROR0("libhal_ctx_new returned NULL\n"); goto failure; } dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); if (dbus_conn == NULL) { - fprintf(stderr, "%s: dbus_bus_get failed\n", __FUNCTION__); + VIR_ERROR0("dbus_bus_get failed\n"); goto failure; } dbus_connection_set_exit_on_disconnect(dbus_conn, FALSE); if (!libhal_ctx_set_dbus_connection(hal_ctx, dbus_conn)) { - fprintf(stderr, "%s: libhal_ctx_set_dbus_connection failed\n", - __FUNCTION__); + VIR_ERROR0("libhal_ctx_set_dbus_connection failed\n"); goto failure; } if (!libhal_ctx_init(hal_ctx, &err)) { - fprintf(stderr, "%s: libhal_ctx_init failed\n", __FUNCTION__); + VIR_ERROR0("libhal_ctx_init failed\n"); goto failure; } @@ -718,8 +717,7 @@ remove_dbus_watch, toggle_dbus_watch, NULL, NULL)) { - fprintf(stderr, "%s: dbus_connection_set_watch_functions failed\n", - __FUNCTION__); + VIR_ERROR0("dbus_connection_set_watch_functions failed\n"); goto failure; } @@ -729,7 +727,7 @@ !libhal_ctx_set_device_new_capability(hal_ctx, device_cap_added) || !libhal_ctx_set_device_lost_capability(hal_ctx, device_cap_lost) || !libhal_ctx_set_device_property_modified(hal_ctx, device_prop_modified)) { - fprintf(stderr, "%s: setting up HAL callbacks failed\n", __FUNCTION__); + VIR_ERROR0("setting up HAL callbacks failed\n"); goto failure; } @@ -739,7 +737,7 @@ nodeDeviceUnlock(driverState); udi = libhal_get_all_devices(hal_ctx, &num_devs, &err); if (udi == NULL) { - fprintf(stderr, "%s: libhal_get_all_devices failed\n", __FUNCTION__); + VIR_ERROR0("libhal_get_all_devices failed\n"); goto failure; } for (i = 0; i < num_devs; i++) { @@ -752,7 +750,7 @@ failure: if (dbus_error_is_set(&err)) { - fprintf(stderr, "\t%s: %s\n", err.name, err.message); + VIR_ERROR("%s: %s\n", err.name, err.message); dbus_error_free(&err); } virNodeDeviceObjListFree(&driverState->devs); Index: src/storage_conf.c =================================================================== RCS file: /data/cvs/libxen/src/storage_conf.c,v retrieving revision 1.46 diff -u -r1.46 storage_conf.c --- src/storage_conf.c 1 Apr 2009 16:03:22 -0000 1.46 +++ src/storage_conf.c 19 May 2009 15:25:45 -0000 @@ -50,7 +50,9 @@ # define ULLONG_MAX ULONG_LONG_MAX #endif -#define virStorageLog(msg...) fprintf(stderr, msg) +#define virStorageError(conn, code, fmt...) \ + virReportErrorHelper(conn, VIR_FROM_STORAGE, code, __FILE__,\ + __FUNCTION__, __LINE__, fmt) VIR_ENUM_IMPL(virStoragePool, VIR_STORAGE_POOL_LAST, @@ -1333,33 +1335,38 @@ if (!(def = virStoragePoolDefParse(NULL, xml, file))) { virErrorPtr err = virGetLastError(); - virStorageLog("Error parsing storage pool config '%s' : %s", - path, err ? err->message : NULL); + virStorageError(conn, VIR_ERR_PARSE_FAILED, + "Error parsing storage pool config '%s' : %s", + path, err ? err->message : NULL); return NULL; } if (!virFileMatchesNameSuffix(file, def->name, ".xml")) { - virStorageLog("Storage pool config filename '%s' does not match pool name '%s'", + virStorageError(conn, VIR_ERR_INVALID_STORAGE_POOL, + "Storage pool config filename '%s' does not match pool name '%s'", path, def->name); virStoragePoolDefFree(def); return NULL; } if (!(pool = virStoragePoolObjAssignDef(conn, pools, def))) { - virStorageLog("Failed to load storage pool config '%s': out of memory", path); + virStorageError(conn, VIR_ERR_INTERNAL_ERROR, + "Failed to load storage pool config '%s': out of memory", path); virStoragePoolDefFree(def); return NULL; } pool->configFile = strdup(path); if (pool->configFile == NULL) { - virStorageLog("Failed to load storage pool config '%s': out of memory", path); + virStorageError(conn, VIR_ERR_INTERNAL_ERROR, + "Failed to load storage pool config '%s': out of memory", path); virStoragePoolDefFree(def); return NULL; } pool->autostartLink = strdup(autostartLink); if (pool->autostartLink == NULL) { - virStorageLog("Failed to load storage pool config '%s': out of memory", path); + virStorageError(conn, VIR_ERR_INTERNAL_ERROR, + "Failed to load storage pool config '%s': out of memory", path); virStoragePoolDefFree(def); return NULL; } @@ -1383,7 +1390,7 @@ char ebuf[1024]; if (errno == ENOENT) return 0; - virStorageLog("Failed to open dir '%s': %s", + virReportSystemError(conn, errno, _("Failed to open dir '%s': %s"), configDir, virStrerror(errno, ebuf, sizeof ebuf)); return -1; } @@ -1402,15 +1409,17 @@ if (virFileBuildPath(configDir, entry->d_name, NULL, path, PATH_MAX) < 0) { - virStorageLog("Config filename '%s/%s' is too long", - configDir, entry->d_name); + virStorageError(conn, VIR_ERR_INTERNAL_ERROR, + "Config filename '%s/%s' is too long", + configDir, entry->d_name); continue; } if (virFileBuildPath(autostartDir, entry->d_name, NULL, autostartLink, PATH_MAX) < 0) { - virStorageLog("Autostart link path '%s/%s' is too long", - autostartDir, entry->d_name); + virStorageError(conn, VIR_ERR_INTERNAL_ERROR, + "Autostart link path '%s/%s' is too long", + autostartDir, entry->d_name); continue; } Index: src/util.c =================================================================== RCS file: /data/cvs/libxen/src/util.c,v retrieving revision 1.105 diff -u -r1.105 util.c --- src/util.c 11 May 2009 13:50:38 -0000 1.105 +++ src/util.c 19 May 2009 15:25:45 -0000 @@ -73,8 +73,6 @@ # define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif -#define virLog(msg...) fprintf(stderr, msg) - #define VIR_FROM_THIS VIR_FROM_NONE #define ReportError(conn, code, fmt...) \ @@ -938,19 +936,16 @@ int virFileReadAll(const char *path, int maxlen, char **buf) { - char ebuf[1024]; FILE *fh = fopen(path, "r"); if (fh == NULL) { - virLog("Failed to open file '%s': %s\n", - path, virStrerror(errno, ebuf, sizeof ebuf)); + virReportSystemError(NULL, errno, _("Failed to open file '%s'"), path); return -1; } int len = virFileReadLimFP (fh, maxlen, buf); fclose(fh); if (len < 0) { - virLog("Failed to read '%s': %s\n", path, - virStrerror(errno, ebuf, sizeof ebuf)); + virReportSystemError(NULL, errno, _("Failed to read file '%s'"), path); return -1; }