From: Dan Bugnar <danut...@gmail.com> Add ubus method to set the buffer size.
Signed-off-by: Dan Bugnar <danut...@gmail.com> --- log/logd.c | 28 +++++++++++++++++++++++++++- log/syslog.c | 8 +------- log/syslog.h | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/log/logd.c b/log/logd.c index 27d3cac..93ca0e8 100644 --- a/log/logd.c +++ b/log/logd.c @@ -26,11 +26,16 @@ #include "syslog.h" +#define LOG_DEFAULT_SIZE 16 * 1024 + int debug = 0; static struct blob_buf b; static struct ubus_auto_conn conn; static LIST_HEAD(clients); +static const struct blobmsg_policy reload_policy = + { .name = "log_buffer_size", .type = BLOBMSG_TYPE_INT32 }; + static const struct blobmsg_policy read_policy = { .name = "lines", .type = BLOBMSG_TYPE_INT32 }; @@ -124,9 +129,29 @@ write_log(struct ubus_context *ctx, struct ubus_object *obj, return 0; } +static int +reload_log(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct blob_attr *tb; + int size = 0; + + if (msg) { + blobmsg_parse(&reload_policy, 1, &tb, blob_data(msg), blob_len(msg)); + if (tb) { + size = blobmsg_get_u32(tb); + log_buffer_reinit(size < 1 ? LOG_DEFAULT_SIZE : size * 1024); + } + } + + return 0; +} + static const struct ubus_method log_methods[] = { { .name = "read", .handler = read_log, .policy = &read_policy, .n_policy = 1 }, { .name = "write", .handler = write_log, .policy = &write_policy, .n_policy = 1 }, + { .name = "reload", .handler = reload_log, .policy = &reload_policy, .n_policy = 1 }, }; static struct ubus_object_type log_object_type = @@ -191,7 +216,8 @@ main(int argc, char **argv) log_size *= 1024; uloop_init(); - log_init(log_size); + log_init(); + log_buffer_reinit(log_size); conn.cb = ubus_connect_handler; ubus_auto_connect(&conn); uloop_run(); diff --git a/log/syslog.c b/log/syslog.c index d6cb868..683eeb8 100644 --- a/log/syslog.c +++ b/log/syslog.c @@ -270,16 +270,10 @@ log_buffer_reinit(int size) } void -log_init(int _log_size) +log_init() { regcomp(&pat_prio, "^<([0-9]*)>(.*)", REG_EXTENDED); regcomp(&pat_tstamp, "^\[[ 0]*([0-9]*).([0-9]*)] (.*)", REG_EXTENDED); - - if (log_buffer_reinit(_log_size)) { - fprintf(stderr, "Failed to allocate log memory\n"); - exit(-1); - } - syslog_open(); klog_open(); openlog("sysinit", LOG_CONS, LOG_DAEMON); diff --git a/log/syslog.h b/log/syslog.h index ed5a41b..fe815b9 100644 --- a/log/syslog.h +++ b/log/syslog.h @@ -30,7 +30,7 @@ struct log_head { char data[]; }; -void log_init(int log_size); +void log_init(); void log_shutdown(void); typedef void (*log_list_cb)(struct log_head *h); -- 2.8.1 _______________________________________________ Lede-dev mailing list Lede-dev@lists.infradead.org http://lists.infradead.org/mailman/listinfo/lede-dev