Enable debug by default, but only if LIBVIRT_DEBUG=1. Use generic macro for debug output

This commit is contained in:
Daniel P. Berrange 2008-01-19 18:36:01 +00:00
parent 02b98afe29
commit e8d690aeb5
7 changed files with 102 additions and 112 deletions

View File

@ -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

View 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([])

View 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__

View 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,9 +546,7 @@ do_open (const char *name,
goto failed;
}
#ifdef ENABLE_DEBUG
fprintf (stderr,
"libvirt: do_open: name \"%s\" to URI components:\n"
DEBUG("name \"%s\" to URI components:\n"
" scheme %s\n"
" opaque %s\n"
" authority %s\n"
@ -555,7 +557,6 @@ do_open (const char *name,
name,
uri->scheme, uri->opaque, uri->authority, uri->server,
uri->user, uri->port, uri->path);
#endif
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",
DEBUG("trying driver %d (%s) ...",
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",
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")));
#endif
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",
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")));
#endif
if (res == VIR_DRV_OPEN_ERROR) {
if (STREQ(virNetworkDriverTab[i]->name, "remote")) {
virLibConnWarning (NULL, VIR_WAR_NO_NETWORK,

View 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",
} else
DEBUG("passing through variable '%s' ('%s') to remote end",
var->name, var->value);
#endif
}
#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",
DEBUG("loading client cert and key from files %s and %s",
LIBVIRT_CLIENTCERT, LIBVIRT_CLIENTKEY);
#endif
err =
gnutls_certificate_set_x509_key_file (x509_cred,
LIBVIRT_CLIENTCERT,
@ -1000,8 +976,7 @@ 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");
DEBUG0("failed to verify peer's certificate");
if (!no_verify) return NULL;
}
@ -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,7 +3183,7 @@ 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",
DEBUG("Client step result complete: %d. Data %d bytes %p",
complete, serverinlen, serverin);
/* Loop-the-loop...
@ -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,7 +3262,7 @@ 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",
DEBUG("Client step result complete: %d. Data %d bytes %p",
complete, serverinlen, serverin);
/* This server call shows complete, and earlier client step was 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 */

View 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",
DEBUG("Xen sub-driver %d open %s\n",
i, priv->opened[i] ? "ok" : "failed");
#endif
}
/* If as root, then all drivers must succeed.

View 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;
}