X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=log%2Fsyslog.c;h=0e1f2a92a8f8f1527b192a770c4af8cfdb6a0d64;hb=e7a63fbafdc6ec319bab616b43a642728f6b9c1c;hp=7e98d365e6ed085aed35c05f5ecb66dbc6d22af5;hpb=ea3d7fa21f55a39ce55d8e91058c944f5e5d9c6b;p=project%2Fubox.git diff --git a/log/syslog.c b/log/syslog.c index 7e98d36..0e1f2a9 100644 --- a/log/syslog.c +++ b/log/syslog.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -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); } } @@ -243,15 +246,13 @@ log_list(int count, struct log_head *h) int log_buffer_init(int size) { - struct log_head *_log = malloc(size); + struct log_head *_log = calloc(1, size); if (!_log) { fprintf(stderr, "Failed to initialize log buffer with size %d\n", log_size); return -1; } - memset(_log, 0, size); - if (log && ((log_size + sizeof(struct log_head)) < size)) { struct log_head *start = _log; struct log_head *end = ((void*) _log) + size;