diff options
author | Richard W.M. Jones <[email protected]> | 2012-07-24 14:26:55 +0100 |
---|---|---|
committer | Richard W.M. Jones <[email protected]> | 2012-07-24 14:26:55 +0100 |
commit | 67e1c90605f82dbc878a309e7315d982fc63f30d (patch) | |
tree | 384ccbd90f66c6d7535ed398792407e9f07dc5aa /src | |
parent | 493e80ab4e7199bdbb44b16535448d65944eca66 (diff) | |
download | libguestfs-67e1c90605f82dbc878a309e7315d982fc63f30d.tar.gz libguestfs-67e1c90605f82dbc878a309e7315d982fc63f30d.tar.xz libguestfs-67e1c90605f82dbc878a309e7315d982fc63f30d.zip |
launch: libvirt: Suppress printing of libvirt errors to stderr and other cleanups.
Diffstat (limited to 'src')
-rw-r--r-- | src/launch-libvirt.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c index 1e7542ca..0ac7af0f 100644 --- a/src/launch-libvirt.c +++ b/src/launch-libvirt.c @@ -83,6 +83,7 @@ static void restorecon (const char *dir); static int is_dir (const char *path); static int is_blk (const char *path); static int random_chars (char *ret, size_t len); +static void ignore_errors (void *ignore, virErrorPtr ignore2); static int launch_libvirt (guestfs_h *g, const char *libvirt_uri) @@ -131,11 +132,17 @@ launch_libvirt (guestfs_h *g, const char *libvirt_uri) /* XXX Support libvirt authentication in the future. */ conn = virConnectOpen (libvirt_uri); if (!conn) { - error (g, _("could not connect to libvirt: URI: %s"), + libvirt_error (g, _("could not connect to libvirt (URI = %s)"), libvirt_uri ? : "NULL"); 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); + if (g->verbose) guestfs___print_timestamped_message (g, "get libvirt capabilities"); @@ -1266,6 +1273,12 @@ random_chars (char *ret, size_t len) return 0; } +static void +ignore_errors (void *ignore, virErrorPtr ignore2) +{ + /* empty */ +} + static int shutdown_libvirt (guestfs_h *g) { @@ -1311,9 +1324,11 @@ libvirt_error (guestfs_h *g, const char *fs, ...) /* In all recent libvirt, this retrieves the thread-local error. */ err = virGetLastError (); - - error (g, "%s: %s [code=%d domain=%d]", - msg, err->message, err->code, err->domain); + if (err) + error (g, "%s: %s [code=%d domain=%d]", + msg, err->message, err->code, err->domain); + else + error (g, "%s", msg); /* NB. 'err' must not be freed! */ free (msg); |