[Toybox] Outsmarting myself again...

Rob Landley rob at landley.net
Wed Feb 8 07:51:38 PST 2012


On 02/08/2012 03:09 AM, Tim Elliott wrote:
> On Tue, Feb 7, 2012 at 8:02 PM, Rob Landley <rob at landley.net> wrote:
>> P.S.  The reason this came up is that "cmp" has its own "-" handlign
>> logic, and I'm trying to figure out if I should involve loopfiles or
>> just factor out opendash() as a function.  I'm actually leaning towards
>> abusing loopfiles, since it's already there...
> 
> What you ended up doing in 440 is pretty clever, and I wonder if we'll
> eventually want a helper function to do the open/close without
> requiring the cleverness...

I wonder that too.  I'm not against opendash(), I just haven't needed it
_yet_...

If I do write an opendash, I should redo loopfiles() to use it, the
thing is the "if no arguments read from stdin" thing on line 635 doesn't
conceptually quite fold in there cleanly. (It doesn't apply to cmp, but
it does apply to factoring out the dash logic from the blob it's
currently embedded in...)

I try to avoid writing the same code more than once if I can help it.
Sometimes the overhead of encapsulating something is more trouble than
it's worth.

I'm not a big fan of the design patterns crowd (Hey, your language is
missing an abstraction!  And there's another!) but for embedded stuff I
do like http://en.wikipedia.org/wiki/Single_Point_of_Truth, and I apply
it to code too.  "We've got a thing that does that, use the thing.  If
the thing isn't right, fix the thing."

I often get stopped by something simple because I found a splinter in
the wood grain and have to go follow the tangent until it's right...

> I see the switch from read() to readall() at
> http://www.landley.net/hg/toybox/rev/7cff5420c90a#l44 . Is readall()
> there to handle the case where read() is interrupted by a signal?

Yup.  It's so we don't get confused by spurious short reads when we're
not actually out of data yet.

Learned to care about that the hard way, and had to figure out how to
_test_ it so I could debug it:

http://www.mail-archive.com/user-mode-linux-devel@lists.sourceforge.net/msg00709.html
http://www.gossamer-threads.com/lists/linux/kernel/528697

Also, once upon a time with busybox, doing:

  tar cv subdir | gzip | ssh blah at blah "cat > tarball.tgz"

Would silently corrupt the tarball if you suspended the pipeline with
ctrl-z, due to the short write being missed and the data it would have
written discarded instead of resent. (I complained and it got fixed, and
since then the pipe infrastructure got rewritten anyway.)

I need to have the setup code in main call sigaction(SA_RESTART) to
avoid the "read/write zero bytes does _not_ mean EOF" problem where you
have to check EINTR and restart., but do I call that on both STOP and
START, and are there others I need to do it for...?  ("man 7 signal"
doesn't quite say...)

I can has todo items.

> Cheers,
> Tim

Rob

 1328716298.0


More information about the Toybox mailing list