error: ensure errno detail is printed with error_abort

When &error_abort is passed in, the error reporting code
will print the current error message and then abort() the
process. Unfortunately at the time it aborts, we've not
yet appended the errno detail. This makes debugging certain
problems significantly harder as the log is incomplete.

Backports commit 20e2dec14954568848ad74e73aee9b3aeedd6584 from qemu
This commit is contained in:
Daniel P. Berrange 2018-02-21 21:39:59 -05:00 committed by Lioncash
parent 9cf056404a
commit d561d28827
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -46,7 +46,8 @@ static void error_handle_fatal(Error **errp, Error *err)
static void error_setv(Error **errp,
const char *src, int line, const char *func,
ErrorClass err_class, const char *fmt, va_list ap)
ErrorClass err_class, const char *fmt, va_list ap,
const char *suffix)
{
Error *err;
int saved_errno = errno;
@ -59,6 +60,11 @@ static void error_setv(Error **errp,
err = g_malloc0(sizeof(*err));
err->msg = g_strdup_vprintf(fmt, ap);
if (suffix) {
char *msg = err->msg;
err->msg = g_strdup_printf("%s: %s", msg, suffix);
g_free(msg);
}
err->err_class = err_class;
err->src = src;
err->line = line;
@ -77,7 +83,7 @@ void error_set_internal(Error **errp,
va_list ap;
va_start(ap, fmt);
error_setv(errp, src, line, func, err_class, fmt, ap);
error_setv(errp, src, line, func, err_class, fmt, ap, NULL);
va_end(ap);
}
@ -88,7 +94,7 @@ void error_setg_internal(Error **errp,
va_list ap;
va_start(ap, fmt);
error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap);
error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap, NULL);
va_end(ap);
}
@ -97,7 +103,6 @@ void error_setg_errno_internal(Error **errp,
int os_errno, const char *fmt, ...)
{
va_list ap;
char *msg;
int saved_errno = errno;
if (errp == NULL) {
@ -105,15 +110,10 @@ void error_setg_errno_internal(Error **errp,
}
va_start(ap, fmt);
error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap);
error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap,
os_errno != 0 ? strerror(os_errno) : NULL);
va_end(ap);
if (os_errno != 0) {
msg = (*errp)->msg;
(*errp)->msg = g_strdup_printf("%s: %s", msg, strerror(os_errno));
g_free(msg);
}
errno = saved_errno;
}