From 11a2e2972a959a35c924fbc0bc3528505527b3a0 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Thu, 21 Aug 2008 10:12:32 +0000 Subject: [PATCH] Propagate virConnectOpen errors to global error object --- ChangeLog | 5 +++++ src/libvirt.c | 20 ++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd7b20b20a..485e575402 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Aug 21 11:09:09 BST 2008 Daniel P. Berrange + + * src/libvirt.c: Propagate error from virConnect to global + error object for virConnectOpen() failures + Wed Aug 21 10:28:09 BST 2008 Daniel P. Berrange * libvirt.spec.in: Add libvirt_lxc to spec file and conditionals diff --git a/src/libvirt.c b/src/libvirt.c index 9604b58f78..c31a6197aa 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -744,10 +744,8 @@ do_open (const char *name, name = "xen:///"; ret = virGetConnect(); - if (ret == NULL) { - virLibConnError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection")); + if (ret == NULL) return NULL; - } uri = xmlParseURI (name); if (!uri) { @@ -848,7 +846,21 @@ do_open (const char *name, failed: if (ret->driver) ret->driver->close (ret); if (uri) xmlFreeURI(uri); - virUnrefConnect(ret); + + /* If not global error was set, copy any error set + in the connection object we're about to dispose of */ + if (__lastErr.code == VIR_ERR_OK) { + memcpy(&__lastErr, &ret->err, sizeof(ret->err)); + memset(&ret->err, 0, sizeof(ret->err)); + } + + /* Still no error set, then raise a generic error */ + if (__lastErr.code == VIR_ERR_OK) + virLibConnError (NULL, VIR_ERR_INTERNAL_ERROR, + _("unable to open connection")); + + virUnrefConnect(ret); + return NULL; } -- GitLab