From patchwork Fri Feb 26 10:59:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hubert Jasudowicz X-Patchwork-Id: 12106465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D701CC433E0 for ; Fri, 26 Feb 2021 10:59:54 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5EC2064E4B for ; Fri, 26 Feb 2021 10:59:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5EC2064E4B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cert.pl Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.90229.170762 (Exim 4.92) (envelope-from ) id 1lFaqY-0003va-4z; Fri, 26 Feb 2021 10:59:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 90229.170762; Fri, 26 Feb 2021 10:59:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lFaqY-0003vT-1m; Fri, 26 Feb 2021 10:59:46 +0000 Received: by outflank-mailman (input) for mailman id 90229; Fri, 26 Feb 2021 10:59:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lFaqW-0003rd-SC for xen-devel@lists.xenproject.org; Fri, 26 Feb 2021 10:59:44 +0000 Received: from mx.nask.net.pl (unknown [195.187.55.89]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id fa822b0b-cb6d-4cd6-bd58-8919d5d719ee; Fri, 26 Feb 2021 10:59:40 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: fa822b0b-cb6d-4cd6-bd58-8919d5d719ee From: Hubert Jasudowicz To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Wei Liu , =?utf-8?q?Micha?= =?utf-8?q?=C5=82_Leszczy=C5=84ski?= Subject: [PATCH] tools: Improve signal handling in xen-vmtrace Date: Fri, 26 Feb 2021 11:59:26 +0100 Message-Id: <26720bf5c8258e1b7b4600af3648039b5b9ee18d.1614336820.git.hubert.jasudowicz@cert.pl> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Make sure xen-vmtrace exits cleanly in case SIGPIPE is sent. This can happen when piping the output to some other program. Additionaly, add volatile qualifier to interrupted flag to avoid it being optimized away by the compiler. Signed-off-by: Hubert Jasudowicz --- tools/misc/xen-vmtrace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/misc/xen-vmtrace.c b/tools/misc/xen-vmtrace.c index 7572e880c5..e2da043058 100644 --- a/tools/misc/xen-vmtrace.c +++ b/tools/misc/xen-vmtrace.c @@ -43,7 +43,7 @@ static uint32_t domid, vcpu; static size_t size; static char *buf; -static sig_atomic_t interrupted; +static volatile sig_atomic_t interrupted; static void int_handler(int signum) { interrupted = 1; @@ -81,6 +81,9 @@ int main(int argc, char **argv) if ( signal(SIGINT, int_handler) == SIG_ERR ) err(1, "Failed to register signal handler\n"); + if ( signal(SIGPIPE, int_handler) == SIG_ERR ) + err(1, "Failed to register signal handler\n"); + if ( argc != 3 ) { fprintf(stderr, "Usage: %s \n", argv[0]);