[libvirt] [PATCH 4/7] lxc: initialize logging configuration

Daniel P. Berrange berrange at redhat.com
Mon Oct 5 12:52:20 UTC 2009


On Sun, Oct 04, 2009 at 03:29:01PM -0400, Amy Griffis wrote:
> 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     |   73 ++++++++++++++++++++++++++++++++++++++++------
>  2 files changed, 66 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..c5a49f2 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;
> +    virBuffer filterbuf = VIR_BUFFER_INITIALIZER;
> +    virBuffer outputbuf = VIR_BUFFER_INITIALIZER;
> +    char *tmp;
>      pid_t child;
>      int status;
>      fd_set keepfd;
> @@ -863,6 +867,48 @@ 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) {
> +        if (virLogGetFilters(&filterbuf) < 0)
> +            goto no_memory;
> +        ADD_ENV_PAIR("LIBVIRT_LOG_FILTERS", virBufferContentAndReset(&filterbuf));
> +    }
> +
> +    if (virLogGetNbOutputs() > 0) {
> +        if (virLogGetOutputs(&outputbuf) < 0)
> +            goto no_memory;
> +        ADD_ENV_PAIR("LIBVIRT_LOG_OUTPUTS", virBufferContentAndReset(&outputbuf));
> +    }
> +
> +    ADD_ENV(NULL);
> +
>      snprintf(appPtyStr, sizeof(appPtyStr), "%d", appPty);
>  
>      emulator = vm->def->emulator;
> @@ -883,7 +929,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 +956,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;
>  }
>  

ACK, although it'd need a small change for my suggested API contract
change in your previous patch in the series


Daniel
-- 
|: 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 :|




More information about the libvir-list mailing list