[PATCH v2 05/14] Warn when attempting to log in a signal unsafe manner from signal context

Chase Douglas chase.douglas at canonical.com
Mon Apr 9 11:17:31 PDT 2012


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 |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/os/log.c b/os/log.c
index 2583fe8..8a59306 100644
--- a/os/log.c
+++ b/os/log.c
@@ -288,6 +288,21 @@ LogVWrite(int verb, const char *f, va_list args)
     int len = 0;
     static Bool newline = TRUE;
 
+    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 "
+                                      "log format message is:\n";
+
+        write(logFileFd, warning, sizeof(warning) - 1);
+
+        write(logFileFd, f, strlen_sigsafe(f));
+
+        return;
+    }
+
     if (newline) {
         sprintf(tmpBuffer, "[%10.3f] ", GetTimeInMillis() / 1000.0);
         len = strlen(tmpBuffer);
@@ -457,6 +472,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;
+    }
+
     type_str = LogMessageTypeVerbString(type, verb);
     if (!type_str)
         return;
-- 
1.7.9.1



More information about the xorg-devel mailing list