]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cleanup of some direct stderr logging
authorDaniel Veillard <veillard@redhat.com>
Wed, 20 May 2009 13:37:30 +0000 (13:37 +0000)
committerDaniel Veillard <veillard@redhat.com>
Wed, 20 May 2009 13:37:30 +0000 (13:37 +0000)
* qemud/qemud.c src/console.c src/network_driver.c
  src/node_device_conf.c src/node_device_hal.c src/storage_conf.c
  src/util.c: cleanup of some direct stderr logging
daniel

ChangeLog
qemud/qemud.c
src/console.c
src/network_driver.c
src/node_device_conf.c
src/node_device_hal.c
src/storage_conf.c
src/util.c

index c6db03fae3c0d19059b821a13299b501c32c5756..4bce5506e3858532b3fafa3026d795ce0a1d3cb3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed May 20 15:35:35 CEST 2009 Daniel Veillard <veillard@redhat.com>
+
+       * qemud/qemud.c src/console.c src/network_driver.c
+         src/node_device_conf.c src/node_device_hal.c src/storage_conf.c
+         src/util.c: cleanup of some direct stderr logging
+
 Wed May 20 15:33:27 CEST 2009 Daniel Veillard <veillard@redhat.com>
 
        * src/pci.c: small portability patch
index 1847407911ce6cbccee08d29965f60c4100b91f7..0ac9462a7fa7caf902f19411d3d1f1a1baa10d15 100644 (file)
@@ -2673,13 +2673,13 @@ qemudSetupPrivs (void)
 
     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 4954f04d262fe13d680f46107741c31d9526d5d4..badb62c0d304c3f4e353c4cab6e372e3df674888 100644 (file)
@@ -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 @@ int vshRunConsole(const char *tty) {
 
     /* 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 @@ int vshRunConsole(const char *tty) {
        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 @@ int vshRunConsole(const char *tty) {
     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 @@ int vshRunConsole(const char *tty) {
             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 vshRunConsole(const char *tty) {
                 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 vshRunConsole(const char *tty) {
                     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 112346ffef9b66c3bbe230a29081ee0436127fcb..29652d16d2e96fe88bfc07626846240eb7ebfcb2 100644 (file)
@@ -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 void networkDriverUnlock(struct network_driver *driver)
 
 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);
@@ -173,10 +170,7 @@ networkAutostartConfigs(struct network_driver *driver) {
         if (driver->networks.objs[i]->autostart &&
             !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"),
-                       driver->networks.objs[i]->def->name,
-                       err ? err->message : NULL);
+            /* failed to start but already logged */
         }
         virNetworkObjUnlock(driver->networks.objs[i]);
     }
@@ -247,8 +241,7 @@ networkStartup(void) {
     }
 
     if (!(driverState->iptables = iptablesContextNew())) {
-        virReportOOMError(NULL);
-        goto error;
+        goto out_of_memory;
     }
 
 
@@ -266,8 +259,7 @@ networkStartup(void) {
     return 0;
 
 out_of_memory:
-    networkLog (NETWORK_ERR,
-              "%s", _("networkStartup: out of memory\n"));
+    virReportOOMError(NULL);
 
 error:
     if (driverState)
@@ -296,8 +288,7 @@ networkReload(void) {
                              driverState->networkAutostartDir);
 
      if (driverState->iptables) {
-        networkLog(NETWORK_INFO,
-                 "%s", _("Reloading iptables rules\n"));
+        VIR_INFO0(_("Reloading iptables rules\n"));
         iptablesReloadRules(driverState->iptables);
     }
 
@@ -879,14 +870,14 @@ static int networkStartNetworkDaemon(virConnectPtr conn,
  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 +891,7 @@ static int networkShutdownNetworkDaemon(virConnectPtr conn,
     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 +910,12 @@ static int networkShutdownNetworkDaemon(virConnectPtr conn,
 
     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 6e04112d97e59cf10199b3da9d2d98278f59d6ba..236042743fed31abbf3f88e4d253a89c65e147e4 100644 (file)
@@ -53,9 +53,6 @@ VIR_ENUM_IMPL(virNodeDevNetCap, VIR_NODE_DEV_CAP_NET_LAST,
               "80203",
               "80211")
 
-
-#define virNodeDeviceLog(msg...) fprintf(stderr, msg)
-
 virNodeDeviceObjPtr virNodeDeviceFindByName(const virNodeDeviceObjListPtr devs,
                                             const char *name)
 {
index b0955e812fb7948fb7823aae4c57f284b7e74819..2f7ca8db0062a71b1c24f3134dcef6f8cc1d4649 100644 (file)
@@ -689,23 +689,22 @@ static int halDeviceMonitorStartup(void)
     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;
     }
 
@@ -715,8 +714,7 @@ static int halDeviceMonitorStartup(void)
                                              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;
     }
 
@@ -726,8 +724,8 @@ static int halDeviceMonitorStartup(void)
         !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) ||
-        !libhal_device_property_watch_all(hal_ctx, &err))    {
-        fprintf(stderr, "%s: setting up HAL callbacks failed\n", __FUNCTION__);
+        !libhal_device_property_watch_all(hal_ctx, &err)) {
+        VIR_ERROR0("setting up HAL callbacks failed\n");
         goto failure;
     }
 
@@ -737,7 +735,7 @@ static int halDeviceMonitorStartup(void)
     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++) {
@@ -750,7 +748,7 @@ static int halDeviceMonitorStartup(void)
 
  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 9e25ccbe79056f0b180e74ca1d44ca7fa529fe45..5f724dc798b29047de753aa95ddf4a990f6d40a1 100644 (file)
@@ -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,
@@ -1332,34 +1334,31 @@ virStoragePoolObjLoad(virConnectPtr conn,
     virStoragePoolObjPtr pool;
 
     if (!(def = virStoragePoolDefParse(NULL, xml, file))) {
-        virErrorPtr err = virGetLastError();
-        virStorageLog("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);
         virStoragePoolDefFree(def);
         return NULL;
     }
 
     pool->configFile = strdup(path);
     if (pool->configFile == NULL) {
-        virStorageLog("Failed to load storage pool config '%s': out of memory", path);
+        virReportOOMError(conn);
         virStoragePoolDefFree(def);
         return NULL;
     }
     pool->autostartLink = strdup(autostartLink);
     if (pool->autostartLink == NULL) {
-        virStorageLog("Failed to load storage pool config '%s': out of memory", path);
+        virReportOOMError(conn);
         virStoragePoolDefFree(def);
         return NULL;
     }
@@ -1380,11 +1379,10 @@ virStoragePoolLoadAllConfigs(virConnectPtr conn,
     struct dirent *entry;
 
     if (!(dir = opendir(configDir))) {
-        char ebuf[1024];
         if (errno == ENOENT)
             return 0;
-        virStorageLog("Failed to open dir '%s': %s",
-                      configDir, virStrerror(errno, ebuf, sizeof ebuf));
+        virReportSystemError(conn, errno, _("Failed to open dir '%s'"),
+                             configDir);
         return -1;
     }
 
@@ -1402,15 +1400,17 @@ virStoragePoolLoadAllConfigs(virConnectPtr conn,
 
         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 3cf28511e710c9f807d2eb315bf1ee748d23093c..b7fedc58b8860a7d52a5d52bd3de26367d2b0acf 100644 (file)
@@ -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 virFileReadLimFD(int fd_arg, int maxlen, char **buf)
 
 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;
     }