[squid-dev] [PATCH] Do not die silently when dying early

Amos Jeffries squid3 at treenet.co.nz
Sat May 20 11:04:52 UTC 2017


On 20/05/17 10:25, Alex Rousskov wrote:
> Hello,
>
>      The attached patch allows Squid to report various problems (e.g.,
> mishandled exceptions) that may occur very early in Squid lifetime,
> before proper logging is configured by the first _db_init() call.
>
> To enable such early reporting, we started with a trivial debug.cc change:
>
>    -FILE *debug_log = NULL;
>    +FILE *debug_log = stderr;
>
> ... but then realized that debug_log may not be assigned early enough!
> The resulting changes ensure that we can log (to stderr if necessary) as
> soon as stderr itself is initialized. They also polish related logging
> code, including localization of stderr checks and elimination of
> double-closure during log rotation on Windows.
>
> These reporting changes do not bypass or eliminate any failures.
>
> This patch is independent from the "Do not die silently when dying via
> std::terminate()" patch posted a few days ago, but, in combination, the
> two patches fix reporting of early std::terminate() deaths.
>

Audit:

in src/Debug.h:

* instead of adding yet another wrapper macro, please replace all uses 
of debug_log with DebugStream().
  - we already know from earlier macros that these just lead us to much 
more pain and long arguments in future developments.
  - the important comment by Duane in src/main.cc SquidShutdown() is now 
needing an update to reference the current symbol names.

in src/debug.cc:

* debugOpenLog()
  - since the bulk of the function is being altered please take the opportunity to remove the use of NULL in there.

  - in the else condition after fopen() we are writing explicitly to stderr then clearing TheLog. It seems to me that a better thing would be to do is write that notice to TheLog before clearing it, to perror() and then to TheLog after clearing it. Which should result in all places the admin might look getting the message, and the log writes can be via debugs() instead of fprintf().


Amos



More information about the squid-dev mailing list