LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "David Schwartz" <davids@webmaster.com>
To: "Linux-Kernel@Vger. Kernel. Org" <linux-kernel@vger.kernel.org>
Subject: RE: O_NONBLOCK setting "leak" outside of a process??
Date: Sun, 4 Feb 2007 13:08:36 -0800	[thread overview]
Message-ID: <MDEHLPKNGKAHNMBLJOLKEEOJBFAC.davids@webmaster.com> (raw)
In-Reply-To: <45C63DE9.7020800@tls.msk.ru>


> > *Every* blocking fd operation should be followed by a check to
> > see if the
> > operation failed, succeeded, or partially succeeded. If it partially
> > succeeded, it needs to be continued. If it failed, you need to
> > check if the
> > error is fatal or transient. If transient, you need to back off
> > and retry.
> > It has, sadly, always been this way. (Programs can get signals,
> > debuggers
> > can interrupt a system call, the unexpected happens.)

> Well, that's partly nonsense.  The only error condition which is
> always being
> checked in correctly written software is EINTR - if you've got an
> interrupt,
> continue/retry the I/O.

> Checking and retrying for EAGAIN is umm.. plain wrong.  You'll get a nice
> busywait eating 100% CPU this way, till the I/O actually happens, and will
> get another the next try.

I said back off and retry.

> Checking I/Os for every possible weird condition is just non-productive.
>
> It's like this:
>
>   if (fcntl(fd, F_SETFL, ~O_NONBLOCK) < 0)  error_out();
>   if (fcntl(fd, F_GETFL, 0) & O_NOBLOCK) ??? what to do?
>   while(do_something())
>     if (fcntl(fd, F_GETFL, 0) & O_NOBLOCK)
>       if (fcntl(fd, F_SETFL, ~O_NONBLOCK) < 0)  error_out();
>
> (don't pay attention to ~O_NONBLOCK thing - it's wrong, but it's
> used like that just to show the "idea" - which is to clear O_NONBLOCK)

I agree that checking for a condition that there's no sane way to handle is
non-productive. But here we're talking about testing for a condition that
has been proven to happen and for which a sane way to handle it is
obvious -- back off and retry.

> Which is a complete nonsense.  It's either set or cleared, and once
> set or cleared it should stay that way, period.  Until the app changes
> it again.

Until anything with access to it changes it.

> >> Worse, it cannot be worked around by dup() because duped fds
> >> are still sharing O_NONBLOCK. How can I work around this?
> >
> > If this causes your code a problem, your code is broken. What
> > does your code
>
> With dup() - maybe.  But definitely NOT with fork().

With 'fork', you either give the other process the file descriptor or you
share it. Any shared resource requires cooperation for sane results.

> > currently do if it gets a non-fatal error from a blocking
> > operation? If it
> > does anything other than back off and retry, it's mishandling
> > the condition.

> Retrying I/O in case of EAGAIN is *wrong*.  See above.

You missed the "back off" part.

DS



      reply	other threads:[~2007-02-04 21:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-27 20:52 Denis Vlasenko
2007-01-30  3:40 ` Philippe Troin
2007-02-01 23:00   ` Denis Vlasenko
2007-02-01 23:15     ` Philippe Troin
2007-02-02 12:10       ` Roland Kuhn
2007-02-02 13:48         ` Guillaume Chazarain
2007-02-02 15:04           ` Roland Kuhn
2007-02-02 18:59             ` Philippe Troin
2007-02-05 10:49               ` bert hubert
2007-02-04  0:55         ` David Schwartz
2007-02-04  1:22           ` Denis Vlasenko
2007-02-04  7:56             ` David Schwartz
2007-02-04 20:11               ` Michael Tokarev
2007-02-04 21:08                 ` David Schwartz [this message]

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=MDEHLPKNGKAHNMBLJOLKEEOJBFAC.davids@webmaster.com \
    --to=davids@webmaster.com \
    --cc=linux-kernel@vger.kernel.org \
    --subject='RE: O_NONBLOCK setting "leak" outside of a process??' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).