From 98cb89af4df7e1776ce418ed6167b6e214a64435 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Wed, 27 Jul 2016 11:24:26 +0200 Subject: [PATCH 1/2] error: error_setg_errno(): errno gets preserved C11 allows errno to be clobbered by pretty much any library function call, so in general callers need to take care to save errno before calling other functions. However, for error reporting functions this is rather awkward and can make the code on the caller side more complicated than necessary. error_setg_errno() already takes care of preserving errno and some functions rely on that, so just promise that we continue to do so in the future. Signed-off-by: Sascha Silbe Message-Id: <1469611466-31574-1-git-send-email-silbe@linux.vnet.ibm.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- include/qapi/error.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/qapi/error.h b/include/qapi/error.h index 0576659603..7e532d00e9 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -170,6 +170,9 @@ void error_setg_internal(Error **errp, * Just like error_setg(), with @os_error info added to the message. * If @os_error is non-zero, ": " + strerror(os_error) is appended to * the human-readable error message. + * + * The value of errno (which usually can get clobbered by almost any + * function call) will be preserved. */ #define error_setg_errno(errp, os_error, fmt, ...) \ error_setg_errno_internal((errp), __FILE__, __LINE__, __func__, \ From 0d6b50d474090b9085c595e2475c40cfdc092411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 5 Jan 2017 14:59:57 +0100 Subject: [PATCH 2/2] error: Report certain hints on stderr when no monitor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hints printed with error_printf_unless_qmp() are suppressed outside monitor context. Reproducer: $ qemu-system-x86_64 -m 1Z qemu-system-x86_64: -m 1Z: Parameter 'size' expects a size Print to stderr instead. The reproducer now additionally prints: You may use k, M, G or T suffixes for kilobytes, megabytes, gigabytes and terabytes. Signed-off-by: Marc-André Lureau Message-Id: <20170105135957.12003-1-marcandre.lureau@redhat.com> Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster [Commit message tweaked] Signed-off-by: Markus Armbruster --- monitor.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/monitor.c b/monitor.c index 0841d436b0..90c5bafcc3 100644 --- a/monitor.c +++ b/monitor.c @@ -3973,6 +3973,8 @@ void error_vprintf_unless_qmp(const char *fmt, va_list ap) { if (cur_mon && !monitor_cur_is_qmp()) { monitor_vprintf(cur_mon, fmt, ap); + } else if (!cur_mon) { + vfprintf(stderr, fmt, ap); } }