QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] error-report: Add info_report_once helper
Date: Fri, 13 Sep 2019 18:43:44 +0300
Message-ID: <20190913154344.GH1508@uranus> (raw)

We already have error_report_once and warn_report_once,
thus lets add info_report_once to complement. Actually
I use this helper a lot so might be usefull for others.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 include/qemu/error-report.h |   13 +++++++++++++
 util/qemu-error.c           |   20 ++++++++++++++++++++
 2 files changed, 33 insertions(+)

Index: vanilla.git/include/qemu/error-report.h
===================================================================
--- vanilla.git.orig/include/qemu/error-report.h
+++ vanilla.git/include/qemu/error-report.h
@@ -47,6 +47,8 @@ bool error_report_once_cond(bool *printe
     GCC_FMT_ATTR(2, 3);
 bool warn_report_once_cond(bool *printed, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);
+bool info_report_once_cond(bool *printed, const char *fmt, ...)
+    GCC_FMT_ATTR(2, 3);
 
 void error_init(const char *argv0);
 
@@ -72,6 +74,17 @@ void error_init(const char *argv0);
                               fmt, ##__VA_ARGS__);      \
     })
 
+/*
+ * Similar to info_report(), except it prints the message just once.
+ * Return true when it prints, false otherwise.
+ */
+#define info_report_once(fmt, ...)                      \
+    ({                                                  \
+        static bool print_once_;                        \
+        info_report_once_cond(&print_once_,             \
+                              fmt, ##__VA_ARGS__);      \
+    })
+
 const char *error_get_progname(void);
 extern bool enable_timestamp_msg;
 
Index: vanilla.git/util/qemu-error.c
===================================================================
--- vanilla.git.orig/util/qemu-error.c
+++ vanilla.git/util/qemu-error.c
@@ -350,6 +350,26 @@ bool warn_report_once_cond(bool *printed
     return true;
 }
 
+/*
+ * Like info_report(), except print just once.
+ * If *printed is false, print the message, and flip *printed to true.
+ * Return whether the message was printed.
+ */
+bool info_report_once_cond(bool *printed, const char *fmt, ...)
+{
+    va_list ap;
+
+    assert(printed);
+    if (*printed) {
+        return false;
+    }
+    *printed = true;
+    va_start(ap, fmt);
+    vreport(REPORT_TYPE_INFO, fmt, ap);
+    va_end(ap);
+    return true;
+}
+
 static char *qemu_glog_domains;
 
 static void qemu_log_func(const gchar *log_domain,


             reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-13 15:43 Cyrill Gorcunov [this message]
2019-09-14 18:40 ` Markus Armbruster
2019-09-14 18:57   ` Cyrill Gorcunov

Reply instructions:

You may reply publically 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=20190913154344.GH1508@uranus \
    --to=gorcunov@gmail.com \
    --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

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org qemu-devel@archiver.kernel.org
	public-inbox-index qemu-devel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox