]> xenbits.xensource.com Git - libvirt.git/commitdiff
Enable debug by default, but only if LIBVIRT_DEBUG=1. Use generic macro for debug...
authorDaniel P. Berrange <berrange@redhat.com>
Sat, 19 Jan 2008 18:36:01 +0000 (18:36 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Sat, 19 Jan 2008 18:36:01 +0000 (18:36 +0000)
ChangeLog
configure.in
src/internal.h
src/libvirt.c
src/remote_internal.c
src/xen_unified.c
src/xend_internal.c

index 81ecbd35504913fc92ca9cee2189289325839ee7..a2e9b5f42a8d0c0e97a56ff6365c423c34d24af0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Jan 19 13:32:22 EST 2008 Daniel P. Berrange <berrange@redhat.com>
+
+       * src/configure.in: enable debug by default. print status of
+       compiler warning flags in configure summary
+       * src/internal.h: Provide a generic VIR_DEBUG macro for logging
+       * src/libvirt.c, src/remote_internal.c, src/xen_unified.c,
+       src/xend_internal.c: Use generic VIR_DEBUG macro for logging.
+       Enable debug when env var LIBVIRT_DEBUG=1
+
 Tue Jan 15 16:25:57 CET  Jim Meyering  <meyering@redhat.com>
 
        * docs/examples/examples.xml: Regenerate, now that *.c file names
index 0fefb437db1afc406e36f3b02a5fd7353659069e..06c6b641e4bcbe262362cec59487239c32288c94 100644 (file)
@@ -147,7 +147,7 @@ AC_SUBST(STATIC_BINARIES)
 dnl --enable-debug=(yes|no)
 AC_ARG_ENABLE(debug,
               AC_HELP_STRING([--enable-debug=no/yes],
-                             [enable debugging output]),[],[enable_debug=no])
+                             [enable debugging output]),[],[enable_debug=yes])
 if test x"$enable_debug" = x"yes"; then
    AC_DEFINE(ENABLE_DEBUG, [], [whether debugging is enabled])
 fi
@@ -725,5 +725,6 @@ AC_MSG_NOTICE([])
 AC_MSG_NOTICE([Miscellaneous])
 AC_MSG_NOTICE([])
 AC_MSG_NOTICE([  Debug: $enable_debug])
+AC_MSG_NOTICE([  Warnings: $enable_compile_warnings])
 AC_MSG_NOTICE([  Readline: $lv_use_readline])
 AC_MSG_NOTICE([])
