logread: fix line buffer size
[project/ubox.git] / log / logread.c
index edac1d9..784d1f9 100644 (file)
@@ -100,10 +100,9 @@ static int log_notify(struct blob_attr *msg)
 {
        struct blob_attr *tb[__LOG_MAX];
        struct stat s;
-       char buf[512];
+       char buf[LOG_LINE_SIZE + 128];
        char buf_ts[32];
        uint32_t p;
-       char *str;
        time_t t;
        uint32_t t_ms = 0;
        char *c, *m;
@@ -145,7 +144,7 @@ static int log_notify(struct blob_attr *msg)
        c = ctime(&t);
        p = blobmsg_get_u32(tb[LOG_PRIO]);
        c[strlen(c) - 1] = '\0';
-       str = blobmsg_format_json(msg, true);
+
        if (log_type == LOG_NET) {
                int err;
 
@@ -191,7 +190,6 @@ static int log_notify(struct blob_attr *msg)
                ret = write(sender.fd, buf, strlen(buf));
        }
 
-       free(str);
        if (log_type == LOG_FILE)
                fsync(sender.fd);
 
@@ -236,8 +234,11 @@ static void logread_fd_data_cb(struct ustream *s, int bytes)
                log_notify(a);
                ustream_consume(s, cur_len);
        }
-       if (!log_follow)
-               uloop_end();
+}
+
+static void logread_fd_state_cb(struct ustream *s)
+{
+       uloop_end();
 }
 
 static void logread_fd_cb(struct ubus_request *req, int fd)
@@ -245,6 +246,7 @@ static void logread_fd_cb(struct ubus_request *req, int fd)
        static struct ustream_fd test_fd;
 
        test_fd.stream.notify_read = logread_fd_data_cb;
+       test_fd.stream.notify_state = logread_fd_state_cb;
        ustream_fd_init(&test_fd, fd);
 }
 
@@ -331,6 +333,7 @@ int main(int argc, char **argv)
 
                blob_buf_init(&b, 0);
                blobmsg_add_u8(&b, "stream", 1);
+               blobmsg_add_u8(&b, "oneshot", !log_follow);
                if (lines)
                        blobmsg_add_u32(&b, "lines", lines);
                else if (log_follow)