[libvirt] PATCH: Remove qemudLog() macro, use logging.h instead

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The qemudLog() macro just spews its messages to stderr. This patch changes
it to use the proper logging.h APIs, so the output channel is configurable
in the expected way.

Daniel

diff --git a/src/iptables.c b/src/iptables.c
--- a/src/iptables.c
+++ b/src/iptables.c
@@ -45,8 +45,7 @@
 #include "util.h"
 #include "memory.h"
 #include "virterror_internal.h"
-
-#define qemudLog(level, msg...) fprintf(stderr, msg)
+#include "logging.h"
 
 enum {
     ADD = 0,
@@ -101,7 +100,7 @@ notifyRulesUpdated(const char *table,
 
     char ebuf[1024];
     if (virRun(NULL, argv, NULL) < 0)
-        qemudLog(QEMUD_WARN, _("Failed to run '%s %s': %s"),
+        VIR_WARN(_("Failed to run '%s %s': %s"),
                  LOKKIT_PATH, arg, virStrerror(errno, ebuf, sizeof ebuf));
 }
 
@@ -149,8 +148,8 @@ notifyRulesRemoved(const char *table,
     len = virFileReadAll(SYSCONF_DIR "/sysconfig/system-config-firewall",
                          MAX_FILE_LEN, &content);
     if (len < 0) {
-        qemudLog(QEMUD_WARN, "%s", _("Failed to read " SYSCONF_DIR
-                                     "/sysconfig/system-config-firewall"));
+        VIR_WARN("%s", _("Failed to read " SYSCONF_DIR
+                         "/sysconfig/system-config-firewall"));
         return;
     }
 
@@ -178,8 +177,8 @@ notifyRulesRemoved(const char *table,
 
  write_error:;
     char ebuf[1024];
-    qemudLog(QEMUD_WARN, _("Failed to write to " SYSCONF_DIR
-                           "/sysconfig/system-config-firewall : %s"),
+    VIR_WARN(_("Failed to write to " SYSCONF_DIR
+               "/sysconfig/system-config-firewall : %s"),
              virStrerror(errno, ebuf, sizeof ebuf));
     if (f)
         fclose(f);
@@ -244,13 +243,13 @@ iptRulesSave(iptRules *rules)
 
     char ebuf[1024];
     if ((err = virFileMakePath(rules->dir))) {
-        qemudLog(QEMUD_WARN, _("Failed to create directory %s : %s"),
+        VIR_WARN(_("Failed to create directory %s : %s"),
                  rules->dir, virStrerror(err, ebuf, sizeof ebuf));
         return;
     }
 
     if ((err = writeRules(rules->path, rules->rules, rules->nrules))) {
-        qemudLog(QEMUD_WARN, _("Failed to saves iptables rules to %s : %s"),
+        VIR_WARN(_("Failed to saves iptables rules to %s : %s"),
                  rules->path, virStrerror(err, ebuf, sizeof ebuf));
         return;
     }
@@ -551,8 +550,7 @@ iptRulesReload(iptRules *rules)
         rule->argv[rule->command_idx] = (char *) "--delete";
 
         if (virRun(NULL, rule->argv, NULL) < 0)
-            qemudLog(QEMUD_WARN,
-                     _("Failed to remove iptables rule '%s'"
+            VIR_WARN(_("Failed to remove iptables rule '%s'"
                        " from chain '%s' in table '%s': %s"),
                      rule->rule, rules->chain, rules->table,
                      virStrerror(errno, ebuf, sizeof ebuf));
@@ -562,8 +560,8 @@ iptRulesReload(iptRules *rules)
 
     for (i = 0; i < rules->nrules; i++)
         if (virRun(NULL, rules->rules[i].argv, NULL) < 0)
-            qemudLog(QEMUD_WARN, _("Failed to add iptables rule '%s'"
-                                   " to chain '%s' in table '%s': %s"),
+            VIR_WARN(_("Failed to add iptables rule '%s'"
+                       " to chain '%s' in table '%s': %s"),
                      rules->rules[i].rule, rules->chain, rules->table,
                      virStrerror(errno, ebuf, sizeof ebuf));
 }
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -47,6 +47,7 @@
 #include "datatypes.h"
 #include "xml.h"
 #include "nodeinfo.h"
+#include "logging.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -77,8 +78,6 @@ VIR_ENUM_IMPL(qemuDiskCacheV2, VIR_DOMAI
               "writeback");
 
 
-#define qemudLog(level, msg...) fprintf(stderr, msg)
-
 int qemudLoadDriverConfig(struct qemud_driver *driver,
                           const char *filename) {
     virConfPtr conf;
@@ -469,18 +468,16 @@ rewait:
         if (errno == EINTR)
             goto rewait;
 
-        qemudLog(QEMUD_ERR,
-                 _("Unexpected exit status from qemu %d pid %lu"),
-                 WEXITSTATUS(status), (unsigned long)child);
+        VIR_ERROR(_("Unexpected exit status from qemu %d pid %lu"),
+                  WEXITSTATUS(status), (unsigned long)child);
         ret = -1;
     }
     /* Check & log unexpected exit status, but don't fail,
      * as there's really no need to throw an error if we did
      * actually read a valid version number above */
     if (WEXITSTATUS(status) != 0) {
-        qemudLog(QEMUD_WARN,
-                 _("Unexpected exit status '%d', qemu probably failed"),
-                 WEXITSTATUS(status));
+        VIR_ERROR(_("Unexpected exit status '%d', qemu probably failed"),
+                  WEXITSTATUS(status));
     }
 
     return ret;
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -82,8 +82,6 @@
 
 static int qemudShutdown(void);
 
-#define qemudLog(level, msg...) fprintf(stderr, msg)
-
 static void qemuDriverLock(struct qemud_driver *driver)
 {
     virMutexLock(&driver->lock);
@@ -220,9 +218,9 @@ qemudAutostartConfigs(struct qemud_drive
             int ret = qemudStartVMDaemon(conn, driver, vm, NULL, -1);
             if (ret < 0) {
                 virErrorPtr err = virGetLastError();
-                qemudLog(QEMUD_ERROR, _("Failed to autostart VM '%s': %s\n"),
-                         vm->def->name,
-                         err ? err->message : NULL);
+                VIR_ERROR(_("Failed to autostart VM '%s': %s\n"),
+                          vm->def->name,
+                          err ? err->message : NULL);
             } else {
                 virDomainEventPtr event =
                     virDomainEventNewFromObj(vm,
@@ -306,8 +304,8 @@ qemudReconnectVMs(struct qemud_driver *d
         if ((config = virDomainConfigFile(NULL,
                                           driver->stateDir,
                                           vm->def->name)) == NULL) {
-            qemudLog(QEMUD_ERROR, _("Failed to read domain status for %s\n"),
-                     vm->def->name);
+            VIR_ERROR(_("Failed to read domain status for %s\n"),
+                      vm->def->name);
             goto next_error;
         }
 
@@ -316,14 +314,14 @@ qemudReconnectVMs(struct qemud_driver *d
             vm->newDef = vm->def;
             vm->def = status->def;
         } else {
-            qemudLog(QEMUD_ERROR, _("Failed to parse domain status for %s\n"),
-                     vm->def->name);
+            VIR_ERROR(_("Failed to parse domain status for %s\n"),
+                      vm->def->name);
             goto next_error;
         }
 
         if ((rc = qemudOpenMonitor(NULL, driver, vm, status->monitorpath, 1)) != 0) {
-            qemudLog(QEMUD_ERROR, _("Failed to reconnect monitor for %s: %d\n"),
-                     vm->def->name, rc);
+            VIR_ERROR(_("Failed to reconnect monitor for %s: %d\n"),
+                      vm->def->name, rc);
             goto next_error;
         }
 
@@ -369,7 +367,7 @@ qemudStartup(void) {
         return -1;
 
     if (virMutexInit(&qemu_driver->lock) < 0) {
-        qemudLog(QEMUD_ERROR, "%s", _("cannot initialize mutex"));
+        VIR_ERROR("%s", _("cannot initialize mutex"));
         VIR_FREE(qemu_driver);
         return -1;
     }
@@ -422,8 +420,8 @@ qemudStartup(void) {
 
     if (virFileMakePath(qemu_driver->stateDir) < 0) {
         char ebuf[1024];
-        qemudLog(QEMUD_ERROR, _("Failed to create state dir '%s': %s\n"),
-                 qemu_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf));
+        VIR_ERROR(_("Failed to create state dir '%s': %s\n"),
+                  qemu_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf));
         goto error;
     }
 
@@ -901,7 +899,7 @@ static int qemudWaitForMonitor(virConnec
                              "console", 3);
     if (close(logfd) < 0) {
         char ebuf[1024];
-        qemudLog(QEMUD_WARN, _("Unable to close logfile: %s\n"),
+        VIR_WARN(_("Unable to close logfile: %s\n"),
                  virStrerror(errno, ebuf, sizeof ebuf));
     }
 
@@ -1299,29 +1297,29 @@ static int qemudStartVMDaemon(virConnect
     tmp = progenv;
     while (*tmp) {
         if (safewrite(vm->logfile, *tmp, strlen(*tmp)) < 0)
-            qemudLog(QEMUD_WARN, _("Unable to write envv to logfile: %s\n"),
+            VIR_WARN(_("Unable to write envv to logfile: %s\n"),
                      virStrerror(errno, ebuf, sizeof ebuf));
         if (safewrite(vm->logfile, " ", 1) < 0)
-            qemudLog(QEMUD_WARN, _("Unable to write envv to logfile: %s\n"),
+            VIR_WARN(_("Unable to write envv to logfile: %s\n"),
                      virStrerror(errno, ebuf, sizeof ebuf));
         tmp++;
     }
     tmp = argv;
     while (*tmp) {
         if (safewrite(vm->logfile, *tmp, strlen(*tmp)) < 0)
-            qemudLog(QEMUD_WARN, _("Unable to write argv to logfile: %s\n"),
+            VIR_WARN(_("Unable to write argv to logfile: %s\n"),
                      virStrerror(errno, ebuf, sizeof ebuf));
         if (safewrite(vm->logfile, " ", 1) < 0)
-            qemudLog(QEMUD_WARN, _("Unable to write argv to logfile: %s\n"),
+            VIR_WARN(_("Unable to write argv to logfile: %s\n"),
                      virStrerror(errno, ebuf, sizeof ebuf));
         tmp++;
     }
     if (safewrite(vm->logfile, "\n", 1) < 0)
-        qemudLog(QEMUD_WARN, _("Unable to write argv to logfile: %s\n"),
+        VIR_WARN(_("Unable to write argv to logfile: %s\n"),
                  virStrerror(errno, ebuf, sizeof ebuf));
 
     if ((pos = lseek(vm->logfile, 0, SEEK_END)) < 0)
-        qemudLog(QEMUD_WARN, _("Unable to seek to end of logfile: %s\n"),
+        VIR_WARN(_("Unable to seek to end of logfile: %s\n"),
                  virStrerror(errno, ebuf, sizeof ebuf));
 
     for (i = 0 ; i < ntapfds ; i++)
@@ -1399,7 +1397,7 @@ static void qemudShutdownVMDaemon(virCon
     if (!virDomainIsActive(vm))
         return;
 
-    qemudLog(QEMUD_DEBUG, _("Shutting down VM '%s'\n"), vm->def->name);
+    VIR_DEBUG(_("Shutting down VM '%s'\n"), vm->def->name);
 
     if (virKillProcess(vm->pid, 0) == 0 &&
         virKillProcess(vm->pid, SIGTERM) < 0)
@@ -1414,7 +1412,7 @@ static void qemudShutdownVMDaemon(virCon
 
     if (close(vm->logfile) < 0) {
         char ebuf[1024];
-        qemudLog(QEMUD_WARN, _("Unable to close logfile: %s\n"),
+        VIR_WARN(_("Unable to close logfile: %s\n"),
                  virStrerror(errno, ebuf, sizeof ebuf));
     }
     if (vm->monitor != -1)
@@ -1426,7 +1424,7 @@ static void qemudShutdownVMDaemon(virCon
     virKillProcess(vm->pid, SIGKILL);
 
     if (qemudRemoveDomainStatus(conn, driver, vm) < 0) {
-        qemudLog(QEMUD_WARN, _("Failed to remove domain status for %s"),
+        VIR_WARN(_("Failed to remove domain status for %s"),
                  vm->def->name);
     }
     vm->pid = -1;
@@ -1473,8 +1471,8 @@ qemudDispatchVMEvent(int watch, int fd, 
         if (events & (VIR_EVENT_HANDLE_HANGUP | VIR_EVENT_HANDLE_ERROR))
             quit = 1;
         else {
-            qemudLog(QEMUD_ERROR, _("unhandled fd event %d for %s"),
-                                    events, vm->def->name);
+            VIR_ERROR(_("unhandled fd event %d for %s"),
+                      events, vm->def->name);
             failed = 1;
         }
     }
@@ -1587,7 +1585,7 @@ qemudMonitorCommandExtra(const virDomain
     /* Log, but ignore failures to write logfile for VM */
     if (safewrite(vm->logfile, buf, strlen(buf)) < 0) {
         char ebuf[1024];
-        qemudLog(QEMUD_WARN, _("Unable to log VM console data: %s\n"),
+        VIR_WARN(_("Unable to log VM console data: %s\n"),
                  virStrerror(errno, ebuf, sizeof ebuf));
     }
 
@@ -1599,7 +1597,7 @@ qemudMonitorCommandExtra(const virDomain
         /* Log, but ignore failures to write logfile for VM */
         if (safewrite(vm->logfile, buf, strlen(buf)) < 0) {
             char ebuf[1024];
-            qemudLog(QEMUD_WARN, _("Unable to log VM console data: %s\n"),
+            VIR_WARN(_("Unable to log VM console data: %s\n"),
                      virStrerror(errno, ebuf, sizeof ebuf));
         }
         VIR_FREE(buf);
@@ -3380,7 +3378,7 @@ static int qemudDomainAttachPciDiskDevic
         s += strlen(PCI_ATTACH_OK_MSG);
 
         if (virStrToLong_i ((const char*)s, &dummy, 10, &dev->data.disk->slotnum) == -1)
-            qemudLog(QEMUD_WARN, "%s", _("Unable to parse slot number\n"));
+            VIR_WARN("%s", _("Unable to parse slot number\n"));
     } else {
         qemudReportError (conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
                           _("adding %s disk failed"), type);
@@ -4512,8 +4510,8 @@ cleanup:
              * overwrite the previous error, though, so we just throw something
              * to the logs and hope for the best
              */
-            qemudLog(QEMUD_ERROR, _("Failed to resume guest %s after failure\n"),
-                     vm->def->name);
+            VIR_ERROR(_("Failed to resume guest %s after failure\n"),
+                      vm->def->name);
         }
         else {
             DEBUG ("cont reply: %s", info);
diff --git a/src/uuid.c b/src/uuid.c
--- a/src/uuid.c
+++ b/src/uuid.c
@@ -37,8 +37,7 @@
 #include "internal.h"
 #include "util.h"
 #include "virterror_internal.h"
-
-#define qemudLog(level, msg...) fprintf(stderr, msg)
+#include "logging.h"
 
 #ifndef ENODATA
 #define ENODATA EIO
@@ -102,8 +101,7 @@ virUUIDGenerate(unsigned char *uuid)
 
     if ((err = virUUIDGenerateRandomBytes(uuid, VIR_UUID_BUFLEN))) {
         char ebuf[1024];
-        qemudLog(QEMUD_WARN,
-                 _("Falling back to pseudorandom UUID,"
+        VIR_WARN(_("Falling back to pseudorandom UUID,"
                    " failed to generate random bytes: %s"),
                  virStrerror(err, ebuf, sizeof ebuf));
     }


-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]