From patchwork Thu May 12 12:09:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dbugnar X-Patchwork-Id: 621453 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3r5Bg43Csnz9sD3 for ; Thu, 12 May 2016 22:11:44 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=TkQx6eY8; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b0pRU-0003PZ-NW; Thu, 12 May 2016 12:10:12 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b0pRQ-00035r-Lc for lede-dev@bombadil.infradead.org; Thu, 12 May 2016 12:10:08 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by merlin.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1b0pRP-0002dX-1B for lede-dev@lists.infradead.org; Thu, 12 May 2016 12:10:07 +0000 Received: by mail-wm0-x243.google.com with SMTP id w143so15649059wmw.3 for ; Thu, 12 May 2016 05:09:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JiKb2TDRjLPcVqxYTD6ztRUjGOVkNdZtoxSzrNrr0cs=; b=TkQx6eY8ZHnjOUrQfP2x52CNFg/Y1b7+VL3JDekkx/4m+8nWx1Ata87h7BTe+YAKFh ox7F4vqjgZbalvobFuSNQHXkE/rn9B3QdQWEWY7dIKemP06QsTVphJaiDshu+T3f24I+ EstL9vQtitnL5+/QI2VcNXO1Wf4XIeAmmN7ZiZC/zEdF1YHBtiX5DLHOno+jhcIZ4OHa Lqyl4VRE2x1OepXiyyEzW918HkHQXSHhTsIKX+8K2k30OvA9rKlLHTv5Xwq+1mOk0i1g +eD36ltjTK6s9jJYzgPiHoqIY7D/kL5T/CGbKYLyPIc7muh+masXAggVAA5TVsJ14olZ u1vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JiKb2TDRjLPcVqxYTD6ztRUjGOVkNdZtoxSzrNrr0cs=; b=lnc/MnSvmXC/PEiFMcidGIDqrO0Y8c8b0W4mQP4YqXttS9Ru5UMvJNIMNqTxHwIkG2 d+4v7v56DDKnf5YXGvMJrzMJ5kJ+cHg4ZjLrza3r3HChDtgPRx1MiBAzIWqfLKdEbbdL q/Qs5n3tFxDTe/pSRCjlGUXTLub1lIxtNSEjuyFGPl/AOwCH+gcULpdJd/cQgJk6gJsq NOLkBX95ETzg5Dcuvm6UHYSDAKNbwTTIUukBSkhLJlRjt6r2yurl9UufCSARuV2Q6W4J 6nJ24OMNHjtn3pLeiSeNeYcQoqcIBQu6qYuHjitaRuG+V7uF6aPq4YZY/HI0NkYcBWRc Y49A== X-Gm-Message-State: AOPr4FUEFinpy9hAjxgfFMm7Ok5VvlY5WqSwGift4OJtXaa61St5PHuTlPn/rSZPoR1W6g== X-Received: by 10.28.230.137 with SMTP id e9mr10832481wmi.0.1463054983967; Thu, 12 May 2016 05:09:43 -0700 (PDT) Received: from localhost.localdomain ([5.2.198.78]) by smtp.gmail.com with ESMTPSA id m3sm12891266wjc.27.2016.05.12.05.09.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 May 2016 05:09:43 -0700 (PDT) From: Dan Bugnar X-Google-Original-From: Dan Bugnar To: lede-dev@lists.infradead.org Date: Thu, 12 May 2016 15:09:04 +0300 Message-Id: <1463054944-6207-2-git-send-email-dnbugnar@ocedo.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1463054944-6207-1-git-send-email-dnbugnar@ocedo.com> References: <1463054944-6207-1-git-send-email-dnbugnar@ocedo.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160512_081007_216054_DE2D97C1 X-CRM114-Status: GOOD ( 18.53 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.1 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:243 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (danutbug[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Subject: [LEDE-DEV] [PATCH 2/2] [ubox] logd: add ubus reload method X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dan Bugnar MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Dan Bugnar Add logd link to uci library, to read the system config file and get the buffer size. Remove the -S option support and use just the option from the config file. Signed-off-by: Dan Bugnar --- CMakeLists.txt | 2 +- log/logd.c | 60 ++++++++++++++++++++++++++++++++++++++++++++-------------- log/syslog.c | 8 +------- log/syslog.h | 2 +- 4 files changed, 49 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 834b5b6..b635c4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ INSTALL(TARGETS validate_data ) ADD_EXECUTABLE(logd log/logd.c log/syslog.c) -TARGET_LINK_LIBRARIES(logd ubox ubus) +TARGET_LINK_LIBRARIES(logd ubox ubus uci) INSTALL(TARGETS logd RUNTIME DESTINATION sbin ) diff --git a/log/logd.c b/log/logd.c index 27d3cac..6e493d0 100644 --- a/log/logd.c +++ b/log/logd.c @@ -23,9 +23,14 @@ #include #include #include +#include #include "syslog.h" +#define SYSTEM_CONFIG_PATH "/etc/config" +#define SYSTEM_CONFIG "system" +#define LOG_DEFAULT_SIZE 16 + int debug = 0; static struct blob_buf b; static struct ubus_auto_conn conn; @@ -124,9 +129,48 @@ write_log(struct ubus_context *ctx, struct ubus_object *obj, return 0; } +static void +config_reload() +{ + struct uci_context *ctx; + struct uci_package *p; + struct uci_element *e; + int size = LOG_DEFAULT_SIZE; + + ctx = uci_alloc_context(); + if (!ctx) { + fprintf(stderr, "Could not allocate memory for config\n"); + exit(-1); + } + ctx->flags &= ~UCI_FLAG_STRICT; + uci_set_confdir(ctx, SYSTEM_CONFIG_PATH); + if (uci_load(ctx, SYSTEM_CONFIG, &p) == 0){ + uci_foreach_element(&p->sections, e){ + struct uci_section *s = uci_to_section(e); + if (strcmp(s->type, "system") == 0){ + const char *buffer_size = uci_lookup_option_string(ctx, s, "log_buffer_size"); + if (buffer_size != NULL) + size = atoi(buffer_size); + break; + } + } + } + uci_free_context(ctx); + log_buffer_reinit(size * 1024); +} + +static int +reload_log(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + config_reload(); + 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 }, }; static struct ubus_object_type log_object_type = @@ -176,22 +220,10 @@ 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_size); + config_reload(); + log_init(); 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);