wrapper 

Commit MetaInfo

Revision162 (tree)
Time2011-12-14 04:20:45
Authormortenson

Log Message

Fix a problem with asynchronous log messages

Change Summary

Diff

--- trunk/wrapper/doc/revisions.txt (revision 161)
+++ trunk/wrapper/doc/revisions.txt (revision 162)
@@ -6,6 +6,10 @@
66 where the 'status' command was incorrectly being reported as 'query' in
77 the usage output. The 'status' command had always worked correctly if
88 used.
9+ * Fix a problem in the Community Edition where some asynchronous messages
10+ were causing a warning message to be logged in place of the intended
11+ message. Other than the incorrect log entry, the Wrapper works correctly.
12+ Introduced in 3.5.2.
913
1014 3.5.13
1115 * Fix a typo in the script where the environment variable 'TR_BIN' should
--- trunk/wrapper/src/c/logger.c (revision 161)
+++ trunk/wrapper/src/c/logger.c (revision 162)
@@ -184,6 +184,7 @@
184184 #define QUEUE_SIZE 20
185185 #define QUEUED_BUFFER_SIZE_USABLE (512 + 1)
186186 #define QUEUED_BUFFER_SIZE (QUEUED_BUFFER_SIZE_USABLE + 4)
187+TCHAR formatMessages[WRAPPER_THREAD_COUNT][QUEUED_BUFFER_SIZE];
187188 int queueWrapped[WRAPPER_THREAD_COUNT];
188189 int queueWriteIndex[WRAPPER_THREAD_COUNT];
189190 int queueReadIndex[WRAPPER_THREAD_COUNT];
@@ -367,6 +368,7 @@
367368 threadSets[threadId] = FALSE;
368369 /* threadIds[threadId] = 0; */
369370
371+ formatMessages[threadId][0] = TEXT('\0');
370372 for ( i = 0; i < QUEUE_SIZE; i++ )
371373 {
372374 queueWrapped[threadId] = 0;
@@ -2838,6 +2840,9 @@
28382840 int localReadIndex;
28392841 va_list vargs;
28402842 int count;
2843+ TCHAR *format;
2844+ size_t i;
2845+ size_t len;
28412846 TCHAR *buffer;
28422847
28432848 /* Start by processing any arguments so that we can store a simple string. */
@@ -2847,10 +2852,40 @@
28472852
28482853 #if defined(UNICODE) && !defined(WIN32)
28492854 if (wcsstr(lpszFmt, TEXT("%s")) != NULL) {
2850- /* This is a coding error as strings coming into this function should NEVER use this format.
2851- * If the token below is not '%S' then this would recurse. */
2852- log_printf_queue(useQueue, source_id, LEVEL_ERROR, TEXT("Coding Error. String contains invalid string token for queued logging: %S"), lpszFmt);
2853- return;
2855+ /* On UNIX platforms string tokens must always use "%S" variables and not "%s". We can
2856+ * not safely use malloc here as the call may have originated from a signal handler.
2857+ * Copy the template into the formatMessages string reserved for this thread, replace
2858+ * the tokens and then continue using that. */
2859+ threadId = getThreadId();
2860+ _tcsncpy(formatMessages[threadId], lpszFmt, QUEUED_BUFFER_SIZE);
2861+ /* Terminate just in case the format was too long. */
2862+ formatMessages[threadId][QUEUED_BUFFER_SIZE - 1] = TEXT('\0');
2863+
2864+ format = formatMessages[threadId];
2865+
2866+ /* Replace the tokens. */
2867+#ifdef _DEBUG_QUEUE
2868+ _tprintf(TEXT("Replacing string tokens.\n"));
2869+ _tprintf(TEXT(" From: %S\n"), format);
2870+#endif
2871+ len = wcslen(format);
2872+ if (len > 0) {
2873+ for (i = 0; i < len; i++) {
2874+ if ((i > 0) && (format[i - 1] == TEXT('%')) && (format[i] == TEXT('s'))) {
2875+ /* Make sure the '%' was not escaped. */
2876+ if ((i > 1) && (format[i - 2] == TEXT('%'))) {
2877+ /* Escaped. Do nothing. */
2878+ } else {
2879+ /* 's' needs to be changed to 'S' */
2880+ format[i] = TEXT('S');
2881+ }
2882+ }
2883+ }
2884+ }
2885+#ifdef _DEBUG_QUEUE
2886+ _tprintf(TEXT(" To: %S\n"), format);
2887+#endif
2888+ lpszFmt = format;
28542889 }
28552890 #endif
28562891
旧リポジトリブラウザで表示