From nobody Wed Apr 24 13:02:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1573172591; cv=none; d=zoho.com; s=zohoarc; b=ih5alHfpytP/CpldCUOF4WHqV8NsnoCp9xWCJ9AF78Bzppms3V3hswzhGTibeBMVi4scxZabFkLBzaGTJ1WCjkCBOejVw/okX93+kQawLBdwGmaVjTlJJJQjpSoYNaFzRKxWLGzBwIuC4dJ3kO4rqv1+XacLx1UQVX45z71DGeU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573172591; 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=aIPjTMk5rGrrjxGZgSaphG6yBE2ZHyieA8wUnFoe+0w=; b=YMlg8FdA+5YA8nn/edFu4gdRnoozVgjfJBJ52yu3lWpxcIvp/XxSJwUB8o1rwN9sdXU6FAMbMJ1jIhon3W0T2t73QXv7LAkhUNAr4tO4dLECL3xta2pXi6JDNp1gOWGkDyxHslo0Gf62nPIRZGMEMr7Oq0UA30ZxoTSe7ybRXt0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1573172590562683.8064599992155; Thu, 7 Nov 2019 16:23:10 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-60-0YHS0bhsNoy3SQsQsrUWew-1; Thu, 07 Nov 2019 19:23:07 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4BC38017DE; Fri, 8 Nov 2019 00:22:59 +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 7C2B560BE2; Fri, 8 Nov 2019 00:22:58 +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 B1FD018089C8; Fri, 8 Nov 2019 00:22:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xA80Mr3l028463 for ; Thu, 7 Nov 2019 19:22:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id AA1693CCA; Fri, 8 Nov 2019 00:22:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx22.extmail.prod.ext.phx2.redhat.com [10.5.110.63]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A34FF19481 for ; Fri, 8 Nov 2019 00:22:50 +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 B665B18DA8A8 for ; Fri, 8 Nov 2019 00:22:48 +0000 (UTC) Received: from mse-fl2.zte.com.cn (unknown [10.30.14.239]) by Forcepoint Email with ESMTPS id 8A65A515CF2349D0B011 for ; Fri, 8 Nov 2019 08:22:46 +0800 (CST) Received: from notes_smtp.zte.com.cn (notes_smtp.zte.com.cn [10.30.1.239]) by mse-fl2.zte.com.cn with ESMTP id xA80MWUF043774 for ; Fri, 8 Nov 2019 08:22:32 +0800 (GMT-8) (envelope-from wang.yechao255@zte.com.cn) Received: from fox-host8.localdomain ([10.74.120.8]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2019110808230622-340644 ; Fri, 8 Nov 2019 08:23:06 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573172589; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=aIPjTMk5rGrrjxGZgSaphG6yBE2ZHyieA8wUnFoe+0w=; b=ZQIYpvVe7kynwclnlj2r1DBeig8yhZKYpk3tT+d6czvQprCDRWbPbmpRWg1Ma7jKumMMTF FKaAHou1WrQ6VSUMqD7fP7bUsvwPFrkjK/lMp+ScgQn448eehHQYF780fWcdsula7V8iaD QfsYumYlr3tNYv6mqWc2B7AqHRkmPxA= From: Wang Yechao To: libvir-list@redhat.com Date: Fri, 8 Nov 2019 08:25:15 +0800 Message-Id: <1573172715-15369-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-11-08 08:23:06, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2019-11-08 08:22:37, Serialize complete at 2019-11-08 08:22:37 X-MAIL: mse-fl2.zte.com.cn xA80MWUF043774 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 238 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Fri, 08 Nov 2019 00:22:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Fri, 08 Nov 2019 00:22:49 +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.63 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: wang.yi59@zte.com.cn, Wang Yechao , wang.liang82@zte.com.cn, xue.zhihong@zte.com.cn Subject: [libvirt] [PATCH v6] 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 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: 0YHS0bhsNoy3SQsQsrUWew-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 the handler will get reset to SIG_DFL when execve() runs. Now we can delete sigaction() call entirely in virExec(). 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 Changes in v6: - add a comment and delete sigaction() call entirely in virExec --- src/util/vircommand.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 93b3dd2..8b10253 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,14 @@ virFork(void) ignore_value(sigaction(i, &sig_action, NULL)); } =20 + /* Code that runs between fork & execve might trigger + * SIG_PIPE, so we must explicitly set that to a no-op + * handler. This handler will get reset to SIG_DFL when + * execve() runs + */ + 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 +560,6 @@ virExec(virCommandPtr cmd) g_autofree char *binarystr =3D NULL; const char *binary =3D NULL; int ret; - struct sigaction waxon, waxoff; g_autofree gid_t *groups =3D NULL; int ngroups; =20 @@ -718,21 +727,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,12 +777,6 @@ virExec(virCommandPtr cmd) if (virCommandHandshakeChild(cmd) < 0) goto fork_error; =20 - if (sigaction(SIGPIPE, &waxon, NULL) < 0) { - virReportSystemError(errno, "%s", - _("Could not re-enable SIGPIPE")); - goto fork_error; - } - /* Close logging again to ensure no FDs leak to child */ virLogReset(); =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list