[libvirt] [PATCH 4/7] lxc: initialize logging configuration
Amy Griffis
amy.griffis at hp.com
Wed Oct 7 19:36:18 UTC 2009
Daniel P. Berrange wrote: [Mon Oct 05 2009, 08:52:20AM EDT]
> ACK, although it'd need a small change for my suggested API contract
> change in your previous patch in the series
Updated for API change...
Before launching the lxc controller, have the lxc driver query the log
settings and setup envp[]. This provides the advantage of honoring the
actual log configuration instead of only what had been set in the
environment. The lxc controller now simply has to call
virLogSetFromEnv().
---
src/lxc/lxc_controller.c | 3 ++
src/lxc/lxc_driver.c | 77 ++++++++++++++++++++++++++++++++++++++++------
2 files changed, 70 insertions(+), 10 deletions(-)
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index bca721b..545f718 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -793,6 +793,9 @@ int main(int argc, char *argv[])
}
}
+ /* Initialize logging */
+ virLogSetFromEnv();
+
/* Accept initial client which is the libvirtd daemon */
if ((client = accept(monitor, NULL, 0)) < 0) {
virReportSystemError(NULL, errno, "%s",
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 5fb4105..f79d109 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -830,9 +830,13 @@ static int lxcControllerStart(virConnectPtr conn,
{
int i;
int rc;
- int ret = -1;
int largc = 0, larga = 0;
const char **largv = NULL;
+ int lenvc = 0, lenva = 0;
+ const char **lenv = NULL;
+ char *filterstr;
+ char *outputstr;
+ char *tmp;
pid_t child;
int status;
fd_set keepfd;
@@ -863,6 +867,52 @@ static int lxcControllerStart(virConnectPtr conn,
goto no_memory; \
} while (0)
+#define ADD_ENV_SPACE \
+ do { \
+ if (lenvc == lenva) { \
+ lenva += 10; \
+ if (VIR_REALLOC_N(lenv, lenva) < 0) \
+ goto no_memory; \
+ } \
+ } while (0)
+
+#define ADD_ENV(thisarg) \
+ do { \
+ ADD_ENV_SPACE; \
+ lenv[lenvc++] = thisarg; \
+ } while (0)
+
+#define ADD_ENV_PAIR(envname, val) \
+ do { \
+ char *envval; \
+ ADD_ENV_SPACE; \
+ if (virAsprintf(&envval, "%s=%s", envname, val) < 0) \
+ goto no_memory; \
+ lenv[lenvc++] = envval; \
+ } while (0)
+
+ if (virAsprintf(&tmp, "LIBVIRT_DEBUG=%d", virLogGetDefaultPriority()) < 0)
+ goto no_memory;
+ ADD_ENV(tmp);
+
+ if (virLogGetNbFilters() > 0) {
+ filterstr = virLogGetFilters();
+ if (!filterstr)
+ goto no_memory;
+ ADD_ENV_PAIR("LIBVIRT_LOG_FILTERS", filterstr);
+ VIR_FREE(filterstr);
+ }
+
+ if (virLogGetNbOutputs() > 0) {
+ outputstr = virLogGetOutputs();
+ if (!outputstr)
+ goto no_memory;
+ ADD_ENV_PAIR("LIBVIRT_LOG_OUTPUTS", outputstr);
+ VIR_FREE(outputstr);
+ }
+
+ ADD_ENV(NULL);
+
snprintf(appPtyStr, sizeof(appPtyStr), "%d", appPty);
emulator = vm->def->emulator;
@@ -883,7 +933,7 @@ static int lxcControllerStart(virConnectPtr conn,
FD_SET(appPty, &keepfd);
- if (virExec(conn, largv, NULL, &keepfd, &child,
+ if (virExec(conn, largv, lenv, &keepfd, &child,
-1, &logfd, &logfd,
VIR_EXEC_NONE) < 0)
goto cleanup;
@@ -910,18 +960,25 @@ static int lxcControllerStart(virConnectPtr conn,
#undef ADD_ARG
#undef ADD_ARG_LIT
#undef ADD_ARG_SPACE
+#undef ADD_ENV_SPACE
+#undef ADD_ENV_PAIR
- ret = 0;
-
-cleanup:
- for (i = 0 ; i < largc ; i++)
- VIR_FREE(largv[i]);
-
- return ret;
+ return 0;
no_memory:
virReportOOMError(conn);
- goto cleanup;
+cleanup:
+ if (largv) {
+ for (i = 0 ; i < largc ; i++)
+ VIR_FREE(largv[i]);
+ VIR_FREE(largv);
+ }
+ if (lenv) {
+ for (i=0 ; i < lenvc ; i++)
+ VIR_FREE(lenv[i]);
+ VIR_FREE(lenv);
+ }
+ return -1;
}
More information about the libvir-list
mailing list