index 50842cb1e772aa8ceb3bbe3df3f40651ca76e226..b30b874126fa285ce6c56ec32dfcc416c6d01daa 100644 (file)
@@ -54,6 +54,19 @@ extern "C" {
 #define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
 #define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
 
+
+/* If configured with --enable-debug=yes then library calls
+ * are printed to stderr for debugging.
+ */
+#ifdef ENABLE_DEBUG
+extern int debugFlag;
+#define VIR_DEBUG(category, fmt,...)                                    \
+    do { if (debugFlag) fprintf (stderr, "DEBUG: %s: %s (" fmt ")\n", category, __func__, __VA_ARGS__); } while (0)
+#else
+#define VIR_DEBUG(category, fmt,...)
+    do { } while (0)
+#endif /* !ENABLE_DEBUG */
+
 /* C99 uses __func__.  __FUNCTION__ is legacy. */
 #ifndef __GNUC__
 #define __FUNCTION__ __func__
index ca38c547541e0ec9484e208869d36f352a383db4..3a5cb7ba509de75958af75836362443f3be965c5 100644 (file)
@@ -55,18 +55,12 @@ static virStateDriverPtr virStateDriverTab[MAX_DRIVERS];
 static int virStateDriverTabCount = 0;
 static int initialized = 0;
 
-/* If configured with --enable-debug=yes then library calls
- * are printed to stderr for debugging.
- */
+#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
+#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
+
 #ifdef ENABLE_DEBUG
-#define DEBUG(fs,...)                                                   \
-    fprintf (stderr, "libvirt: %s (" fs ")\n", __func__, __VA_ARGS__)
-#define DEBUG0                                                          \
-    fprintf (stderr, "libvirt: %s ()\n", __func__)
-#else
-#define DEBUG0
-#define DEBUG(fs,...)
-#endif /* !ENABLE_DEBUG */
+int debugFlag = 0;
+#endif
 
 static int virConnectAuthCallbackDefault(virConnectCredentialPtr cred,
                                          unsigned int ncred,
@@ -179,11 +173,21 @@ winsock_init (void)
 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 && *debugEnv != '0')
+        debugFlag = 1;
+#endif
+
+    DEBUG0("register drivers");
+
 #if HAVE_WINSOCK2_H
     if (winsock_init () == -1) return -1;
 #endif
@@ -542,20 +546,17 @@ do_open (const char *name,
         goto failed;
     }
 
-#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);
-#endif
+    DEBUG("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);
 
     ret->name = strdup (name);
     if (!ret->name) {
@@ -564,18 +565,14 @@ 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);
-#endif
+        DEBUG("trying driver %d (%s) ...",
+              i, virDriverTab[i]->name);
         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")));
-#endif
+        DEBUG("driver %d %s returned %s",
+              i, virDriverTab[i]->name,
+              res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
+              (res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
+               (res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
         if (res == VIR_DRV_OPEN_ERROR) goto failed;
         else if (res == VIR_DRV_OPEN_SUCCESS) {
             ret->driver = virDriverTab[i];
@@ -591,13 +588,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")));
-#endif
+        DEBUG("network driver %d %s returned %s",
+              i, virNetworkDriverTab[i]->name,
+              res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
+              (res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
+               (res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
         if (res == VIR_DRV_OPEN_ERROR) {
             if (STREQ(virNetworkDriverTab[i]->name, "remote")) {
                 virLibConnWarning (NULL, VIR_WAR_NO_NETWORK, 
index bf887118f0d785435c3be8476af171ab1bd86c58..860b4d8363937434dbf0e60e5ceac57d8d97a919 100644 (file)
@@ -72,6 +72,9 @@
 #include "remote_internal.h"
 #include "remote_protocol.h"
 
+#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt,__VA_ARGS__)
+#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
+
 /* Per-connection private data. */
 #define MAGIC 999               /* private_data->magic if OK */
 #define DEAD 998                /* private_data->magic if dead/closed */
@@ -159,22 +162,6 @@ remoteStartup(void)
     return 0;
 }
 
-#if HAVE_SASL || HAVE_POLKIT
-static void
-remoteDebug(struct private_data *priv, const char *msg,...)
-{
-    va_list args;
-    if (priv->debugLog == NULL)
-        return;
-
-    va_start(args, msg);
-    vfprintf(priv->debugLog, msg, args);
-    va_end(args);
-    fprintf(priv->debugLog, "\n");
-}
-#endif /* HAVE_SASL */
-
-
 /**
  * remoteFindServerPath:
  *
@@ -426,14 +413,9 @@ doRemoteOpen (virConnectPtr conn,
                 priv->debugLog = stdout;
             else
                 priv->debugLog = stderr;
-        }
-#ifdef ENABLE_DEBUG
-        else
-            fprintf (stderr,
-                     "remoteOpen: "
-                     "passing through variable '%s' ('%s') to remote end\n",
-                     var->name, var->value);
-#endif
+        } else
+            DEBUG("passing through variable '%s' ('%s') to remote end",
+                  var->name, var->value);
     }
 
 #ifdef HAVE_XMLURI_QUERY_RAW
@@ -478,9 +460,7 @@ doRemoteOpen (virConnectPtr conn,
     }
 
     assert (name);
-#ifdef ENABLE_DEBUG
-    fprintf (stderr, "remoteOpen: proceeding with name = %s\n", name);
-#endif
+    DEBUG("proceeding with name = %s", name);
 
     /* Connect to the remote service. */
     switch (transport) {
@@ -910,9 +890,7 @@ initialise_gnutls (virConnectPtr conn)
         return -1;
 
     /* Set the trusted CA cert. */
-#ifdef ENABLE_DEBUG
-    fprintf (stderr, "loading CA file %s\n", LIBVIRT_CACERT);
-#endif
+    DEBUG("loading CA file %s", LIBVIRT_CACERT);
     err =
         gnutls_certificate_set_x509_trust_file (x509_cred, LIBVIRT_CACERT,
                                                 GNUTLS_X509_FMT_PEM);
@@ -922,10 +900,8 @@ initialise_gnutls (virConnectPtr conn)
     }
 
     /* Set the client certificate and private key. */
-#ifdef ENABLE_DEBUG
-    fprintf (stderr, "loading client cert and key from files %s and %s\n",
-             LIBVIRT_CLIENTCERT, LIBVIRT_CLIENTKEY);
-#endif
+    DEBUG("loading client cert and key from files %s and %s",
+          LIBVIRT_CLIENTCERT, LIBVIRT_CLIENTKEY);
     err =
         gnutls_certificate_set_x509_key_file (x509_cred,
                                               LIBVIRT_CLIENTCERT,
@@ -1000,10 +976,9 @@ negotiate_gnutls_on_connection (virConnectPtr conn,
 
     /* Verify certificate. */
     if (verify_certificate (conn, priv, session) == -1) {
-            fprintf (stderr,
-                     "remote_internal: failed to verify peer's certificate\n");
-            if (!no_verify) return NULL;
-        }
+        DEBUG0("failed to verify peer's certificate");
+        if (!no_verify) return NULL;
+    }
 
     /* At this point, the server is verifying _our_ certificate, IP address,
      * etc.  If we make the grade, it will send us a '\1' byte.
@@ -3013,7 +2988,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
     int ret = -1;
     const char *mechlist;
 
-    remoteDebug(priv, "Client initialize SASL authentication");
+    DEBUG0("Client initialize SASL authentication");
     /* Sets up the SASL library as a whole */
     err = sasl_client_init(NULL);
     if (err != SASL_OK) {
@@ -3085,7 +3060,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
         }
         ssf *= 8; /* key size is bytes, sasl wants bits */
 
-        remoteDebug(priv, "Setting external SSF %d", ssf);
+        DEBUG("Setting external SSF %d", ssf);
         err = sasl_setprop(saslconn, SASL_SSF_EXTERNAL, &ssf);
         if (err != SASL_OK) {
             __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
@@ -3135,7 +3110,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
     }
  restart:
     /* Start the auth negotiation on the client end first */
-    remoteDebug(priv, "Client start negotiation mechlist '%s'", mechlist);
+    DEBUG("Client start negotiation mechlist '%s'", mechlist);
     err = sasl_client_start(saslconn,
                             mechlist,
                             &interact,
@@ -3195,7 +3170,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
     sargs.data.data_val = (char*)clientout;
     sargs.data.data_len = clientoutlen;
     sargs.mech = (char*)mech;
-    remoteDebug(priv, "Server start negotiation with mech %s. Data %d bytes %p", mech, clientoutlen, clientout);
+    DEBUG("Server start negotiation with mech %s. Data %d bytes %p", mech, clientoutlen, clientout);
 
     /* Now send the initial auth data to the server */
     memset (&sret, 0, sizeof sret);
@@ -3208,8 +3183,8 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
     /* NB, distinction of NULL vs "" is *critical* in SASL */
     serverin = sret.nil ? NULL : sret.data.data_val;
     serverinlen = sret.data.data_len;
-    remoteDebug(priv, "Client step result complete: %d. Data %d bytes %p",
-                complete, serverinlen, serverin);
+    DEBUG("Client step result complete: %d. Data %d bytes %p",
+          complete, serverinlen, serverin);
 
     /* Loop-the-loop...
      * Even if the server has completed, the client must *always* do at least one step
@@ -3262,7 +3237,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
             free(serverin);
             serverin = NULL;
         }
-        remoteDebug(priv, "Client step result %d. Data %d bytes %p", err, clientoutlen, clientout);
+        DEBUG("Client step result %d. Data %d bytes %p", err, clientoutlen, clientout);
 
         /* Previous server call showed completion & we're now locally complete too */
         if (complete && err == SASL_OK)
@@ -3274,7 +3249,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
         pargs.nil = clientout ? 0 : 1;
         pargs.data.data_val = (char*)clientout;
         pargs.data.data_len = clientoutlen;
-        remoteDebug(priv, "Server step with %d bytes %p", clientoutlen, clientout);
+        DEBUG("Server step with %d bytes %p", clientoutlen, clientout);
 
         memset (&pret, 0, sizeof pret);
         if (call (conn, priv, in_open, REMOTE_PROC_AUTH_SASL_STEP,
@@ -3287,8 +3262,8 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
         serverin = pret.nil ? NULL : pret.data.data_val;
         serverinlen = pret.data.data_len;
 
-        remoteDebug(priv, "Client step result complete: %d. Data %d bytes %p",
-                    complete, serverinlen, serverin);
+        DEBUG("Client step result complete: %d. Data %d bytes %p",
+              complete, serverinlen, serverin);
 
         /* This server call shows complete, and earlier client step was OK */
         if (complete && err == SASL_OK) {
@@ -3308,7 +3283,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
             goto cleanup;
         }
         ssf = *(const int *)val;
-        remoteDebug(priv, "SASL SSF value %d", ssf);
+        DEBUG("SASL SSF value %d", ssf);
         if (ssf < 56) { /* 56 == DES level, good for Kerberos */
             __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
                              VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
@@ -3317,7 +3292,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
         }
     }
 
-    remoteDebug(priv, "SASL authentication complete");
+    DEBUG0("SASL authentication complete");
     priv->saslconn = saslconn;
     ret = 0;
 
@@ -3352,7 +3327,7 @@ remoteAuthPolkit (virConnectPtr conn, struct private_data *priv, int in_open,
         NULL,
         0,
     };
-    remoteDebug(priv, "Client initialize PolicyKit authentication");
+    DEBUG0("Client initialize PolicyKit authentication");
 
     if (auth && auth->cb) {
         /* Check if the neccessary credential type for PolicyKit is supported */
@@ -3370,10 +3345,10 @@ remoteAuthPolkit (virConnectPtr conn, struct private_data *priv, int in_open,
                 return -1;
             }
         } else {
-            remoteDebug(priv, "Client auth callback does not support PolicyKit");
+            DEBUG0("Client auth callback does not support PolicyKit");
         }
     } else {
-        remoteDebug(priv, "No auth callback provided");
+        DEBUG0("No auth callback provided");
     }
 
     memset (&ret, 0, sizeof ret);
@@ -3383,7 +3358,7 @@ remoteAuthPolkit (virConnectPtr conn, struct private_data *priv, int in_open,
         return -1; /* virError already set by call */
     }
 
-    remoteDebug(priv, "PolicyKit authentication complete");
+    DEBUG0("PolicyKit authentication complete");
     return 0;
 }
 #endif /* HAVE_POLKIT */
index 99f99ce5651b11edca7c78d3e5778fc12db903a3..187b7f5a0114e6e82155f90868dcfe5bc4720fb8 100644 (file)
@@ -40,6 +40,8 @@
 #include "xm_internal.h"
 #include "xml.h"
 
+#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt,__VA_ARGS__)
+
 static int
 xenUnifiedNodeGetInfo (virConnectPtr conn, virNodeInfoPtr info);
 static int
@@ -271,15 +273,11 @@ xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int f
             continue;
 
         if (drivers[i]->open) {
-#ifdef ENABLE_DEBUG
-            fprintf (stderr, "libvirt: xenUnifiedOpen: trying Xen sub-driver %d\n", i);
-#endif
+            DEBUG("trying Xen sub-driver %d", i);
             if (drivers[i]->open (conn, uri, auth, flags) == VIR_DRV_OPEN_SUCCESS)
                 priv->opened[i] = 1;
-#ifdef ENABLE_DEBUG
-            fprintf (stderr, "libvirt: xenUnifiedOpen: Xen sub-driver %d open %s\n",
-                     i, priv->opened[i] ? "ok" : "failed");
-#endif
+            DEBUG("Xen sub-driver %d open %s\n",
+                  i, priv->opened[i] ? "ok" : "failed");
         }
 
         /* If as root, then all drivers must succeed.
index 8e4c3d5ed955223881c1dcb5b9f3ce5846004c5e..bff625bf39a0272c5b1bf154c5e7dc022b81791e 100644 (file)
@@ -48,6 +48,9 @@
 /* required for cpumap_t */
 #include <xen/dom0_ops.h>
 
+#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt,__VA_ARGS__)
+#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
+
 #ifndef PROXY
 static int xenDaemonListDomains(virConnectPtr conn, int *ids, int maxids);
 static int xenDaemonNumOfDomains(virConnectPtr conn);
@@ -3410,9 +3413,7 @@ xenDaemonDomainMigratePerform (virDomainPtr domain,
         }
     }
 
-#ifdef ENABLE_DEBUG
-    fprintf (stderr, "hostname = %s, port = %s\n", hostname, port);
-#endif
+    DEBUG("hostname = %s, port = %s", hostname, port);
 
     /* Make the call. */
     ret = xend_op (domain->conn, domain->name,
@@ -3424,9 +3425,7 @@ xenDaemonDomainMigratePerform (virDomainPtr domain,
                    NULL);
     free (hostname);
 
-#ifdef ENABLE_DEBUG
-    fprintf (stderr, "migration done\n");
-#endif
+    DEBUG0("migration done");
 
     return ret;
 }