On 04/27/2015 10:36 AM, 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...
Actually, we had lunch last time I was in california: https://github.com/landley/toybox/blob/master/lib/xwrap.c#L106 https://github.com/landley/toybox/blob/master/lib/xwrap.c#L31 Sometimes I downshift calls from xputc() and xprintf() to the non-checking versions because I know the xexit() test will get it (returning from a command's main() also calls xexit(), see toy_exec() in main.c) and I don't want to flush there (without which the ferror() check is useless). But yes, I'm _that_ level of crazy. (I also care about -EINTR restarts but the kernel behavior here seems to have changed over the years with regards to whether or not you can get a 0 byte read/write that does _not_ mean EOF. I need to do another pass over that...) > plus there's the question of whether giving up because you're writing > to a broken pipe is an error exit or not. That is a bigger question. cat file | head -n 5 presumably isn't an error, but with ours it is. (Of course conventional pipe only shows the error from the last command, you'd need -o pipefail to see the return code of cat. Presumably for this very reason. :) > 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). I have a local patch that does if (CFG_TOYBOX_ON_ANDROID) signal(blah) with more or less your change that I fished out of git after giving up on gerrit. I haven't checked it in yet (still going hmmm) but probably will later today. But first I need to read the rest of this GIANT THREAD. (Was reading via web interface, implemented the thing, saw the next message questioned whether or not it was the right thing to do, saw the next message was one I needed to reply to, wandered back to the machine with the right email setup, and now I head back out to a place where I won't have a cat in my face while I type. (In this case, PeeJee.)) Rob _______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
