[PATCH] Log message before aborting

Michael Crute mike at crute.us
Wed Jan 11 20:51:12 CET 2023


On Wed, Jan 11, 2023, at 08:36, Ondrej Zajicek wrote:
> 1) vlog() (which is internally caled from bug()) is not safe to call from
> a signal handler, as it internally takes a mutex, if the signal is received
> when the interrupted thread is already in mutex, it will deadlock.
>
> 2) This alarm is here to ensure that BIRD does not hang, if there is some
> issue withing logging (e.g. deadlock or long-term blocking on write), we
> could hang on the logging, circumventing the watchdog.
>
> 3) bug() has slightly different meaning, so it is not really matching
> here, but that is easily fixed by using log() and abort() separately.
>
> These issues could be fixed, but more intricate approach has to be used.

Thanks Ondrej. I did not realize that vlog was unsafe in this context. It looks like the debug function is closer to a correct solution except that on error it will call bug and also fputs is not async safe.

My goal is to present some log message immediately prior to abort to alert the user that this crash was on purpose. I think this would have helped our Alpine user find their configuration error faster rather than wasting time debugging the bird binary itself.

Is this proposed log function a valid solution?:

void
watchdog_debug(const char *msg)
{
  if (dbgf)
    {
      write(dbgf, msg, strlen(msg));
      abort();
    }
}

write is async-safe and there is no need for string formatting in this case. Is there any other complexity that I'm missing?

~mike


More information about the Bird-users mailing list