diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2009-04-16 16:17:07 +1000 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2009-05-08 22:50:35 -0700 |
commit | 9c643b1e3ddc4ec9f1a924bd25f24df8536c7ea6 (patch) | |
tree | db950b247a6e5926dbc09002f688dc97d6b9dcdc | |
parent | 7cd596e0dd6b9c195d7e395c26bfb00ef544c525 (diff) |
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>
(cherry picked from commit 0e0642ee9466d3268476d0084a83a9d93a4aa555)
Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r-- | os/log.c | 22 |
1 files changed, 6 insertions, 16 deletions
@@ -312,7 +312,7 @@ _X_EXPORT void LogVMessageVerb(MessageType type, int verb, const char *format, va_list args) { const char *s = X_UNKNOWN_STRING; - char *tmpBuf = NULL; + char tmpBuf[1024]; /* Ignore verbosity for X_ERROR */ if (logVerbosity >= verb || logFileVerbosity >= verb || type == X_ERROR) { @@ -354,21 +354,11 @@ LogVMessageVerb(MessageType type, int verb, const char *format, va_list args) break; } - /* - * Prefix the format string with the message type. We do it this way - * so that LogVWrite() is only called once per message. - */ - if (s) { - 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); + /* if s is not NULL we need a space before format */ + snprintf(tmpBuf, sizeof(tmpBuf), "%s%s%s", s ? s : "", + s ? " " : "", + format); + LogVWrite(verb, tmpBuf, args); } } |