mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Jonny Prouty <jonathanprouty@gmail.com>
Cc: musl@lists.openwall.com
Subject: Re: Unexpected behaviour writing to /dev/full
Date: Thu, 2 Aug 2018 14:03:06 -0400	[thread overview]
Message-ID: <20180802180306.GL1392@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAEzKa92sOgkeijjnogjrFBF+BxiEbR3cuP1RexRR6OpFUguvcw@mail.gmail.com>

On Thu, Aug 02, 2018 at 01:51:21PM -0400, Jonny Prouty wrote:
> Hello all,
> 
> I have a question regarding the interaction of atexit() (I believe its
> atexit, anyways) and exit statuses. First the issue I stumbled across, so
> you'll see where I'm coming from:
> 
> # ls "$HOME" > /dev/full; echo $?
> 0
> # echo "$HOME" > /dev/full; echo $?
> 1
> 
> I expected neither command to return 0 since ultimately an ENOSPC should be
> returned when writing to /dev/full. Indeed, failure statuses are returned
> for 'ls' and 'echo' derived from binaries built against glibc. I tried to
> walk the musl code and it looks like the exit codes are being set (or not
> set) by atexit(). In the case of 'ls', it seems that it was able to
> successfully get a directory listing, but the final fflush() of the output
> buffer fails with ENOSPC, but that is lost because it happened as a result
> of some function that was registered with atexit. I *think*. This
> interpretation is also borne of a desire to be able to ascribe this to the
> undefined re-entrant exit behaviour described in "Re-entrancy of exit" at
> https://wiki.musl-libc.org/functional-differences-from-glibc.html. 'echo'
> would be failing (as expected) because presumably stdout is flushed before
> it exits.
> 
> Regardless, the fact that writing to /dev/full can return success seems
> wrong. Any thoughts are much appreciated. Please CC me on any responses.
> Thanks!
> 
> Jonny
> 
> P.S.
> musl behaves similarly to uClibc and uClibc-ng in my testing.

What versions of ls and echo are you using? Busybox? GNU coreutils?
(Note that echo is probably a shell builtin in your shell; you need to
execute /bin/echo or similar to get the real echo program.)

There is nothing musl can do directly to change the exit status;
failure when writing/flushing a file is an error returned to the
application, which determines its own exit status, not something that
automatically changes the return value of main/argument passed to
exit().

Do you mean the program is trying to detect flush failure and set an
exit status from an atexit handler it installed? That's what gnulib
stuff does, if I recall, and it may be how the GNU coreutils ls and
other programs handle termination status. It's not a very good way to
do it, but it should work if they're doing things right. If they're
doing something that's unspecified or undefined from the atexit
handler, such as calling exit again (reentrantly), that's an
application bug.

If you tell us which versions of the utilities you're using, I can
look into it a bit more.

Rich


  reply	other threads:[~2018-08-02 18:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-02 17:51 Jonny Prouty
2018-08-02 18:03 ` Rich Felker [this message]
2018-08-02 18:05   ` Rich Felker
2018-08-02 18:32     ` Jonny Prouty
2018-08-02 18:53       ` Jonny Prouty
2018-08-02 19:51         ` Rich Felker

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=20180802180306.GL1392@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=jonathanprouty@gmail.com \
    --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).