All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Christian Brauner <christian@brauner.io>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-api@vger.kernel.org
Subject: Re: [PATCH 1/2] open: add close_range()
Date: Tue, 21 May 2019 15:39:53 +0200	[thread overview]
Message-ID: <82d34133-e174-efc3-48ed-332304028595@rasmusvillemoes.dk> (raw)
In-Reply-To: <20190521113448.20654-1-christian@brauner.io>

On 21/05/2019 13.34, Christian Brauner wrote:

> 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)
> {
>         DIR *dir;
>         struct dirent *direntp;
> 
>         dir = opendir("/proc/self/fd");
>         if (!dir)
>                 return -1;
> 
>         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 == 0 || fd == 1 || fd == 2)
>                         continue;
>                 close(fd);
>         }
> 
>         closedir(dir); /* cannot fail */
>         return 0;
> }

Before anybody copy-pastes this, please note that it lacks a check for
fd == dirfd(dir). If all of /proc/self/fd is returned in the first
getdents() syscall one won't notice, but...

Rasmus

  parent reply	other threads:[~2019-05-21 13:39 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-21 11:34 [PATCH 1/2] open: add close_range() Christian Brauner
2019-05-21 11:34 ` Christian Brauner
2019-05-21 11:34 ` Christian Brauner
2019-05-21 11:34 ` Christian Brauner
2019-05-21 11:34 ` Christian Brauner
2019-05-21 11:34 ` Christian Brauner
2019-05-21 11:34 ` christian
2019-05-21 11:34 ` Christian Brauner
2019-05-21 11:34 ` [PATCH 2/2] tests: add close_range() tests Christian Brauner
2019-05-21 11:34   ` Christian Brauner
2019-05-21 11:34   ` Christian Brauner
2019-05-21 11:34   ` Christian Brauner
2019-05-21 11:34   ` christian
2019-05-21 11:34   ` Christian Brauner
2019-05-21 12:09 ` [PATCH 1/2] open: add close_range() Florian Weimer
2019-05-21 12:09   ` Florian Weimer
2019-05-21 12:09   ` Florian Weimer
2019-05-21 12:09   ` Florian Weimer
2019-05-21 12:09   ` Florian Weimer
2019-05-21 12:09   ` fweimer
2019-05-21 12:09   ` Florian Weimer
2019-05-21 13:04   ` Christian Brauner
2019-05-21 13:04     ` Christian Brauner
2019-05-21 13:04     ` Christian Brauner
2019-05-21 13:04     ` Christian Brauner
2019-05-21 13:04     ` Christian Brauner
2019-05-21 13:04     ` christian
2019-05-21 13:04     ` Christian Brauner
2019-05-21 13:10     ` Florian Weimer
2019-05-21 13:10       ` Florian Weimer
2019-05-21 13:10       ` Florian Weimer
2019-05-21 13:10       ` Florian Weimer
2019-05-21 13:10       ` fweimer
2019-05-21 13:10       ` Florian Weimer
2019-05-21 13:18       ` Christian Brauner
2019-05-21 13:18         ` Christian Brauner
2019-05-21 13:18         ` Christian Brauner
2019-05-21 13:18         ` Christian Brauner
2019-05-21 13:18         ` christian
2019-05-21 13:18         ` Christian Brauner
2019-05-21 13:23       ` Christian Brauner
2019-05-21 13:23         ` Christian Brauner
2019-05-21 13:23         ` Christian Brauner
2019-05-21 13:23         ` christian
2019-05-21 13:23         ` Christian Brauner
2019-05-21 13:23         ` Christian Brauner
2019-05-21 13:07 ` Marc Gonzalez
2019-05-21 13:12   ` Christian Brauner
2019-05-21 13:39 ` Rasmus Villemoes [this message]
2019-05-21 15:00 ` Al Viro
2019-05-21 15:00   ` Al Viro
2019-05-21 15:00   ` Al Viro
2019-05-21 15:00   ` Al Viro
2019-05-21 15:00   ` viro
2019-05-21 15:00   ` Al Viro
2019-05-21 16:53   ` Christian Brauner
2019-05-21 16:53     ` Christian Brauner
2019-05-21 16:53     ` Christian Brauner
2019-05-21 16:53     ` Christian Brauner
2019-05-21 16:53     ` christian
2019-05-21 16:53     ` Christian Brauner
2019-05-21 16:30 ` David Howells
2019-05-21 16:30   ` David Howells
2019-05-21 16:30   ` David Howells
2019-05-21 16:30   ` David Howells
2019-05-21 16:30   ` dhowells
2019-05-21 16:30   ` David Howells
2019-05-21 16:41   ` Christian Brauner
2019-05-21 16:41     ` Christian Brauner
2019-05-21 16:41     ` Christian Brauner
2019-05-21 16:41     ` Christian Brauner
2019-05-21 16:41     ` christian
2019-05-21 16:41     ` Christian Brauner
2019-05-21 20:23     ` Linus Torvalds
2019-05-21 20:23       ` Linus Torvalds
2019-05-21 20:23       ` Linus Torvalds
2019-05-21 20:23       ` Linus Torvalds
2019-05-21 20:23       ` Linus Torvalds
2019-05-21 20:23       ` torvalds
2019-05-21 20:23       ` Linus Torvalds
2019-05-21 20:23       ` Linus Torvalds
2019-05-22  8:12       ` Christian Brauner
2019-05-22  8:12         ` Christian Brauner
2019-05-22  8:12         ` Christian Brauner
2019-05-22  8:12         ` Christian Brauner
2019-05-22  8:12         ` Christian Brauner
2019-05-22  8:12         ` Christian Brauner
2019-05-22  8:12         ` christian
2019-05-22  8:12         ` Christian Brauner
2019-05-21 19:20   ` Al Viro
2019-05-21 19:20     ` Al Viro
2019-05-21 19:20     ` Al Viro
2019-05-21 19:20     ` Al Viro
2019-05-21 19:20     ` viro
2019-05-21 19:20     ` Al Viro
2019-05-21 19:59     ` Matthew Wilcox
2019-05-21 19:59       ` Matthew Wilcox
2019-05-21 19:59       ` Matthew Wilcox
2019-05-21 19:59       ` willy
2019-05-21 19:59       ` Matthew Wilcox
2019-05-21 19:59       ` Matthew Wilcox
2019-05-24 20:32 ` Michael Tirado

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=82d34133-e174-efc3-48ed-332304028595@rasmusvillemoes.dk \
    --to=linux@rasmusvillemoes.dk \
    --cc=christian@brauner.io \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.