mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: printf POSIX compliance
Date: Fri, 8 Jun 2012 19:25:06 -0400	[thread overview]
Message-ID: <20120608232506.GX163@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAOnWdoiumYwoNg=fBRJ1r=ZKQSd_XT4vrYctfc_EGpu1+zqEwA@mail.gmail.com>

On Fri, Jun 08, 2012 at 06:07:37PM +0100, Reuben Thomas wrote:
> On 8 June 2012 18:00, Rich Felker <dalias@aerifal.cx> wrote:
> > On Fri, Jun 08, 2012 at 05:46:10PM +0100, Reuben Thomas wrote:
> >>
> >> Jim Meyering has an analysis of the problem here:
> >>
> >> http://www.gnu.org/ghm/2011/paris/#sec-2-1
> >
> > He makes it a lot more difficult than it has to be...
> 
> Possibly a discussion worth having with Jim? Most obviously on
> bug-gnulib@gnu.org, as he's an active gnulib maintainer.

I'm not sure it's worth starting a debate. His slides made for an
interesting presentation, but in my opinion, the reason it got to be a
mess is that his choice to "factor out" the close operation into an
exit handler registered with atexit was a fundamentally bad design. It
creates additional global state (not to mention the fact that exiting
from an atexit handler has some major issues in itself!) and
unnaturally breaks up the use and checking of stdout status into
unrelated parts of the program, which then required adding ugly and
non-portable hacks to determine if closing stdout needs to be checked.

There's also the issue that if fd 1 did not exist when the program
started and got assigned to another file the program opened,
fclose(stdout) could wrongly close that fd; in the worst case
(especially with multi-threaded programs) this could then lead to
another file getting reassigned to the same fd, and code that's still
in the process of writing to the original one could clobber the wrong
file.

If he'd stuck to closing stdout and checking for errors in the main
program flow after the program is done using stdout, everything would
remain incredibly simple. By the way, note that my test
ferror(stdout)||fclose(stdout) avoids calling fclose if ferror returns
nonzero, so you don't clobber the existing errno value, but that's
fragile anyway since it's likely that you already clobbered errno
elsewhere.

Rich


  reply	other threads:[~2012-06-08 23:25 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-08 10:34 Reuben Thomas
2012-06-08 12:19 ` Luca Barbato
2012-06-08 12:32   ` Reuben Thomas
2012-06-08 14:04 ` Szabolcs Nagy
2012-06-08 14:16   ` Rich Felker
2012-06-08 14:44 ` Rich Felker
2012-06-08 14:55   ` Rich Felker
2012-06-08 15:06     ` Szabolcs Nagy
2012-06-08 15:29       ` Rich Felker
2012-06-08 15:43         ` Reuben Thomas
2012-06-08 15:53           ` Rich Felker
2012-06-08 16:16             ` Reuben Thomas
2012-06-08 16:38               ` John Spencer
2012-06-08 16:37                 ` Reuben Thomas
2012-06-09  7:43                   ` John Spencer
2012-06-09 14:17                     ` Reuben Thomas
2012-06-08 16:46       ` John Spencer
2012-06-08 16:46         ` Reuben Thomas
2012-06-08 16:51           ` Rich Felker
2012-06-08 16:58             ` Reuben Thomas
2012-06-08 17:00           ` Rich Felker
2012-06-08 17:07             ` Reuben Thomas
2012-06-08 23:25               ` Rich Felker [this message]
2012-06-09  2:33           ` Isaac Dunham
2012-06-09  2:45             ` Rich Felker
2012-06-09 12:58               ` Szabolcs Nagy
2012-06-09 14:17                 ` Reuben Thomas
2012-06-09 21:11                 ` Rich Felker
2012-06-09 21:24                   ` Reuben Thomas
2012-06-09 14:15               ` Reuben Thomas
2012-06-11  9:37 Pedro Alves

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=20120608232506.GX163@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).