From: Richard W.M. Jones Date: Fri, 6 May 2011 16:32:59 +0000 (-0400) Subject: add-domain: Suppress libvirt errors on stderr. X-Git-Tag: 1.11.4~5 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=a4c28b4ed1c5a102c8de2a7425568eb504d05c34 add-domain: Suppress libvirt errors on stderr. Install an error handler on the libvirt error connection so that errors are not printed on stderr (instead they go up through the usual libguestfs error mechanism). Unfortunately this doesn't suppress initial connection error messages to stderr. I cannot see how to do this without affecting the global libvirt error handler, which is not acceptable for a library to be doing. --- diff --git a/src/virt.c b/src/virt.c index aa2c022..cd48888 100644 --- a/src/virt.c +++ b/src/virt.c @@ -53,6 +53,12 @@ init_libxml2 (void) LIBXML_TEST_VERSION; } +static void +ignore_errors (void *ignore, virErrorPtr ignore2) +{ + /* empty */ +} + struct guestfs___add_libvirt_dom_argv { uint64_t bitmask; #define GUESTFS___ADD_LIBVIRT_DOM_READONLY_BITMASK (UINT64_C(1)<<0) @@ -102,6 +108,12 @@ guestfs__add_domain (guestfs_h *g, const char *domain_name, goto cleanup; } + /* Suppress default behaviour of printing errors to stderr. Note + * you can't set this to NULL to ignore errors; setting it to NULL + * restores the default error handler ... + */ + virConnSetErrorFunc (conn, NULL, ignore_errors); + dom = virDomainLookupByName (conn, domain_name); if (!dom) { err = virGetLastError ();