[Toybox] [PATCH] count.c: Human readable -h option and MAYFORK

Rob Landley rob at landley.net
Fri Oct 27 02:47:02 PDT 2023


On 10/26/23 18:33, enh wrote:
> On Tue, Oct 24, 2023 at 12:31 AM Rob Landley <rob at landley.net> wrote:
>> Possibly the test is wrong, and I should change it to call "echo -n" and check
>> for 'yyy'. How either way proves they ran in parallel is unclear...
> 
> (yeah, if _other_ echo's aren't atomic, it probably doesn't make sense
> for you to bend over backwards to make yours atomic.)

Well, other echo's _are_ atomic, "for the first 500 characters" or similar.

$ strace /bin/echo one two three |& grep write
write(1, "one two three\n", 14one two three

They stop being atomic when we exceed their stdio buffer size (which is
undocumented and variable)...

$ strace /bin/echo $(seq 1 10000) |& grep write | wc -l
12

and nothing's going to be atomic if it exceeds the kernel's pipe buffer size
(which is kernel version specific and changeable with ulimit...

But not being atomic for a simple case like this smells likely to break other
stuff. Alas "smells" is not portably regression-testable.

Rob


More information about the Toybox mailing list