Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



/dev/stderr wasn't being truncated. The redirect caused the options (e.g. O_TRUNC) to be inherited by the file it was redirected to.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: