logd: fix time passed via unix fd
[project/ubox.git] / log / logd.c
index 0407f4c..5c614f6 100644 (file)
@@ -14,6 +14,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <syslog.h>
+#include <unistd.h>
 
 #include <linux/types.h>
 
@@ -57,17 +58,12 @@ client_close(struct ustream *s)
 static void
 client_notify_write(struct ustream *s, int bytes)
 {
-       if (s->w.data_bytes < 128 && ustream_read_blocked(s))
-               ustream_set_read_blocked(s, false);
+       client_close(s);
 }
 
 static void client_notify_state(struct ustream *s)
 {
-       if (!s->eof)
-               return;
-
-       if (!s->w.data_bytes)
-               return client_close(s);
+       return client_close(s);
 }
 
 static int
@@ -89,7 +85,6 @@ read_log(struct ubus_context *ctx, struct ubus_object *obj,
 
        pipe(fds);
        ubus_request_set_fd(ctx, req, fds[0]);
-
        cl = calloc(1, sizeof(*cl));
        cl->s.stream.notify_write = client_notify_write;
        cl->s.stream.notify_state = client_notify_state;
@@ -103,7 +98,7 @@ read_log(struct ubus_context *ctx, struct ubus_object *obj,
                blobmsg_add_u32(&b, "id", l->id);
                blobmsg_add_u32(&b, "priority", l->priority);
                blobmsg_add_u32(&b, "source", l->source);
-               blobmsg_add_u64(&b, "time", l->ts.tv_sec);
+               blobmsg_add_u64(&b, "time", l->ts.tv_sec * 1000LL);
                l = log_list(count, l);
                if (ustream_write(&cl->s.stream, (void *) b.head, blob_len(b.head) + sizeof(struct blob_attr), false) <= 0)
                        break;
@@ -178,10 +173,22 @@ ubus_connect_handler(struct ubus_context *ctx)
 int
 main(int argc, char **argv)
 {
+       int ch, log_size = 16;
+
        signal(SIGPIPE, SIG_IGN);
+       while ((ch = getopt(argc, argv, "S:")) != -1) {
+               switch (ch) {
+               case 'S':
+                       log_size = atoi(optarg);
+                       if (log_size < 1)
+                               log_size = 16;
+                       break;
+               }
+       }
+       log_size *= 1024;
 
        uloop_init();
-       log_init();
+       log_init(log_size);
        conn.cb = ubus_connect_handler;
        ubus_auto_connect(&conn);
        uloop_run();