[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 May 14 12:35:39 PDT 2012


On 05/10/2012 11:23 PM, Peter Hutterer wrote:
> On Mon, Apr 16, 2012 at 11:30:22AM -0700, Chase Douglas wrote:
>> 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.
> 
> how about a define for the message? I don't think the header is that
> important, the log message alone should be enough to identify (or print a
> backtrace here)

This has been reduced to two warnings after rebasing on top of master. I
hope that's good enough. I need to get these patches off my queue of
work :).

-- Chase


More information about the xorg-devel mailing list