Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp68181ybg; Tue, 2 Jun 2020 16:43:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+8o1wLwPwVu/hBpAUD7i4Nz3AzGjqC+bBYk3sIg8nd5diSRCJ0WIY4X5+cLPBVXCNfuuF X-Received: by 2002:a17:906:be2:: with SMTP id z2mr24687950ejg.169.1591141387343; Tue, 02 Jun 2020 16:43:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591141387; cv=none; d=google.com; s=arc-20160816; b=Eiggn9m4FvJT5kOTF5kXGsDWDdlepU9xY8ZUy+OnIURc9qYlfBXzpTG5gNDX55HXfc yx1+TMS7ZNfIcIr6Uqu3iOwa4yScZocIpLaR14rOF8CoBn3HBP6XWlqwMwUvqaNGojUQ LIck+m8ze7nz51ZFP6OdSgDooJdYuVHE0ecOdfYgfvVhVmaEx/gYT735Vj2v/NOqGXT6 FGg/zr7YqPW7No2nQJ0WDFk84aGUmBsIvFWMQ5KRomsRmKQdzfaAMKZcJGc67lACc4VU 7+wXHzklA5WF2KFgbLmPDTssqjjam+9WtXtSbNdRIGsRZLfTPjqpP7yFVrWMEsHvLALK z6Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=zmx5PWxb+goUSCW7tSqCHepWWAHOYHcV2lMAeqCKqQk=; b=O5hNOac7ZVTUGZY5fs93iFZo5Uluq669VZMedPscyvaRfqZebAv83pn+QwPTJVPiL7 yI4q8as91NPsAwLGVwUE2FNkQ7d2HqAtBP3O/kdAInU8rahzA77PFLJ62ZmO379Puico GeZgSFCvd4DafBycEcQ/LWsl+p+ShwEwHMme8A/a9X726qwVkdMb/3Y9duYnLdfPBcTl bKNNCo/aZgnG0PgTUiolb9N9vOKB/7soj9vV+bQdrXO2J9I/qtJrPlCXFCGW5XKyIzF+ VAMW97m+DGgDudLJhTdCSGcvtRhOAVCrqJcCqIi3DU8N1lJA5vlZ8N5CWXLWFyXPC6Hw Osxw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 63si140105edn.276.2020.06.02.16.42.37; Tue, 02 Jun 2020 16:43:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728254AbgFBXhy (ORCPT + 99 others); Tue, 2 Jun 2020 19:37:54 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:54659 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726223AbgFBXhx (ORCPT ); Tue, 2 Jun 2020 19:37:53 -0400 Received: from ip5f5af183.dynamic.kabel-deutschland.de ([95.90.241.131] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jgGTe-000281-Ps; Tue, 02 Jun 2020 23:37:50 +0000 Date: Wed, 3 Jun 2020 01:37:49 +0200 From: Christian Brauner To: Florian Weimer Cc: torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, Kyle Evans , Victor Stinner , viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, fweimer@redhat.com, jannh@google.com, oleg@redhat.com, arnd@arndb.de, shuah@kernel.org, dhowells@redhat.com, ldv@altlinux.org Subject: Re: [PATCH v5 1/3] open: add close_range() Message-ID: <20200602233749.mo65o2enokiypwiz@wittgenstein> References: <20200602204219.186620-1-christian.brauner@ubuntu.com> <20200602204219.186620-2-christian.brauner@ubuntu.com> <87d06hdozy.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <87d06hdozy.fsf@mid.deneb.enyo.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 03, 2020 at 01:30:57AM +0200, Florian Weimer wrote: > * Christian Brauner: > > > The performance is striking. For good measure, comparing the following > > simple close_all_fds() userspace implementation that is essentially just > > glibc's version in [6]: > > > > static int close_all_fds(void) > > { > > int dir_fd; > > DIR *dir; > > struct dirent *direntp; > > > > dir = opendir("/proc/self/fd"); > > if (!dir) > > return -1; > > dir_fd = dirfd(dir); > > while ((direntp = readdir(dir))) { > > int fd; > > if (strcmp(direntp->d_name, ".") == 0) > > continue; > > if (strcmp(direntp->d_name, "..") == 0) > > continue; > > fd = atoi(direntp->d_name); > > if (fd == dir_fd || fd == 0 || fd == 1 || fd == 2) > > continue; > > close(fd); > > } > > closedir(dir); > > return 0; > > } > > > > > [6]: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/grantpt.c;h=2030e07fa6e652aac32c775b8c6e005844c3c4eb;hb=HEAD#l17 > > Note that this is an internal implementation that is not exported. > > Currently, libc seems to not provide an exported version of this > > because of missing kernel support to do this. > > Just to be clear, this code is not compiled into glibc anymore in > typical configurations. I have posted a patch to turn grantpt into a > no-op: That's great! (I remember commenting on that thread.)