text: B. Guaranteed namespace anonymity would be nice, but initially it will be ok to sacrifice that, as long as we choose a function name that is long and random.. >> # test with this: >> # (while :; do printf 'x\ny\n'; sleep 1; done) |line-buffer grep x > > Is that really a valid test? Doesn't the stdout of grep need to be a > pipe? You're right. It's not. Now I have this: # test with this: # (while :; do printf 'x\ny\n'; sleep 1; done) |line-buffer grep x|sed s/x/./ # Or, more realistically, grep for warnings in build output: # make >& log & line-buffer tail -F log --pid=$! |grep -i warning Thanks! >> > Of course this solution depends on gcc and LD_PRELOAD etc. >> >> The mixed blessing of shared libraries... > > Well, __attribute__((constructor)) is gcc-specific but it was another > shorthand used for brevity to squeeze things into one line. The ctor > could however just as well be implemented in plain ISO C++. Naturally > the specific set of required options to produce a shared library does > tend to be compiler specific though. > > I'd be more concerned about the portability of LD_PRELOAD, which tends > to be a feature of ELF systems. Cygwin does provide an emulation of > LD_PRELOAD however, so the example at least does work there as well, > modulo s/-fPIC// and s/.so/.dll/.