I can never seem to remember how this works, but are you sure the <code>write()</code> won't block if there is no reader on the other end (for whatever reason)?

The drainers I've seen before often make use of <code>poll()</code> to be sure neither the input nor output will block.