diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 3864a31b31af968be535657c8dc1710176fea537..cd7e3b31e0a5d1106e2808aefd1f82cce6eba6c6 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -313,6 +313,8 @@ void virResetLastError (void); void virResetError (virErrorPtr err); void virFreeError (virErrorPtr err); +const char * virGetLastErrorMessage (void); + virErrorPtr virConnGetLastError (virConnectPtr conn); void virConnResetLastError (virConnectPtr conn); int virCopyLastError (virErrorPtr to); diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index dfbf44ef5331fa88454868546f64d4c9b9d5f8b9..4ee2d275393a8314101c7aa6ca94b5fe9a6e1344 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -616,4 +616,9 @@ LIBVIRT_1.0.5 { virNodeDeviceDetachFlags; } LIBVIRT_1.0.3; +LIBVIRT_1.0.6 { + global: + virGetLastErrorMessage; +} LIBVIRT_1.0.5; + # .... define new API here using predicted next version number .... diff --git a/src/util/virerror.c b/src/util/virerror.c index af4da8c8fb7ccda73e37f47c1a2529c39f3121d0..4e1dc9a32b8861d94f7c5fdefe48f1d65317fe26 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -234,6 +234,27 @@ virGetLastError(void) return err; } + +/** + * virGetLastErrorMessage: + * + * Get the most recent error message + * + * Returns the most recent error message string in this + * thread, or a generic message if none is set + */ +const char * +virGetLastErrorMessage(void) +{ + virErrorPtr err = virLastErrorObject(); + if (!err || err->code == VIR_ERR_OK) + return _("no error"); + if (err->message == NULL) + return _("unknown error"); + return err->message; +} + + /** * virSetError: * @newerr: previously saved error object