I had a really "fun" redirection bug. My library was appening a log file to stderr, but for various convenience reasons, it opened /dev/stderr (instead of just writing to fd #2).
We got a bug report that if you ran a program that used the library by doing:
prog >& /tmp/log
then stderr from the program before my library started logging would disappear. If you did this intead, it would work fine:
prog |& tee /tmp/log
It turned out (obvious in hindsight, not at the time) that we opened /dev/stderr with O_TRUNC, causing /tmp/log to be truncated and earlier logs to be lost.
TLDR: /dev/stderr can be truncated, which was unexpected.
We got a bug report that if you ran a program that used the library by doing:
then stderr from the program before my library started logging would disappear. If you did this intead, it would work fine: It turned out (obvious in hindsight, not at the time) that we opened /dev/stderr with O_TRUNC, causing /tmp/log to be truncated and earlier logs to be lost.TLDR: /dev/stderr can be truncated, which was unexpected.