From nobody Sat Apr 27 08:16:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571212322; cv=none; d=zoho.com; s=zohoarc; b=lZvmwUumJmSid+J/sGds5/NEtMdyDQ06iFkFXSRIowcfoa9EGCbAEyr/u50gV3Z5e08L1m2SWShat8v12YFEh7ip8jiw58L6/gGPey0P/LYsvE077nDCQ8Aw8ipHI2e2vc2bziSdRnn51NsXZCVQHAnamB+yzHCBsxreMQD4nTM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571212322; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=jLiKaEnl8XpJm1w9BWZ6omd5P/+497IrzKOa3w265sM=; b=FxgG4dZxsGXH1N1TIYJv+ZS8C5aywdlLNK/3ZyPBvof2lEVuPeDlegRVMIJq3xfk6JQoL0Dj6F7n0Ehev8qhcqV/J7e80PRxAOOnxP7kfMMHO8A23jLXkSZc2cY7bqQlAJptqzA/2c7dkDsjue9KC49rq8UzksZnsmK3kupl8Yc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 157121232231750.57920704242895; Wed, 16 Oct 2019 00:52:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E82FFC0578F4; Wed, 16 Oct 2019 07:51:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EFE70100194E; Wed, 16 Oct 2019 07:51:55 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C2133180B536; Wed, 16 Oct 2019 07:51:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9G7mEBn006773 for ; Wed, 16 Oct 2019 03:48:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3D0305C1D6; Wed, 16 Oct 2019 07:48:14 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 376635C1B5 for ; Wed, 16 Oct 2019 07:48:11 +0000 (UTC) Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.217.80.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ACDE23167E57 for ; Wed, 16 Oct 2019 07:48:04 +0000 (UTC) Received: from mse-fl2.zte.com.cn (unknown [10.30.14.239]) by Forcepoint Email with ESMTPS id 16E973BF2685B8CD7497 for ; Wed, 16 Oct 2019 15:48:03 +0800 (CST) Received: from notes_smtp.zte.com.cn (notessmtp.zte.com.cn [10.30.1.239]) by mse-fl2.zte.com.cn with ESMTP id x9G7lW5w075493 for ; Wed, 16 Oct 2019 15:47:32 +0800 (GMT-8) (envelope-from wang.yechao255@zte.com.cn) Received: from kvm-146.localdomain ([10.74.120.146]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2019101615475250-59224 ; Wed, 16 Oct 2019 15:47:52 +0800 From: Wang Yechao To: libvir-list@redhat.com Date: Wed, 16 Oct 2019 15:47:18 +0800 Message-Id: <1571212038-4291-1-git-send-email-wang.yechao255@zte.com.cn> X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2019-10-16 15:47:52, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2019-10-16 15:47:35, Serialize complete at 2019-10-16 15:47:35 X-MAIL: mse-fl2.zte.com.cn x9G7lW5w075493 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 238 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 16 Oct 2019 07:48:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 16 Oct 2019 07:48:04 +0000 (UTC) for IP:'63.217.80.70' DOMAIN:'mxhk.zte.com.cn' HELO:'mxhk.zte.com.cn' FROM:'wang.yechao255@zte.com.cn' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 63.217.80.70 mxhk.zte.com.cn 63.217.80.70 mxhk.zte.com.cn X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Wang Yechao Subject: [libvirt] [PATCH v4] util: Ignore SIGPIPE before write logs to stderr in child process X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 16 Oct 2019 07:52:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Libvirtd has set SIGPIPE to ignored, and virFork resets all signal handlers to the defaults. But child process may write logs to stderr/stdout, that may generate SIGPIPE if journald has stopped. So in virExec(), set SIGPIPE to ignored before invoke virCommandMassClose, and revert it back to SIG_DFL after that. In virProcessRunInFork(), just set SIGPIPE to ignored. Signed-off-by: Wang Yechao --- v1 patch: https://www.redhat.com/archives/libvir-list/2019-October/msg00720.html Changes in v2: - use pthread_sigmask to block SIGPIPE Changes in v3: - pass SIG_UNBLOCK(not SIG_SETMASK) to pthread_sigmask when unlock SIGPIPE Changes in v4: - don't block SIGPIPE, ignore it when invoke VIR_FORCE_CLOSE and virComma= ndMassClose --- src/util/vircommand.c | 16 ++++++++++++++++ src/util/virprocess.c | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 763bcb6..bb6e73b 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -653,9 +653,25 @@ virExec(virCommandPtr cmd) umask(cmd->mask); ret =3D EXIT_CANCELED; =20 + memset(&waxoff, 0, sizeof(waxoff)); + waxoff.sa_handler =3D SIG_IGN; + sigemptyset(&waxoff.sa_mask); + memset(&waxon, 0, sizeof(waxon)); + if (sigaction(SIGPIPE, &waxoff, &waxon) < 0) { + virReportSystemError(errno, "%s", + _("Could not disable SIGPIPE")); + goto fork_error; + } + if (virCommandMassClose(cmd, childin, childout, childerr) < 0) goto fork_error; =20 + if (sigaction(SIGPIPE, &waxon, NULL) < 0) { + virReportSystemError(errno, "%s", + _("Could not re-enable SIGPIPE")); + goto fork_error; + } + if (prepareStdFd(childin, STDIN_FILENO) < 0) { virReportSystemError(errno, "%s", _("failed to setup stdin file handle")); diff --git a/src/util/virprocess.c b/src/util/virprocess.c index e8d4ba0..da66dcf 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1151,6 +1151,16 @@ virProcessRunInFork(virProcessForkCallback cb, goto cleanup; =20 if (child =3D=3D 0) { + struct sigaction waxoff; + + memset(&waxoff, 0, sizeof(waxoff)); + waxoff.sa_handler =3D SIG_IGN; + sigemptyset(&waxoff.sa_mask); + if (sigaction(SIGPIPE, &waxoff, NULL) < 0) { + virReportSystemError(errno, "%s", + _("Could not disable SIGPIPE")); + } + VIR_FORCE_CLOSE(errfd[0]); ret =3D virProcessRunInForkHelper(errfd[1], parent, cb, opaque); VIR_FORCE_CLOSE(errfd[1]); --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list