Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1iRv1k-00085t-TN for mharc-grub-devel@gnu.org; Tue, 05 Nov 2019 04:21:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45224) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iRv1i-00080w-7k for grub-devel@gnu.org; Tue, 05 Nov 2019 04:21:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iRv1g-0005zX-QJ for grub-devel@gnu.org; Tue, 05 Nov 2019 04:21:26 -0500 Received: from m4a0041g.houston.softwaregrp.com ([15.124.2.87]:55364) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1iRv1g-0005zD-JE for grub-devel@gnu.org; Tue, 05 Nov 2019 04:21:24 -0500 Received: FROM m4a0041g.houston.softwaregrp.com (15.120.17.146) BY m4a0041g.houston.softwaregrp.com WITH ESMTP FOR grub-devel@gnu.org; Tue, 5 Nov 2019 09:20:30 +0000 Received: from M4W0334.microfocus.com (2002:f78:1192::f78:1192) by M4W0334.microfocus.com (2002:f78:1192::f78:1192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Tue, 5 Nov 2019 09:19:28 +0000 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (15.124.8.12) by M4W0334.microfocus.com (15.120.17.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10 via Frontend Transport; Tue, 5 Nov 2019 09:19:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C+V60g4aYuISObyRSqZ6fpM8hRFEYCQX33RpLo1F5ed99tGhyipKhhKiRsTjKY6QLWbTDVQbMgyPlInQoT82ZhYciWL7nCAV7/4jgRzezmTLyBameceHc4ze6FlorC6YxXnfGBjPd6f2nUwsP7nCMTB2teCxOcwWu4gwhz31xDh/GzqTCt55CXKYWOQ1hrNQgMU38H/xk1JEZPlh0sAZtbESuORjk15vzZCsLZNmco8vHT7G8k8Q10yos/4HgaMD8A3efSO0NRDa2qZ/WI1xTECByVSsQ04VuLwCgr3gTdSt5QhxYVA0c17INA3vX72NmhQ1IfFbguGQ4NIcqCaptA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VC4kWKzl5KrcoNS9Qx5POgahAupx45aBMuCTnhGENCc=; b=h6wVziTQTTlXbAbNl6tr1cRGsNwhdb5of3udoyyS8/yACJnc2cTm+chpTmL5KSromZ90MTPH16ClFXqgZdq6xLUqhw7T/nFkzbcsKnuuln5OD35v8WWX+MLrYqOVmHFmQGwfy6rRhzUZDshHlW3rC7HrYe3mmN4Q+UpCR3m6FG8dBpYP54/FYoFWmV7bMDFaFAPhPKH1nwyH6I4q4OYkXv/o/fT8jucugjMgAgcDCYeC9N9HB2yJhmXKVN8u5nsoa6eL9eXJ0qbj/THn0A9xjK+tMWU4zRmvC0BCKzu3x4xdTY8spDv8g7Le2ZoCigFGHzW8SzP6Ku6G9+qSaBeinQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Received: from BY5PR18MB3122.namprd18.prod.outlook.com (10.255.139.11) by BY5PR18MB3249.namprd18.prod.outlook.com (10.255.138.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2430.20; Tue, 5 Nov 2019 09:19:26 +0000 Received: from BY5PR18MB3122.namprd18.prod.outlook.com ([fe80::297d:fc41:ae2a:13d9]) by BY5PR18MB3122.namprd18.prod.outlook.com ([fe80::297d:fc41:ae2a:13d9%5]) with mapi id 15.20.2408.024; Tue, 5 Nov 2019 09:19:26 +0000 From: Michael Chang To: "grub-devel@gnu.org" Subject: [PATCH] set linux file descriptor to O_CLOEXEC as default Thread-Topic: [PATCH] set linux file descriptor to O_CLOEXEC as default Thread-Index: AQHVk7oeBhWL7D/Wf0q5hZaUDMDM0g== Date: Tue, 5 Nov 2019 09:19:26 +0000 Message-ID: <20191105091915.29462-1-mchang@suse.com> Accept-Language: zh-TW, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HK2PR06CA0021.apcprd06.prod.outlook.com (2603:1096:202:2e::33) To BY5PR18MB3122.namprd18.prod.outlook.com (2603:10b6:a03:1af::11) authentication-results: spf=none (sender IP is ) smtp.mailfrom=MChang@suse.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.16.4 x-originating-ip: [60.251.47.116] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: f62ba180-ec2d-48e3-969d-08d761d140ee x-ms-traffictypediagnostic: BY5PR18MB3249: x-ms-exchange-purlcount: 1 x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 0212BDE3BE x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(396003)(39860400002)(376002)(136003)(366004)(346002)(199004)(189003)(99286004)(66066001)(66476007)(25786009)(66946007)(5660300002)(50226002)(52116002)(71200400001)(8936002)(71190400001)(316002)(305945005)(7736002)(2906002)(256004)(14454004)(8676002)(14444005)(81166006)(966005)(6486002)(5640700003)(81156014)(6916009)(486006)(66556008)(2351001)(6436002)(2501003)(1076003)(186003)(66446008)(6512007)(55236004)(36756003)(80792005)(86362001)(102836004)(6506007)(386003)(26005)(6306002)(64756008)(478600001)(476003)(2616005)(6116002)(3846002); DIR:OUT; SFP:1102; SCL:1; SRVR:BY5PR18MB3249; H:BY5PR18MB3122.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: suse.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ivI8qj73OnhooxIFqY70kMPszSy18zcgeF374G+vAL/iULEgSp/ZHBoXq1+OJM4jQE60EU3aLYXwuuksWqHP06AFIPmjmtRY7Rwqmky4XcoLogczhQ9ZLG69Uo2+woB1kGv/TkvYrq1rkJS5EQL0FEPO4Wpls8JwDZQOJv7mefA1/G49XvUUULD963R4BN+KK3TNbr5TXXVtMadXly2AvkEypVWESsP6sYIAplyATTsK9wO8ni7q4m+Xz7GMPovEGmq3dqOmAz6yA94W82f8BmArmv8TgouD2GZR3TDhzD8kwwUTTeQ65iiapuZGslSxcwLP9wxWRxa+/LojIO5q6dJAFFaxiFoNOCuLZmuIIyHJKpM4sFtYSDyHVbfQQivt4BnCP3Thgp4Vs64Jxy6J/gK0w+Vkf5lcuIbjBdtwbztdZcghGlDDXNtYVAMrMW1ve6GOFoSX9ksXqlQ4T4Pky8KRfqpoKUgPz+LSuIK+S7c= x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: f62ba180-ec2d-48e3-969d-08d761d140ee X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2019 09:19:26.3940 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 856b813c-16e5-49a5-85ec-6f081e13b527 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: BrfDwWh0DpQTpEHRcjgrLNnG68MJGNlMYCH3gomIfoOrbQsvwrSHpDcrLSYS9F/W X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR18MB3249 X-OriginatorOrg: suse.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 15.124.2.87 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Nov 2019 09:21:28 -0000 We are often bothered by this sort of lvm warning while running grub-instal= l or grub-install every now and then. File descriptor 4 (/dev/vda1) leaked on vgs invocation. Parent PID 1991: /u= sr/sbin/grub2-install The requirement related to the warning is dictated in the lvm man page. "On invocation, lvm requires that only the standard file descriptors stdin, stdout and stderr are available. If others are found, they get closed and messages are issued warning about the leak. This warning can be suppressed= by setting the environment variable LVM_SUPPRESS_FD_WARNINGS." While it coulde be disabled through settings, most linux distributions seem= to enable it by default and the justification provided by the developer looks = to be valid to me. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=3D466138#15 Rather than trying to close and reopen the file descriptor to the same file multiple times, which is rather cumbersome, for the sake of no vgs invocati= on could happen in between. This patch enables the close-on-exec flag (O_CLOEX= EC) for new file descriptor returned by the open() system call, making it close= d thus not inherited by the child process forked and executed by the exec() family of functions. Signed-off-by: Michael Chang --- grub-core/osdep/linux/hostdisk.c | 3 +++ grub-core/osdep/unix/hostdisk.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostd= isk.c index 8b92f8528..da62f924e 100644 --- a/grub-core/osdep/linux/hostdisk.c +++ b/grub-core/osdep/linux/hostdisk.c @@ -366,6 +366,9 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_= disk_addr_t sector, int f #ifdef O_BINARY flags |=3D O_BINARY; #endif +#ifdef O_CLOEXEC + flags |=3D O_CLOEXEC; +#endif =20 /* Linux has a bug that the disk cache for a whole disk is not consisten= t with the one for a partition of the disk. */ diff --git a/grub-core/osdep/unix/hostdisk.c b/grub-core/osdep/unix/hostdis= k.c index 91150969b..3a00d7451 100644 --- a/grub-core/osdep/unix/hostdisk.c +++ b/grub-core/osdep/unix/hostdisk.c @@ -164,6 +164,9 @@ grub_util_fd_open (const char *os_dev, int flags) #ifdef O_BINARY flags |=3D O_BINARY; #endif +#ifdef O_CLOEXEC + flags |=3D O_CLOEXEC; +#endif =20 return open (os_dev, flags, S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR); } --=20 2.16.4