mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-23 19:49:43 +00:00
util/error: Save errno from clobbering
There may be calls to error_setg() and especially error_setg_errno() which blindly (and until now wrongly) assume these functions not to clobber errno (e.g., they pass errno to error_setg_errno() and return -errno afterwards). Instead of trying to find and fix all of these constructs, just make sure error_setg() and error_setg_errno() indeed do not clobber errno. Suggested-by: Eric Blake <eblake@redhat.com> Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Benoit Canet <benoit@irqsave.net Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
5a37b60a61
commit
b276d24994
@ -27,6 +27,7 @@ void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...)
|
|||||||
{
|
{
|
||||||
Error *err;
|
Error *err;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
int saved_errno = errno;
|
||||||
|
|
||||||
if (errp == NULL) {
|
if (errp == NULL) {
|
||||||
return;
|
return;
|
||||||
@ -41,6 +42,8 @@ void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...)
|
|||||||
err->err_class = err_class;
|
err->err_class = err_class;
|
||||||
|
|
||||||
*errp = err;
|
*errp = err;
|
||||||
|
|
||||||
|
errno = saved_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
|
void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
|
||||||
@ -49,6 +52,7 @@ void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
|
|||||||
Error *err;
|
Error *err;
|
||||||
char *msg1;
|
char *msg1;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
int saved_errno = errno;
|
||||||
|
|
||||||
if (errp == NULL) {
|
if (errp == NULL) {
|
||||||
return;
|
return;
|
||||||
@ -69,6 +73,8 @@ void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
|
|||||||
err->err_class = err_class;
|
err->err_class = err_class;
|
||||||
|
|
||||||
*errp = err;
|
*errp = err;
|
||||||
|
|
||||||
|
errno = saved_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
void error_setg_file_open(Error **errp, int os_errno, const char *filename)
|
void error_setg_file_open(Error **errp, int os_errno, const char *filename)
|
||||||
|
Loading…
Reference in New Issue
Block a user