From patchwork Thu Mar 21 17:08:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 10864103 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A888B922 for ; Thu, 21 Mar 2019 17:13:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 849EA2A3BE for ; Thu, 21 Mar 2019 17:13:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78AE92A3E5; Thu, 21 Mar 2019 17:13:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2A4CD2A2FF for ; Thu, 21 Mar 2019 17:13:50 +0000 (UTC) Received: from localhost ([127.0.0.1]:42449 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h71GH-00053g-5f for patchwork-qemu-devel@patchwork.kernel.org; Thu, 21 Mar 2019 13:13:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52462) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h71EZ-0003US-Mt for qemu-devel@nongnu.org; Thu, 21 Mar 2019 13:12:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h71BI-0002T6-Rj for qemu-devel@nongnu.org; Thu, 21 Mar 2019 13:08:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42200) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h71BI-0002R6-Gc for qemu-devel@nongnu.org; Thu, 21 Mar 2019 13:08:40 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C81ADC057F4F for ; Thu, 21 Mar 2019 17:08:39 +0000 (UTC) Received: from localhost (ovpn-117-168.ams2.redhat.com [10.36.117.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D99F6014C; Thu, 21 Mar 2019 17:08:37 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Thu, 21 Mar 2019 17:08:30 +0000 Message-Id: <20190321170831.6539-2-stefanha@redhat.com> In-Reply-To: <20190321170831.6539-1-stefanha@redhat.com> References: <20190321170831.6539-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 21 Mar 2019 17:08:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] trace: handle tracefs path truncation 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 , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP If the tracefs mountpoint has a very long path we may exceed PATH_MAX. This is a system misconfiguration and the user must resolve it so that applications can perform path-based system calls successfully. This issue does not occur on real-world systems since tracefs is mounted on /sys/kernel/debug/tracing/, but the compiler is smart enough to foresee the possibility and warn about the unchecked snprintf(3) return value. This patch fixes the compiler warning. Reported-by: Markus Armbruster Signed-off-by: Stefan Hajnoczi Reviewed-by: Markus Armbruster Reviewed-by: Liam Merwick --- trace/ftrace.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/trace/ftrace.c b/trace/ftrace.c index 61692a8682..9749543d9b 100644 --- a/trace/ftrace.c +++ b/trace/ftrace.c @@ -53,7 +53,11 @@ bool ftrace_init(void) } if (tracefs_found) { - snprintf(path, PATH_MAX, "%s%s/tracing_on", mount_point, subdir); + if (snprintf(path, PATH_MAX, "%s%s/tracing_on", mount_point, subdir) + >= sizeof(path)) { + fprintf(stderr, "Using tracefs mountpoint would exceed PATH_MAX\n"); + return false; + } trace_fd = open(path, O_WRONLY); if (trace_fd < 0) { if (errno == EACCES) { @@ -72,7 +76,11 @@ bool ftrace_init(void) } close(trace_fd); } - snprintf(path, PATH_MAX, "%s%s/trace_marker", mount_point, subdir); + if (snprintf(path, PATH_MAX, "%s%s/trace_marker", mount_point, subdir) + >= sizeof(path)) { + fprintf(stderr, "Using tracefs mountpoint would exceed PATH_MAX\n"); + return false; + } trace_marker_fd = open(path, O_WRONLY); if (trace_marker_fd < 0) { perror("Could not open ftrace 'trace_marker' file"); From patchwork Thu Mar 21 17:08:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 10864113 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 138D0139A for ; Thu, 21 Mar 2019 17:18:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E26922A064 for ; Thu, 21 Mar 2019 17:18:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6B322A3F0; Thu, 21 Mar 2019 17:18:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8E89C2A064 for ; Thu, 21 Mar 2019 17:18:23 +0000 (UTC) Received: from localhost ([127.0.0.1]:42638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h71Kg-0008Hw-CB for patchwork-qemu-devel@patchwork.kernel.org; Thu, 21 Mar 2019 13:18:22 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h71EY-0003UJ-Qu for qemu-devel@nongnu.org; Thu, 21 Mar 2019 13:12:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h71BK-0002hS-Mx for qemu-devel@nongnu.org; Thu, 21 Mar 2019 13:08:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37906) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h71BK-0002at-Bw for qemu-devel@nongnu.org; Thu, 21 Mar 2019 13:08:42 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A091F85541 for ; Thu, 21 Mar 2019 17:08:41 +0000 (UTC) Received: from localhost (ovpn-117-168.ams2.redhat.com [10.36.117.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33835605CA; Thu, 21 Mar 2019 17:08:41 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Thu, 21 Mar 2019 17:08:31 +0000 Message-Id: <20190321170831.6539-3-stefanha@redhat.com> In-Reply-To: <20190321170831.6539-1-stefanha@redhat.com> References: <20190321170831.6539-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 21 Mar 2019 17:08:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/2] trace: avoid SystemTap dtrace(1) warnings on empty files 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 , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP target/hppa/trace-events only contains disabled events, resulting in a trace-dtrace.dtrace file that says "provider qemu {}". SystemTap's dtrace(1) tool prints a warning when processing this input file. This patch avoids the error by emitting an empty file instead of "provider qemu {}" when there are no enabled trace events. Fixes: 23c3d569f44284066714ff7c46bc4f19e630583f ("target/hppa: add TLB trace events") Reported-by: Markus Armbruster Signed-off-by: Stefan Hajnoczi Reviewed-by: Markus Armbruster Reviewed-by: Liam Merwick --- scripts/tracetool/format/d.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/tracetool/format/d.py b/scripts/tracetool/format/d.py index 78397c24d2..c7cb2a93a6 100644 --- a/scripts/tracetool/format/d.py +++ b/scripts/tracetool/format/d.py @@ -33,6 +33,11 @@ def generate(events, backend, group): events = [e for e in events if "disable" not in e.properties] + # SystemTap's dtrace(1) warns about empty "provider qemu {}" but is happy + # with an empty file. Avoid the warning. + if not events: + return + out('/* This file is autogenerated by tracetool, do not edit. */' '', 'provider qemu {')