From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: peterx@redhat.com, Markus Armbruster <armbru@redhat.com>
Subject: [Qemu-devel] [PATCH RFC] qemu-error: introduce error_report_once
Date: Tue, 15 May 2018 17:13:56 +0800 [thread overview]
Message-ID: <20180515091356.24106-1-peterx@redhat.com> (raw)
I stole the printk_once() macro.
I always wanted to be able to print some error directly if there is a
buffer to dump, however we can't use error_report() really quite often
when there can be any DDOS attack. To avoid that, we can introduce a
print-once function for it.
CC: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
We can for sure introduce similar functions for the rest of the
error_*() functions, it's just an idea to see whether we'd like it
in general.
---
include/qemu/error-report.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index e1c8ae1a52..efebb80e2c 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -44,6 +44,18 @@ void error_report(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);
+#define error_report_once(fmt, ...) \
+ ({ \
+ static bool __print_once; \
+ bool __ret_print_once = !__print_once; \
+ \
+ if (!__print_once) { \
+ __print_once = true; \
+ error_report(fmt, ##__VA_ARGS__); \
+ } \
+ unlikely(__ret_print_once); \
+ })
+
const char *error_get_progname(void);
extern bool enable_timestamp_msg;
--
2.17.0
next reply other threads:[~2018-05-15 9:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-15 9:13 Peter Xu [this message]
2018-05-15 9:16 ` [Qemu-devel] [PATCH RFC] qemu-error: introduce error_report_once no-reply
2018-05-15 12:02 ` Markus Armbruster
2018-05-15 12:38 ` Peter Xu
2018-05-15 15:56 ` Markus Armbruster
2018-05-15 16:39 ` Eric Blake
2018-05-16 3:08 ` Peter Xu
2018-05-15 15:29 ` Eric Blake
2018-05-16 3:07 ` Peter Xu
2018-05-16 14:02 ` Eric Blake
2018-05-17 2:51 ` Peter Xu
2018-05-31 11:03 ` Stefan Hajnoczi
2018-06-01 3:17 ` Peter Xu
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=20180515091356.24106-1-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=armbru@redhat.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
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).