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

[Libvir] PATCH: make debug builds quiet by default



During development I like to have the --enable-debug flag enabled all the
time because its very handy at times. I don't want it spewing to stderr
all the time though, just because I turned on the compile option. So this
patch adds an env variable 'LIBVIRT_DEBUG' which controls whether it is
chatty or not. So with this patch you can use --enable-debug all the time,
and just run

   LIBVIRT_DEBUG=1 ./src/virsh ....

to turn it on for a particular test, or likewise for the daemon

  LIBVIRT_DEBUG=1 ./qemud/libvirtd

Dan.

  libvirt.c |   64 +++++++++++++++++++++++++++++++++++---------------------------
   1 file changed, 37 insertions(+), 27 deletions(-)


diff -r c747561694fc src/libvirt.c
--- a/src/libvirt.c	Tue Jan 08 23:52:20 2008 -0500
+++ b/src/libvirt.c	Tue Jan 08 23:53:57 2008 -0500
@@ -59,10 +59,11 @@ static int initialized = 0;
  * are printed to stderr for debugging.
  */
 #ifdef ENABLE_DEBUG
+static int debugFlag = 0;
 #define DEBUG(fs,...)                                                   \
-    fprintf (stderr, "libvirt: %s (" fs ")\n", __func__, __VA_ARGS__)
+    do { if (debugFlag) fprintf (stderr, "libvirt: %s (" fs ")\n", __func__, __VA_ARGS__); } while (0)
 #define DEBUG0                                                          \
-    fprintf (stderr, "libvirt: %s ()\n", __func__)
+    do { if (debugFlag) fprintf (stderr, "libvirt: %s ()\n", __func__); } while (0)
 #else
 #define DEBUG0
 #define DEBUG(fs,...)
@@ -179,10 +180,20 @@ int
 int
 virInitialize(void)
 {
-    DEBUG0;
+#ifdef ENABLE_DEBUG
+    char *debugEnv;
+#endif
     if (initialized)
         return(0);
     initialized = 1;
+
+#ifdef ENABLE_DEBUG
+    debugEnv = getenv("LIBVIRT_DEBUG");
+    if (debugEnv && *debugEnv)
+        debugFlag = 1;
+#endif
+
+    DEBUG0;
 
 #if HAVE_WINSOCK2_H
     if (winsock_init () == -1) return -1;
@@ -543,18 +554,17 @@ do_open (const char *name,
     }
 
 #ifdef ENABLE_DEBUG
-    fprintf (stderr,
-             "libvirt: do_open: name \"%s\" to URI components:\n"
-             "  scheme %s\n"
-             "  opaque %s\n"
-             "  authority %s\n"
-             "  server %s\n"
-             "  user %s\n"
-             "  port %d\n"
-             "  path %s\n",
-             name,
-             uri->scheme, uri->opaque, uri->authority, uri->server,
-             uri->user, uri->port, uri->path);
+    DEBUG("libvirt: do_open: name \"%s\" to URI components:\n"
+          "  scheme %s\n"
+          "  opaque %s\n"
+          "  authority %s\n"
+          "  server %s\n"
+          "  user %s\n"
+          "  port %d\n"
+          "  path %s\n",
+          name,
+          uri->scheme, uri->opaque, uri->authority, uri->server,
+          uri->user, uri->port, uri->path);
 #endif
 
     ret->name = strdup (name);
@@ -565,16 +575,16 @@ do_open (const char *name,
 
     for (i = 0; i < virDriverTabCount; i++) {
 #ifdef ENABLE_DEBUG
-        fprintf (stderr, "libvirt: do_open: trying driver %d (%s) ...\n",
-                 i, virDriverTab[i]->name);
+        DEBUG("libvirt: do_open: trying driver %d (%s) ...\n",
+              i, virDriverTab[i]->name);
 #endif
         res = virDriverTab[i]->open (ret, uri, auth, flags);
 #ifdef ENABLE_DEBUG
-        fprintf (stderr, "libvirt: do_open: driver %d %s returned %s\n",
-                 i, virDriverTab[i]->name,
-                 res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
-                 (res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
-                  (res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
+        DEBUG("libvirt: do_open: driver %d %s returned %s\n",
+              i, virDriverTab[i]->name,
+              res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
+              (res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
+               (res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
 #endif
         if (res == VIR_DRV_OPEN_ERROR) goto failed;
         else if (res == VIR_DRV_OPEN_SUCCESS) {
@@ -592,11 +602,11 @@ do_open (const char *name,
     for (i = 0; i < virNetworkDriverTabCount; i++) {
         res = virNetworkDriverTab[i]->open (ret, uri, auth, flags);
 #ifdef ENABLE_DEBUG
-        fprintf (stderr, "libvirt: do_open: network driver %d %s returned %s\n",
-                 i, virNetworkDriverTab[i]->name,
-                 res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
-                 (res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
-                  (res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
+        DEBUG("libvirt: do_open: network driver %d %s returned %s\n",
+              i, virNetworkDriverTab[i]->name,
+              res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
+              (res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
+               (res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
 #endif
         if (res == VIR_DRV_OPEN_ERROR) {
             if (STREQ(virNetworkDriverTab[i]->name, "remote")) {


Regards,
Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 


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