On Mon, Apr 27, 2015 at 12:30:05PM -0700, Isaac Dunham wrote: > On Mon, Apr 27, 2015 at 08:36:53AM -0700, enh wrote: > > On Sun, Apr 26, 2015 at 7:30 PM, Rich Felker <[email protected]> wrote: > > > On Sat, Apr 25, 2015 at 12:14:44PM -0700, enh wrote: > > >> what's the plan wrt SIGPIPE? the desktop is pretty inconsistent. many > > >> (but not all) commands install a signal handler that does _exit(0). > > >> others (coreutils 8.21's ls, say) do nothing. normally "what you do > > >> about SIGPIPE" isn't a problem but on Android that leads to a crash > > >> report and people filing "ls crashed" bugs against me. (our default > > >> shell PS setup is also noisy about crashes.) > > > > > > Why not just *block* SIGPIPE (with sigprocmask) so that the write > > > returns an error (EPIPE) and the program applies the same logic it > > > would for any other write error? > > > > toybox does a little better than toolbox there thanks to xwrite, but > > i've yet never met anyone who checks the return value of printf... > > vmstat.c, cal.c, and see xprintf(). > In some places the choice of non-erroring functions is deliberate, so > that a failure to write will not lead to an early exit.
Thanks for clarifying. > > plus there's the question of whether giving up because you're writing > > to a broken pipe is an error exit or not. you could add a special case > > to xwrite (and add xprintf and xputs and...), but since the whole idea > > is that code shouldn't have to care, it's easier just to install a > > signal handler that does _exit(0). > > There are xputs and xprintf already. > > Calling _exit() is wrong for toybox, since you cannot use atexit() > type code (eg, delete tempfiles on exit) - xexit() is the recommended > path for toybox. Agreed. _exit was only proposed because exit (or xexit) would be invalid from a signal handler in general. > Using a fixed return value is wrong; for an example, grep returns > 0 for "line matched", 1 for "no match", and >1 for errors. Agreed. This is another reason the logic needs to be local to the tool or else xprintf/xwrite/etc. need a way to control the exit value if they don't already have one. Rich _______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
