[squid-dev] [PATCH] avoid clobbering errno in debugs()

Amos Jeffries squid3 at treenet.co.nz
Sun Jul 12 00:34:44 UTC 2015


On 12/07/2015 5:42 a.m., Kinkie wrote:
> Hi all,
>   this patch saves and restores errno around calls to strftime in
> debugLogTime, preventing harmless errors in these calls from clobbering
> errno, thus messing up xstrerror() calls within debugs().
> 

1) xerrno is a local variable in lots of places in the code. This patch
introduces shadowing errors. Please call it debug_xerrno.

2) The snprintf() call directly after restoring errno in the top chunk
may alter the original errno in rare cases as well.

Which is a good example of why we simply can't rely on errno being
correct for any length of time in C++. Things such as errno changes by
operator<< implementations, print() methods, implicit calls to copy
constructors/destructors, and exlicit function/method calls are also
possible in ways we are unlikely to be predict.


We are still going to have to do a global removal of xstrerror() anyway.

IMO, we should move xstrerror() to Debugs.h and make it use the
debug_xerrno local variable instead of errno.

Amos



More information about the squid-dev mailing list