os: don't malloc memory in LogVMessageVerb.

LogVWrite is limited to a buffer size of 1024, so we don't loose anything here
by truncating. This way we can use LogVMessageVerb (and xf86Msg and friends)
during signal handlers with the normal message types.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Alan Coopersmith <alan.coopersmith@sun.com>
This commit is contained in:
Peter Hutterer 2009-04-16 16:17:07 +10:00
parent 62d2fb6863
commit 0e0642ee94

View File

@ -316,7 +316,7 @@ void
LogVMessageVerb(MessageType type, int verb, const char *format, va_list args) LogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
{ {
const char *s = X_UNKNOWN_STRING; const char *s = X_UNKNOWN_STRING;
char *tmpBuf = NULL; char tmpBuf[1024];
/* Ignore verbosity for X_ERROR */ /* Ignore verbosity for X_ERROR */
if (logVerbosity >= verb || logFileVerbosity >= verb || type == X_ERROR) { if (logVerbosity >= verb || logFileVerbosity >= verb || type == X_ERROR) {
@ -358,21 +358,11 @@ LogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
break; break;
} }
/* /* if s is not NULL we need a space before format */
* Prefix the format string with the message type. We do it this way snprintf(tmpBuf, sizeof(tmpBuf), "%s%s%s", s ? s : "",
* so that LogVWrite() is only called once per message. s ? " " : "",
*/ format);
if (s) { LogVWrite(verb, tmpBuf, args);
tmpBuf = malloc(strlen(format) + strlen(s) + 1 + 1);
/* Silently return if malloc fails here. */
if (!tmpBuf)
return;
sprintf(tmpBuf, "%s ", s);
strcat(tmpBuf, format);
LogVWrite(verb, tmpBuf, args);
free(tmpBuf);
} else
LogVWrite(verb, format, args);
} }
} }