mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
util: error: Add helpers for saving and restoring of last error
Some cleanup paths overwrite a usefull error message with a less useful one and we then try to preserve the original message. The handlers added in this patch will simplify the operations since they are designed right for the purpose.
This commit is contained in:
parent
1f085acb81
commit
8333e7455e
@ -1605,6 +1605,8 @@ ebtablesRemoveForwardAllowIn;
|
||||
virDispatchError;
|
||||
virErrorCopyNew;
|
||||
virErrorInitialize;
|
||||
virErrorPreserveLast;
|
||||
virErrorRestore;
|
||||
virErrorSetErrnoFromLastError;
|
||||
virLastErrorIsSystemErrno;
|
||||
virRaiseErrorFull;
|
||||
|
@ -371,6 +371,51 @@ virSaveLastError(void)
|
||||
return to;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virErrorPreserveLast:
|
||||
* @saveerr: pointer to virErrorPtr for storing last error object
|
||||
*
|
||||
* Preserves the currently set last error (for the thread) into @saveerr so that
|
||||
* it can be restored via virErrorRestore(). @saveerr must be passed to
|
||||
* virErrorRestore()
|
||||
*/
|
||||
void
|
||||
virErrorPreserveLast(virErrorPtr *saveerr)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
virErrorPtr lasterr = virGetLastError();
|
||||
|
||||
*saveerr = NULL;
|
||||
|
||||
if (lasterr)
|
||||
*saveerr = virErrorCopyNew(lasterr);
|
||||
|
||||
errno = saved_errno;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virErrorRestore:
|
||||
* @savederr: error object holding saved error
|
||||
*
|
||||
* Restores the error passed via @savederr and clears associated memory.
|
||||
*/
|
||||
void
|
||||
virErrorRestore(virErrorPtr *savederr)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
|
||||
if (!*savederr)
|
||||
return;
|
||||
|
||||
virSetError(*savederr);
|
||||
virFreeError(*savederr);
|
||||
*savederr = NULL;
|
||||
errno = saved_errno;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virResetError:
|
||||
* @err: pointer to the virError to clean up
|
||||
|
@ -196,4 +196,7 @@ void virErrorSetErrnoFromLastError(void);
|
||||
|
||||
bool virLastErrorIsSystemErrno(int errnum);
|
||||
|
||||
void virErrorPreserveLast(virErrorPtr *saveerr);
|
||||
void virErrorRestore(virErrorPtr *savederr);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user