From nobody Wed Oct 29 22:39:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526375717863704.305259230097; Tue, 15 May 2018 02:15:17 -0700 (PDT) Received: from localhost ([::1]:53615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIW31-00029L-Ni for importer@patchew.org; Tue, 15 May 2018 05:15:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIW29-0001mJ-Tl for qemu-devel@nongnu.org; Tue, 15 May 2018 05:14:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIW24-0006hh-Rm for qemu-devel@nongnu.org; Tue, 15 May 2018 05:14:13 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57830 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fIW24-0006gJ-NV for qemu-devel@nongnu.org; Tue, 15 May 2018 05:14:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7D351400BA82 for ; Tue, 15 May 2018 09:14:02 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-204-161.brq.redhat.com [10.40.204.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D3EF10EE6C9; Tue, 15 May 2018 09:13:57 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 15 May 2018 17:13:56 +0800 Message-Id: <20180515091356.24106-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 15 May 2018 09:14:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 15 May 2018 09:14:02 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'peterx@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH RFC] qemu-error: introduce error_report_once X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Peter Xu --- 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); =20 +#define error_report_once(fmt, ...) \ + ({ \ + static bool __print_once; \ + bool __ret_print_once =3D !__print_once; \ + \ + if (!__print_once) { \ + __print_once =3D true; \ + error_report(fmt, ##__VA_ARGS__); \ + } \ + unlikely(__ret_print_once); \ + }) + const char *error_get_progname(void); extern bool enable_timestamp_msg; =20 --=20 2.17.0