[Libvirt-cim] [PATCH] Redirect stdout & stderr when run as out-of-process provider

Eduardo Lima (Etrunko) eblima at linux.vnet.ibm.com
Thu Sep 22 19:05:20 UTC 2011


On 09/20/2011 07:33 PM, Chip Vincent wrote:
> # HG changeset patch
> # User Chip Vincent <cvincent at us.ibm.com>
> # Date 1316557881 14400
> # Node ID 4d95f2e9f2d8eac1565307def96bd158f5dcf160
> # Parent  db809376d763493849c2a19f587969eaec619b75
> Redirect stdout & stderr when run as out-of-process provider
> 
> When a provider is loaded in-process by Pegasus, messages sent to
> stdout and stderr are suppressed. However, when loaded out-of-process,
> those same messages appear on the console. This happens excessively when
> libvirt-cim LXC_ and XEN_ classes are enumerated and libvirt sends
> "libvir: error : no connection driver available for..." messages to stderr.
> In development, this can sometimes prevent console usage. Until a fix is
> made to Pegasus, we'll suppress console output during provider initialization
> when run in out-of-process mode.
> 
> Signed-off-by: Chip Vincent <cvincent at us.ibm.com>
> 
> diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c
> --- a/libxkutil/misc_util.c
> +++ b/libxkutil/misc_util.c
> @@ -29,6 +29,7 @@
>  #include <stdarg.h>
>  #include <unistd.h>
>  #include <pthread.h>
> +#include <errno.h>

Why are you including errno.h? Is it because of freopen(), stdout and
stderr? I guess you should be including stdio.h if that is the case.

Best regards, Etrunko.

>  #include <libvirt/libvirt.h>
>  #include <libvirt/virterror.h>
> 
> @@ -540,6 +541,17 @@
>  {
>          int ret = 0;
> 
> +        /* The tog-pegasus out-of-process provider feature does not
> +        * redirect stdout and stderr, so it's done here to prevent
> +        * any messages from taking over the console. One example is
> +        * verbose connection failures sent to stdout by libvirt. */
> +        if (strstr(program_invocation_short_name, "cimprovagt") != NULL) {
> +                CU_DEBUG("Redirecting stdout and stderr");
> +
> +                stdout = freopen("/dev/null", "a", stdout);
> +                stderr = freopen("/dev/null", "a", stderr);
> +        }
> +
>          /* double-check lock pattern used for performance reasons */
>          if (libvirt_initialized == 0) {
>                  pthread_mutex_lock(&libvirt_mutex);
> 
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim


-- 
Eduardo de Barros Lima
Software Engineer, Open Virtualization
Linux Technology Center - IBM/Brazil
eblima at br.ibm.com




More information about the Libvirt-cim mailing list