#include <stdio.h>
#include <syslog.h>
#include <errno.h>
+#include <ctype.h>
#include <libubox/uloop.h>
#include <libubox/usock.h>
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) {
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) {
int len;
while (1) {
- char *c;
-
len = recv(fd->fd, buf, LOG_LINE_SIZE - 1, 0);
if (len < 0) {
if (errno == EINTR)
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);
}
}
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;