Peter Xu <pet...@redhat.com> writes: > 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.
Got an example? > To avoid that, we can introduce a > print-once function for it. > > CC: Markus Armbruster <arm...@redhat.com> > Signed-off-by: Peter Xu <pet...@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; Ignorant question: what's the return value's intended use?