From: Davide Libenzi <davidel@xmailserver.org>
To: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Ulrich Drepper <drepper@redhat.com>,
linux-kernel@vger.kernel.org, akpm@linux-foundation.org
Subject: Re: F_DUPFD_CLOEXEC implementation
Date: Sun, 30 Sep 2007 16:11:32 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0709301605340.19355@alien.or.mcafeemobile.com> (raw)
In-Reply-To: <200709300131.49320.vda.linux@googlemail.com>
On Sun, 30 Sep 2007, Denys Vlasenko wrote:
> Hi Ulrich,
>
> On Friday 28 September 2007 18:34, Ulrich Drepper wrote:
> > One more small change to extend the availability of creation of
> > file descriptors with FD_CLOEXEC set. Adding a new command to
> > fcntl() requires no new system call and the overall impact on
> > code size if minimal.
>
> Tangential question: do you have any idea how userspace can
> safely do nonblocking read or write on a potentially-shared fd?
>
> IIUC, currently it cannot be done without races:
>
> old_flags = fcntl(fd, F_GETFL);
> ...other process may change flags!...
> fcntl(fd, F_SETFL, old_flags | O_NONBLOCK);
> read(fd, ...)
> ...other process may see flags changed under its feet!...
> fcntl(fd, F_SETFL, old_flags);
>
> Can this be fixed?
I'm not sure I understood correctly your use case. But, if you have two
processes/threads randomly switching O_NONBLOCK on/off, your problems
arise not only the F_SETFL time.
If one of the tasks is not expecting an fd to be O_NONBLOCK, that will
likely end up not handling correctly read/write-miss situations.
In that case it'd be better to keep the fd as O_NONBLOCK, and manually
create blocking behaviour (when needed) with poll+read/write.
- Davide
next prev parent reply other threads:[~2007-09-30 23:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-28 17:34 Ulrich Drepper
2007-09-28 18:19 ` Davide Libenzi
2007-09-28 18:23 ` Ulrich Drepper
2007-09-30 0:31 ` Denys Vlasenko
2007-09-30 23:11 ` Davide Libenzi [this message]
2007-09-30 23:58 ` Denys Vlasenko
2007-10-01 3:15 ` Davide Libenzi
2007-10-01 10:07 ` Denys Vlasenko
2007-10-01 18:16 ` Al Viro
2007-10-01 18:49 ` Denys Vlasenko
2007-10-01 19:04 ` Davide Libenzi
2007-10-02 9:28 ` Denys Vlasenko
2007-10-02 19:52 ` Davide Libenzi
2007-10-01 18:53 ` Michael Tokarev
2007-10-01 0:59 ` Miquel van Smoorenburg
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=Pine.LNX.4.64.0709301605340.19355@alien.or.mcafeemobile.com \
--to=davidel@xmailserver.org \
--cc=akpm@linux-foundation.org \
--cc=drepper@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=vda.linux@googlemail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®