[PATCH v3 08/16] Warn when attempting to log in a signal unsafe manner from signal context

Chase Douglas chase.douglas at canonical.com
Mon Apr 16 11:30:22 PDT 2012


On 04/16/2012 11:14 AM, Chase Douglas wrote:
> Also, print out the offending message format. This will hopefully help
> developers track down unsafe logging.
> 
> Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
> ---
>  os/log.c |   26 ++++++++++++++++++++++++++
>  1 files changed, 26 insertions(+), 0 deletions(-)
> 
> diff --git a/os/log.c b/os/log.c
> index 3747fe0..36e678e 100644
> --- a/os/log.c
> +++ b/os/log.c
> @@ -352,6 +352,16 @@ LogVWrite(int verb, const char *f, va_list args)
>      int len = 0;
>      static Bool newline = TRUE;
>  
> +    if (inSignalContext) {
> +        BUG_WARN_MSG(inSignalContext,
> +                     "Warning: attempting to log data in a signal unsafe "
> +                     "manner while in signal context. Please update to check "
> +                     "inSignalContext and/or use LogMessageVerbSigSafe() or "
> +                     "ErrorSigSafe(). The offending log format message is: "
> +                     "%s\n", f);
> +        return;
> +    }
> +
>      if (newline) {
>          sprintf(tmpBuffer, "[%10.3f] ", GetTimeInMillis() / 1000.0);
>          len = strlen(tmpBuffer);
> @@ -578,6 +588,22 @@ LogVHdrMessageVerb(MessageType type, int verb, const char *msg_format,
>      char *p;
>      int left;
>  
> +    if (inSignalContext) {
> +        static const char warning[] = "Warning: attempting to log data in a "
> +                                      "signal unsafe manner while in signal "
> +                                      "context. Please update to check "
> +                                      "inSignalContext and/or use "
> +                                      "LogMessageVerbSigSafe(). The offending "
> +                                      "header and log message formats are:\n";
> +
> +        write(logFileFd, warning, sizeof(warning) - 1);
> +
> +        write(logFileFd, hdr_format, strlen_sigsafe(hdr_format));
> +        write(logFileFd, msg_format, strlen_sigsafe(msg_format));
> +
> +        return;
> +    }
> +

I forgot to fix up this second hunk. I have pushed a fixed version to my
branch at fdo. It basically does the same thing as the first hunk.

-- Chase


More information about the xorg-devel mailing list