[PATCH] ash: clear NONBLOCK flag from stdin when in foreground

Rich Felker dalias at aerifal.cx
Wed Aug 17 23:50:07 UTC 2011


On Thu, Aug 18, 2011 at 12:45:57AM +0200, Laurent Bercot wrote:
>  Look at multitee: http://code.dogmap.org/fdtools/multitee/
>  Don't you agree that the *natural* way to write such a program would
> be an asynchronous loop? Yet, for the very same reason, the author
> jumped through hoops to avoid that. Doesn't that bother you ? It sure
> bothered him.

The natural way to write it is with poll. And that does not require
setting the nonblocking flag. The idea that you have to set O_NONBLOCK
for select/poll to be reliable is nonsense invented and promoted by
Linux kernel developers who refuse to fix their bugs or claim their
bugs are "performance features".

> > Irrelevant. gets is part of ISO C and POSIX/Unix defers to C.
> 
>  It did not have to. POSIX could have declared gets() insecure and not
> part of it, even though it belongs to ISO C. Somewhere, someone decided
> that it was acceptable to accept gets() into the standard. Enough said.

Nobody "decided" to accept/include gets. What was decided is the
general principle that POSIX is a superset of ISO/IEC 9899:1999, and
that in any areas where the two conflict, the conflict is
unintentional and the latter (C) overrides. This is very sane.

> > Instead try to understand why things are the way they are
> 
>  Please explain, then. I (and I'm not alone) have given plenty of
> reasons why the nonblocking flag should not be shared. I am still
> waiting for one argument in favor of sharing it - apart from "it's
> the standard, it's like this, it's always been like this, you have
> to follow it or you're stupid".

I'll admit it could just as easily have been non-shared (like the
close-on-exec flag, a property of the descriptor rather than the
description) and that may have been objectively "better", but the work
to "fix" it would involve making a duplicate flag, adding complexity,
and having it not be portable for many years to come. Since O_NONBLOCK
is *largely useless* (if you use select/poll right and your OS is not
buggy), it's really a non-issue.

> > and just stop insisting on doing stupid things (like setting
> > nonblocking mode on a fd you inherited).
> 
>  I'm insisting on the Unix flexibility. I'm insisting that multitee
> should be writable as an asynchronous program. I'm insisting that
> things should not break if for some reason some program sets a
> nonblocking flag somewhere; if a fcntl() call after every command
> in ash is what it takes to avoid random breakage, then it should be
> done. I'm insisting that you should stop having so much (blind) respect
> for what is Standard, and start thinking about what is Right instead.

What is Standard is what's Right. It's that simple. If you start
trying to "correct" the standard, all you end up with is conflicting
behavior - now portable programs cannot assume either the "Standard"
behavior or the "Right" behavior, so they have to be written with even
more generality and become more klunky and fragile. That road takes
you to the land of autoconf and gnulib....

Rich


More information about the busybox mailing list