Re: perror() changes the orientation of stderr to byte-oriented mode if stderr is not oriented yet.

Corinna Vinschen <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
On Jul  2 10:40, Brian Inglis wrote:
> On 2018-07-02 09:46, Craig Howland wrote:
> > On 07/02/2018 07:36 AM, Eric Blake wrote:
> >> On 07/02/2018 05:28 AM, Corinna Vinschen wrote:
> >>>> By the way, I have noticed that psignal() and psiginfo() also have the
> >>>> same problem. psignal() belongs to newlib, so the same strategy can
> >>>> be applied. However, what can we do for psiginfo()? Only the FreeBSD
> >>>> route may be the answer...
> >>> I guess the simplest solution is to use the FreeBSD/OpenBSD method
> >>> all the time.
> >> If nothing else, it at least would mean fewer variations in practice,
> >> regardless of whether POSIX is changed to relax things (the POSIX discussion
> >> has been started, but it may be a while before any conclusion is reached;
> >> what's more, the C99 standard tried to address it in TC2
> >> (http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_276.htm) but then withdrew
> >> that in TC3 because the attempted resolution conflicted with the POSIX wording
> >> (http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_322.htm).
> >      To make it explicit, as looking back in the thread I don't see it stated
> > directly:  The FreeBSD/OpenBSD method is for perror()/psignal()/psiginfo() to
> > use write() to the stderr file number.  Supporting this as perhaps a good way to
> > go, the discussion thread on POSIX has pointed out that "the historic [perror()]
> > implementation calls write(2) to STDERR_FILENO."
> >      This sounds like a good solution for newlib from the points of view of 1)
> > staying small and uncomplicated, 2) producing behavior consistent with
> > historical systems, 3) not changing the stream orientation.  If does have a
> > potential drawback of possibly changing behavior since it would effectively mix
> > stream and write output from the application level whereas now it is only
> > stream.  On the other hand, since perror() does print a complete line, the
> > behavior should not change if the stream is either unbuffered or line buffered,
> > but could be different only if fully buffered.  However, the since stderr
> > default "is not fully buffered", the number of applications affected would
> > probably be in the minority.  (A subjective statement, but I expect it would be
> > very hard to quantify.)
> > [...]
> 
> DR 322 says:
> "Committee Discussion (for history only)
> 
> The Committee discussed making the behavior undefined, which would allow
> perror() to fail if the stream orientation has already been set to wide.
> 
> The proposed TC will permit (but not require) perror to set the orientation of
> an un-oriented stderr to narrow, and has what C calls undefined behavior if
> stderr was previously set to wide. This permits the POSIX required behavior."

I'm not overly sympathetic with this approach.  It opens up the standard
in a way which basically means, we allow any existing implementation to
claim standard compliance.

The side-effect is that now applications may have to worry about the 
orientation when usingg perror, not quite as, but similar to the
description in http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_322.htm
I'd rather see a better defense of the "don't change orientation".

Either way, to be on the safe side I think we should really do what
FreeBSD/OpenBSD (and Linux, just differently) are doing.

All interested parties ok with that?  If so, I think Takashi's patch can
go in.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAls7eHAACgkQ9TYGna5E
T6BbYQ//YYFfHnRMN2DGAoJg17vJdM+Ylr7xGqgOXf4PTuyHd3kN27uMCZKt+mNs
HjIQtZI4rVZR1LWY1bwj0hBapOh0il1wsrnILXhFwy7PnXGFfK8wjZBskBpCWfFF
Z+JH2J7/8jMuVkF7BJwQyRWj8btCL64PffdOXqZ47Rf6DPRgmkC6XbEWW/AUroA2
YNInfES0dW/FLBmElXZAG4k9vF/e+iwD6WWUts+UcOvvOdO3+w/nalDBtL9+zoRz
zzxHrT4nK+b3JJBE8BKYSoBh/yzppszZGlR7gocMUIIMPEoiqvnRpZlyRth3zosD
onHoXZfCYmY/WIz2HAlMlofwqllqsjtICsRHxAExmLagYopde4pxd9T0EkyKIN1v
4LiES7JxwspKXKd3r8UWYzV8u+17OT1U/5oKeOqCegK1P8EnzndGVEPx3mTtbEfG
1Upn9MGzhkGjKgTikDRA5bW4ambONZ9lImlG6/IzWp3q8xNsA9gPAL4sob8ZNd65
tOW6KzNApPqs5hYLmUw6TfL0yMKGm9NXGjDJYB+RLVd2HDDUEp46NgCB3M8+TJ2e
9xjzjJN3CrtELz6l3I6CRCLHJg97AoeIVOc76i1vY5D4E9Yyceld++qsJiJA5rRh
PEQXnzVHHboI+BJ5aMj0dxZO/ixLY5dLVsBUYcwGIYuKZSk7knQ=
=7m5q
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.