diff options
author | Milan Bartos <mbartos@redhat.com> | 2013-03-13 09:15:03 +0100 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2013-03-19 17:08:34 +0100 |
commit | 39b35a32b4a45ccb6506e15b02780c30ca8c3973 (patch) | |
tree | 15087e2f52c46210b9282ca08e6c687ab92670ff | |
parent | 654ad0a7750fec175d23951cd8abed77abb37be4 (diff) | |
download | rsyslog-39b35a32b4a45ccb6506e15b02780c30ca8c3973.tar.gz rsyslog-39b35a32b4a45ccb6506e15b02780c30ca8c3973.tar.bz2 rsyslog-39b35a32b4a45ccb6506e15b02780c30ca8c3973.zip |
Improved field translate performance.
modified: imjournal.c
-rw-r--r-- | plugins/imjournal/imjournal.c | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/plugins/imjournal/imjournal.c b/plugins/imjournal/imjournal.c index bdfc7756..8e1066dc 100644 --- a/plugins/imjournal/imjournal.c +++ b/plugins/imjournal/imjournal.c @@ -126,6 +126,7 @@ readjournal() { char *sys_iden_help; const void *get; + uchar *parse; char *get2; size_t length; @@ -149,7 +150,7 @@ readjournal() { /* Get message text */ if (sd_journal_get_data(j, "MESSAGE", &get, &length) < 0) { - logmsgInternal(NO_ERRCODE, LOG_SYSLOG|LOG_INFO, "log message from journal doesn't have MESSAGE", 0); + logmsgInternal(NO_ERRCODE, LOG_SYSLOG|LOG_INFO, (uchar *)"log message from journal doesn't have MESSAGE", 0); iRet = RS_RET_OK; goto ret; } @@ -212,21 +213,38 @@ readjournal() { /* get length of journal data prefix */ prefixlen = ((char *)equal_sign - (char *)get); - /* translate name fields to lumberjack names XXX not very effective */ - if (!strncmp(get, "_PID", 4)) { - name = strdup("pid"); - } else if (!strncmp(get, "_GID", 4)) { - name = strdup("gid"); - } else if (!strncmp(get, "_UID", 4)) { - name = strdup("uid"); - } else if (!strncmp(get, "_COMM", 5)) { - name = strdup("appname"); - } else if (!strncmp(get, "_EXE", 4)) { - name = strdup("exe"); - } else if (!strncmp(get, "_CMDLINE", 8)) { - name = strdup("cmd"); - } else { + /* translate name fields to lumberjack names */ + parse = (uchar *)get; + + switch (*parse) + { + case '_': + ++parse; + if (*parse == 'P') { + name = strdup("pid"); + } else if (*parse == 'G') { + name = strdup("gid"); + } else if (*parse == 'U') { + name = strdup("uid"); + } else if (*parse == 'E') { + name = strdup("exe"); + } else if (*parse == 'C') { + parse++; + if (*parse == 'O') { + name = strdup("appname"); + } else if (*parse == 'M') { + name = strdup("cmd"); + } else { + name = strndup(get, prefixlen); + } + } else { + name = strndup(get, prefixlen); + } + break; + + default: name = strndup(get, prefixlen); + break; } if (name == NULL) { |