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

Peter Hutterer peter.hutterer at who-t.net
Wed Jun 20 22:56:39 PDT 2012


From: Chase Douglas <chase.douglas at canonical.com>

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>
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 os/log.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/os/log.c b/os/log.c
index 6048246..3ae8fd4 100644
--- a/os/log.c
+++ b/os/log.c
@@ -454,6 +454,16 @@ LogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
     Bool newline;
     size_t len = 0;
 
+    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 "
+                     "ErrorFSigSafe(). The offending log format message is:\n"
+                     "%s\n", format);
+        return;
+    }
+
     type_str = LogMessageTypeVerbString(type, verb);
     if (!type_str)
         return;
@@ -543,6 +553,16 @@ LogVHdrMessageVerb(MessageType type, int verb, const char *msg_format,
     Bool newline;
     size_t len = 0;
 
+    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(). The "
+                     "offending header and log message formats are:\n%s %s\n",
+                     hdr_format, msg_format);
+        return;
+    }
+
     type_str = LogMessageTypeVerbString(type, verb);
     if (!type_str)
         return;
-- 
1.7.10.2



More information about the xorg-devel mailing list