From nobody Sun May 5 18:08:09 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=1571392597; cv=none; d=zoho.com; s=zohoarc; b=EhZcgXrRdzZoVAO8s4E2j4WtC1N4kxiA1nXnlLqhoD2eL6fMjdW3vl1Y4S+GxflpYfQ3jwGBPb3nFO7YSfQYy9rLnlQBsjVha61dytl1pbdaC8WTEJljGPbXl6YwKGlPJZc6CYt9+9H023tC/zlXIiX272llY0DsyylbAvXA5F4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571392597; 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=A6yRxSH5dY171pt2zxqQcCafkdGqB0IzCbjdjFuO/XU=; b=adFJQTyoM2+dCibt8GNiLXInEXFR33Usvz7zL1AHKqX6i8fRvzMdxorkYNgTYBr+Zvx6r3gD3w4s5RAf/g4k5kwEQ14u6A2wEp3wmCfEeaNE6xBCOSbPnSFTGxW6tifqElcf9xJWNp/L7nvH4b/3Tr80FIzAvGVF7k4kQA2VZo0= 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 1571392596936314.9946392474542; Fri, 18 Oct 2019 02:56:36 -0700 (PDT) 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 0BD4E10CC1E6; Fri, 18 Oct 2019 09:56:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C514C600D1; Fri, 18 Oct 2019 09:56:34 +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 27D464E589; Fri, 18 Oct 2019 09:56:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9I9uWWS015769 for ; Fri, 18 Oct 2019 05:56:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id EC17960A97; Fri, 18 Oct 2019 09:56:32 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E666760852 for ; Fri, 18 Oct 2019 09:56:30 +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 92EF42A09BA for ; Fri, 18 Oct 2019 09:56:28 +0000 (UTC) Received: from mse-fl1.zte.com.cn (unknown [10.30.14.238]) by Forcepoint Email with ESMTPS id B1F6759D5D606B02DCDF for ; Fri, 18 Oct 2019 17:56:26 +0800 (CST) Received: from notes_smtp.zte.com.cn (notessmtp.zte.com.cn [10.30.1.239]) by mse-fl1.zte.com.cn with ESMTP id x9I9tVts024985 for ; Fri, 18 Oct 2019 17:55:31 +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 2019101817553938-21627 ; Fri, 18 Oct 2019 17:55:39 +0800 From: Wang Yechao To: libvir-list@redhat.com Date: Fri, 18 Oct 2019 17:55:10 +0800 Message-Id: <1571392510-17190-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-18 17:55:39, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2019-10-18 17:55:37, Serialize complete at 2019-10-18 17:55:37 X-MAIL: mse-fl1.zte.com.cn x9I9tVts024985 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.38]); Fri, 18 Oct 2019 09:56:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 18 Oct 2019 09:56:29 +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.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Wang Yechao Subject: [libvirt] [PATCH v5] util: Set SIGPIPE to a no-op handler in virFork 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.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Fri, 18 Oct 2019 09:56:35 +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 set SIGPIPE to a dummy no-op handler before unmask signals in virFork. And there is no need to set SIGPIPE ignored before running hooks in virExec. At last, set SIGPIPE to defaults before execve. Signed-off-by: Wang Yechao --- v3 patch: https://www.redhat.com/archives/libvir-list/2019-October/msg00934.html Changes in v4: - don't block SIGPIPE, ignore it when invoke VIR_FORCE_CLOSE and virComma= ndMassClose Changes in v5: - chang from SIG_IGN to a no-op handler in child process --- src/util/vircommand.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 93b3dd2..c13739c 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -217,6 +217,8 @@ virCommandFDSet(virCommandPtr cmd, =20 #ifndef WIN32 =20 +static void virDummyHandler(int sig G_GNUC_UNUSED) {} + /** * virFork: * @@ -312,6 +314,9 @@ virFork(void) ignore_value(sigaction(i, &sig_action, NULL)); } =20 + sig_action.sa_handler =3D virDummyHandler; + ignore_value(sigaction(SIGPIPE, &sig_action, NULL)); + /* Unmask all signals in child, since we've no idea what the * caller's done with their signal mask and don't want to * propagate that to children */ @@ -550,7 +555,7 @@ virExec(virCommandPtr cmd) g_autofree char *binarystr =3D NULL; const char *binary =3D NULL; int ret; - struct sigaction waxon, waxoff; + struct sigaction sig_action; g_autofree gid_t *groups =3D NULL; int ngroups; =20 @@ -718,21 +723,6 @@ virExec(virCommandPtr cmd) } } =20 - /* virFork reset all signal handlers to the defaults. - * This is good for the child process, but our hook - * risks running something that generates SIGPIPE, - * so we need to temporarily block that again - */ - 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 (virProcessSetMaxMemLock(0, cmd->maxMemLock) < 0) goto fork_error; if (virProcessSetMaxProcesses(0, cmd->maxProcesses) < 0) @@ -783,7 +773,10 @@ virExec(virCommandPtr cmd) if (virCommandHandshakeChild(cmd) < 0) goto fork_error; =20 - if (sigaction(SIGPIPE, &waxon, NULL) < 0) { + memset(&sig_action, 0, sizeof(sig_action)); + sig_action.sa_handler =3D SIG_DFL; + sigemptyset(&sig_action.sa_mask); + if (sigaction(SIGPIPE, &sig_action, NULL) < 0) { virReportSystemError(errno, "%s", _("Could not re-enable SIGPIPE")); goto fork_error; --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list