qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Ian Jackson <ian.jackson@eu.citrix.com>
To: qemu-devel@nongnu.org
Cc: "Ian Jackson" <ian.jackson@eu.citrix.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Eric Blake" <eblake@redhat.com>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"Alistair Francis" <alistair.francis@xilinx.com>,
	"Ian Jackson" <Ian.Jackson@eu.citrix.com>
Subject: [Qemu-devel] [RFC PATCH 2/7] error reporting: Provide error_report_errno (and error_vreport_errno)
Date: Thu, 26 Apr 2018 17:53:27 +0100	[thread overview]
Message-ID: <1524761612-5307-3-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com>

This will let us replace a lot of open coded calls to perror,
strerror, etc.

No callers yet so no functional change.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
 include/qemu/error-report.h |  2 ++
 util/qemu-error.c           | 28 ++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index e1c8ae1..2b29678 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -37,10 +37,12 @@ void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 void error_set_progname(const char *argv0);
 
 void error_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
+void error_vreport_errno(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 void warn_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 void info_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 
 void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+void error_report_errno(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 void warn_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 void info_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 
diff --git a/util/qemu-error.c b/util/qemu-error.c
index 9acc4b5..428c762 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -245,6 +245,18 @@ void error_vreport(const char *fmt, va_list ap)
 }
 
 /*
+ * Print an error message to current monitor if we have one, else to stderr.
+ * Format arguments like vsprintf().  The resulting message should be
+ * a single phrase, with no newline or trailing punctuation.
+ * Prepend the current location and append ": " strerror(errno) "\n".
+ * It's wrong to call this in a QMP monitor.  Use error_setg() there.
+ */
+void error_vreport_errno(const char *fmt, va_list ap)
+{
+    vreport(REPORT_TYPE_ERROR, errno, fmt, ap);
+}
+
+/*
  * Print a warning message to current monitor if we have one, else to stderr.
  * Format arguments like vsprintf().  The resulting message should be
  * a single phrase, with no newline or trailing punctuation.
@@ -286,6 +298,22 @@ void error_report(const char *fmt, ...)
 }
 
 /*
+ * Print an error message to current monitor if we have one, else to stderr.
+ * Format arguments like sprintf().  The resulting message should be
+ * a single phrase, with no newline or trailing punctuation.
+ * Prepend the current location and append ": " strerror(errno) "\n".
+ * It's wrong to call this in a QMP monitor.  Use error_setg() there.
+ */
+void error_report_errno(const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    vreport(REPORT_TYPE_ERROR, errno, fmt, ap);
+    va_end(ap);
+}
+
+/*
  * Print a warning message to current monitor if we have one, else to stderr.
  * Format arguments like sprintf(). The resulting message should be a
  * single phrase, with no newline or trailing punctuation.
-- 
2.1.4

  parent reply	other threads:[~2018-04-26 16:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-26 16:53 [Qemu-devel] [RFC PATCH 0/7] Introduce error_[v]report_errno[val] Ian Jackson
2018-04-26 16:53 ` [Qemu-devel] [RFC PATCH 1/7] error reporting: Introduce errnoval parameter to vreport Ian Jackson
2018-04-26 17:24   ` Eric Blake
2018-04-26 17:32     ` Ian Jackson
2018-04-26 17:45       ` Eric Blake
2018-04-26 18:23         ` Ian Jackson
2018-04-26 18:12     ` Eric Blake
2018-04-26 16:53 ` Ian Jackson [this message]
2018-04-26 17:27   ` [Qemu-devel] [RFC PATCH 2/7] error reporting: Provide error_report_errno (and error_vreport_errno) Eric Blake
2018-04-26 16:53 ` [Qemu-devel] [RFC PATCH 3/7] error reporting: Use error_report_errno in obvious places Ian Jackson
2018-04-26 17:37   ` Eric Blake
2018-04-26 17:43     ` Ian Jackson
2018-04-26 18:07       ` Eric Blake
2018-04-26 16:53 ` [Qemu-devel] [RFC PATCH 4/7] error reporting: Fix some error messages to use ":" rather than ", " Ian Jackson
2018-04-26 16:53 ` [Qemu-devel] [RFC PATCH 5/7] error reporting: Provide error_report_errnoval (and error_vreport_errnoval) Ian Jackson
2018-04-26 17:31   ` Eric Blake
2018-04-26 17:42     ` Ian Jackson
2018-04-26 16:53 ` [Qemu-devel] [RFC PATCH 6/7] error reporting: Use error_report_errnoval in obvious places Ian Jackson
2018-04-26 16:53 ` [Qemu-devel] [RFC PATCH 7/7] error reporting: HACKING: Say to use error_report_errno Ian Jackson
2018-04-26 17:51   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1524761612-5307-3-git-send-email-ian.jackson@eu.citrix.com \
    --to=ian.jackson@eu.citrix.com \
    --cc=alistair.francis@xilinx.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).