summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2017-11-06 11:48:52 +0100
committerFelix Fietkau <nbd@nbd.name>2017-11-06 11:48:52 +0100
commit2c0d9cfe05e9712d44622c6bb4558e97359bfb76 (patch)
tree670b1cd6b21b3967eb8c2746f97629a31bfbb82f
parenta0819044b14ec34450d2fcab33fb15232e8164fa (diff)
downloadubox-2c0d9cfe05e9712d44622c6bb4558e97359bfb76.tar.gz
logd: move stripping of newlines to log_add()
Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--log/syslog.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/log/syslog.c b/log/syslog.c
index 7e98d36..af6530c 100644
--- a/log/syslog.c
+++ b/log/syslog.c
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <syslog.h>
#include <errno.h>
+#include <ctype.h>
#include <libubox/uloop.h>
#include <libubox/usock.h>
@@ -63,6 +64,7 @@ log_add(char *buf, int size, int source)
struct log_head *next;
int priority = 0;
int ret;
+ char *c;
/* bounce out if we don't have init'ed yet (regmatch etc will blow) */
if (!log) {
@@ -70,12 +72,19 @@ log_add(char *buf, int size, int source)
return;
}
- /* strip trailing newline */
- if (buf[size - 2] == '\n') {
- buf[size - 2] = '\0';
- size -= 1;
+ for (c = buf; *c; c++) {
+ if (*c == '\n')
+ *c = ' ';
}
+ c = buf + size - 2;
+ while (isspace(*c)) {
+ size--;
+ c--;
+ }
+
+ buf[size - 1] = 0;
+
/* strip the priority */
ret = regexec(&pat_prio, buf, 3, matches, 0);
if (!ret) {
@@ -135,8 +144,6 @@ syslog_handle_fd(struct uloop_fd *fd, unsigned int events)
int len;
while (1) {
- char *c;
-
len = recv(fd->fd, buf, LOG_LINE_SIZE - 1, 0);
if (len < 0) {
if (errno == EINTR)
@@ -148,12 +155,8 @@ syslog_handle_fd(struct uloop_fd *fd, unsigned int events)
break;
buf[len] = 0;
- for (c = buf; *c; c++) {
- if (*c == '\n')
- *c = ' ';
- }
- log_add(buf, c - buf + 1, SOURCE_SYSLOG);
+ log_add(buf, strlen(buf) + 1, SOURCE_SYSLOG);
}
}