logd: allow setting the buffer size from the command line
authorJohn Crispin <blogic@openwrt.org>
Sun, 19 Jan 2014 18:32:58 +0000 (18:32 +0000)
committerJohn Crispin <blogic@openwrt.org>
Sun, 19 Jan 2014 18:32:58 +0000 (18:32 +0000)
Signed-off-by: John Crispin <blogic@openwrt.org>
log/logd.c
log/syslog.c
log/syslog.h

index 978d7d1..cbaf219 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <stdio.h>
 #include <syslog.h>
 
 #include <stdio.h>
 #include <syslog.h>
+#include <unistd.h>
 
 #include <linux/types.h>
 
 
 #include <linux/types.h>
 
@@ -169,12 +170,24 @@ ubus_connect_cb(struct uloop_timeout *timeout)
 int
 main(int argc, char **argv)
 {
 int
 main(int argc, char **argv)
 {
+       int ch, log_size = 0;
+
        signal(SIGPIPE, SIG_IGN);
 
        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 = 1;
+                       log_size *= 1024;
+                       break;
+               }
+       }
        uloop_init();
        ubus_timer.cb = ubus_connect_cb;
        uloop_timeout_set(&ubus_timer, 1000);
        uloop_init();
        ubus_timer.cb = ubus_connect_cb;
        uloop_timeout_set(&ubus_timer, 1000);
-       log_init();
+       log_init(log_size);
        uloop_run();
        if (_ctx)
                ubus_free(_ctx);
        uloop_run();
        if (_ctx)
                ubus_free(_ctx);
index fcc4a74..4cabb43 100644 (file)
@@ -274,8 +274,11 @@ log_buffer_init(int size)
 }
 
 void
 }
 
 void
-log_init(void)
+log_init(int _log_size)
 {
 {
+       if (_log_size > 0)
+               log_size = _log_size;
+
        regcomp(&pat_prio, "^<([0-9]*)>(.*)", REG_EXTENDED);
        regcomp(&pat_tstamp, "^\[[ 0]*([0-9]*).([0-9]*)] (.*)", REG_EXTENDED);
 
        regcomp(&pat_prio, "^<([0-9]*)>(.*)", REG_EXTENDED);
        regcomp(&pat_tstamp, "^\[[ 0]*([0-9]*).([0-9]*)] (.*)", REG_EXTENDED);
 
index dc712ff..b682ced 100644 (file)
@@ -30,7 +30,7 @@ struct log_head {
        char data[];
 };
 
        char data[];
 };
 
-void log_init(void);
+void log_init(int log_size);
 void log_shutdown(void);
 
 typedef void (*log_list_cb)(struct log_head *h);
 void log_shutdown(void);
 
 typedef void (*log_list_cb)(struct log_head *h);