From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13100 Path: news.gmane.org!.POSTED!not-for-mail From: Jonny Prouty Newsgroups: gmane.linux.lib.musl.general Subject: Re: Unexpected behaviour writing to /dev/full Date: Thu, 2 Aug 2018 14:32:18 -0400 Message-ID: References: <20180802180306.GL1392@brightrain.aerifal.cx> <20180802180509.GM1392@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000a69213057278086e" X-Trace: blaine.gmane.org 1533234639 25634 195.159.176.226 (2 Aug 2018 18:30:39 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 2 Aug 2018 18:30:39 +0000 (UTC) Cc: musl@lists.openwall.com To: Rich Felker Original-X-From: musl-return-13116-gllmg-musl=m.gmane.org@lists.openwall.com Thu Aug 02 20:30:35 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1flIMs-0006bC-Fe for gllmg-musl@m.gmane.org; Thu, 02 Aug 2018 20:30:34 +0200 Original-Received: (qmail 28217 invoked by uid 550); 2 Aug 2018 18:32:42 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 28199 invoked from network); 2 Aug 2018 18:32:42 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NtCFGZhJODVJWjIPgK22Ypja/RGbPLztLrOi7JKDW38=; b=j2aOYQtJHSrYT7rICdOHuM31hGqlFzEuEAdZMVUX7+M46pbjZ16+Px9dxqyvRTYgTc BIYuOUNufFf4FwSmffuhs49466EP9Z2Aik/X6HWL0FSQgFbFLVR9xTX/8isgb1Lc3P5R JIaJVE74pisGkZ4ZuQ8WscV5v8N9x+KdhZkTT/J4v/4vbfRarMx26qEA2obV61hp3qKI /fDMfiHqsW9YPU6tzFAblwNSP/RCEmr7pFNErKX6Zw+PGnMmG4sCqQunj36iEok1pnPJ lTID+6/SmWYvMTDV6EDlx4/5QtW/LtL4dl7yaHkygRzaj3BuopvR3008qzMFBqXf/OuX BXcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NtCFGZhJODVJWjIPgK22Ypja/RGbPLztLrOi7JKDW38=; b=EzFqI1nzoj4GrfsbaoD5CruK2CByfZPttDeJrdGWMga5tImOFj46wQokV4E9h/vHHG fNp6ZpfuulJegj0floRsSTU5mHo7lt9jQLOKfFrsoAYVJjh2FMwWhL5/UnBarCUzUZ93 ls/57K0AbsAaABeb2GLkyIXzOYz7HYuNM0vkxfdBFenzPqpqUMc2dYjCKGLtyMBvXeQ4 vn4lDWnWrEpFVHgFxceRUiRVOOxEVLAK82Sz4Qj2cH+s+GCsFyyZ/kC3gNtp9SFKeO9y 3ip785Vtsr2UhSyH2VdmUZKg7rOmERpHKO0lwB8+Rljr6kfJCEsq+MaAg7VMlYNokwEz WW6A== X-Gm-Message-State: AOUpUlHtH53/CzvoLfkpzv9TxOol+kuVuwsCfS/wFLhknn+vu15CsOAu 3tcyYDnZffZAWJsZQO6XiuigzG/5XkrbUnwPDdT4fg== X-Google-Smtp-Source: AAOMgpfM9DeY2xzPSyrqhE9bASUSa0KbRKee1+xFB0mJIk42DKjiPacGUSJY4iE2m9j7bwFy7EiIO0absJolhXiUwBY= X-Received: by 2002:a19:f22:: with SMTP id e34-v6mr2472555lfi.1.1533234750325; Thu, 02 Aug 2018 11:32:30 -0700 (PDT) In-Reply-To: <20180802180509.GM1392@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:13100 Archived-At: --000000000000a69213057278086e Content-Type: text/plain; charset="UTF-8" I am indeed using busybox ls, but I can get similar behavior when running things that aren't shell builtins. For instance in Alpine if you run: # /bin/rc-status > /dev/full ; echo $? 0 or #/sbin/update-conf --help &> /dev/full ; echo $? 0 Some programs do behave as I'd expect, however # /sbin/apk --help> /dev/full ; echo $? 1 Something seems amiss. P.S. Please excuse my brevity, I am corresponding from my phone. On Aug 2, 2018 2:05 PM, "Rich Felker" wrote: On Thu, Aug 02, 2018 at 02:03:06PM -0400, Rich Felker wrote: > 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. For what it's worth, I just tested and got the behavior you saw with busybox ls. With GNU coreutils ls linked against musl, I get a nonzero exit status. So if you're using a busybox-based distro like Alpine and didn't install GNU coreutils in place of it, this very well might just be busybox failing to report the error, which should probably be reported as a bug in busybox. Rich --000000000000a69213057278086e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I am indeed using busybox ls, but I can get similar behav= ior when running things that aren't shell builtins.=C2=A0 For instance = in Alpine if you run:

# /bin/r= c-status > /dev/full ; echo $?
0

or

#/sbin/update-conf --help &>=C2=A0/dev/full ; echo $?
0

Some programs do behave as I'd expect, however

# /sbin/apk --help> /dev/full ; echo $?
1

Something seems amiss.
<= div data-smartmail=3D"gmail_signature" dir=3D"auto">
P.S. Please excuse = my brevity, I am corresponding from my phone.

On Aug 2, 2018 2:05 PM, &qu= ot;Rich Felker" <dalias@libc.org= > wrote:
On Thu, Aug 02, 2018 at 02:03:06PM -0400, Rich Felker wr= ote:
> 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 believ= e its
> > atexit, anyways) and exit statuses. First the issue I stumbled ac= ross, 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 a= gainst 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 w= as able to
> > successfully get a directory listing, but the final fflush() of t= he 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 th= is to the
> > undefined re-entrant exit behaviour described in "Re-entranc= y of exit" at
> > https://wiki.m= usl-libc.org/functional-differences-from-glibc.html. 'echo'
> > would be failing (as expected) because presumably stdout is flush= ed 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 res= ponses.
> > 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<= br> > 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 gnuli= b
> 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&#= 39;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.

For what it's worth, I just tested and got the behavior you saw with busybox ls. With GNU coreutils ls linked against musl, I get a nonzero
exit status. So if you're using a busybox-based distro like Alpine and<= br> didn't install GNU coreutils in place of it, this very well might just<= br> be busybox failing to report the error, which should probably be
reported as a bug in busybox.


Rich

--000000000000a69213057278086e--