2010-02-27

a band of brothers (and a lady from nsa)

Herbert R. J. Grosch has passed, leaving only a private literature that goes 1400 miles per hour. Rest in peace, big guy; we will know you by the trail of bits. Columbia has a fine tribute page up. If you've never read his autobiography, it's an absolutely brilliant, incredibly broad recollection of a bygone era, a time when giants truly strode the earth, everyone spoke Latin, and scientists read the classics. One thousand cocktails to you, Herb.

2010-02-13

avast! sailing the seas of posix and gnu make, i shot the ALBATROSS

Dateline: GNU make. We need a 32-bit hex number. bash(1)isms are unacceptable, but a PRNG having streaming file semantics at $(RNG) may be assumed. I came up with this in about 5 seconds:
RSTR:=0x$(shell dd if=/dev/urandom bs=4 count=1 \
        of=/dev/stdout | cksum | tr -c -d [:xdigit:] \
        | cut -b-8)

how might you do things differently? cksum is POSIX, unlike md5sum(1) (which, for starters, is just "md5(1)" on freebsd). intuition suggests the 802.3 (Ethernet) CRC used by cksum(1) doesn't wreck your uniform distribution properties (the simple one's-complement checksum method of RFC 793 (IPv4) obviously would suffice, but isn't trivially available from the POSIX command line).

ronnie's gonna be hella pissed Note that cksum(1posix) is introduced solely for converting dd-generated seed material into the necessary human-readable format. i'd like to use printf(1posix), but we need to pass dd's output through a pipe. it mustn't go to the shell, or there is a 4*N*(1/256) likelyhood of failure for each of N bytes interpreted as metacharacters. we can use single quotes to interpret only single quote characters, meaning a 1.5625% chance of failure. NASA called and said, "thanks, assmaster! now we'll never know whether tiny screws can be sorted in space!"

yo dawg i put a rocket on your rocket so you can rocket while you rock itremember that variable definitions don't directly abort the build (aka cause a syntax error) for this kind of thing, so it will propagate up in your build...quite probably unnoticed, quite possibly until all too late (this is why i distrust $()/backtick substitution in scripts). Oh, and NASA called. They said you're off the Makefile team. Perhaps you'd have better luck writing PHP for Wet Seal?

unfortunately there's this big fat Hummer2-like (as in it wastes resources) entry in the printf(1) man page:

STDIN Not used.
three bitches in a bitch boat! printf(1posix) ought accept a format conversion modifier indicating "take this one from stdin" (or, to be more flexible, a file descriptor which defaults to stdin's STDIN_FILENO aka 0).

Indeed, if we hijacked %n for this purpose, it would help fix a bug in the printf(1) and printf(1posix) man pages:

"...FORMAT controls the output as in C printf..."

Like hell it does; the byzantine %n conversion specifier, according to printf(3), "store[s] into the integer indicated by the int * (or variant) pointer argument. No argument is converted."

Well, there's jolly little pointer context you can very meaningfully pass to printf(1posix) code, following an exec(2) call as it (by virtue of being printf(1posix) and not printf(3)) does. in fact, this sounds like some incredibly subtle exploit in the making (%n certainly has been for printf(3) over the years). so maybe printf(1posix) ought grab the next $IFS-delimited value from stdin for %n.

so that was 5 seconds to write the Makefile definition, and about 15 minutes to blog this, huzzah!