qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH RFC] qemu-error: introduce error_report_once
@ 2018-05-15  9:13 Peter Xu
  2018-05-15  9:16 ` no-reply
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Peter Xu @ 2018-05-15  9:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: peterx, Markus Armbruster

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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2018-06-01  3:17 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-15  9:13 [Qemu-devel] [PATCH RFC] qemu-error: introduce error_report_once Peter Xu
2018-05-15  9:16 ` 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

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).