From patchwork Thu May 12 12:09:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dbugnar X-Patchwork-Id: 621452 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 3r5Bfw1wZBz9sD3 for ; Thu, 12 May 2016 22:11:36 +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=EEYL50Fp; 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 1b0pRd-00048i-PO; Thu, 12 May 2016 12:10:21 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b0pRI-0002AY-4Q for lede-dev@lists.infradead.org; Thu, 12 May 2016 12:10:17 +0000 Received: by mail-wm0-x242.google.com with SMTP id e201so15704612wme.2 for ; Thu, 12 May 2016 05:09:39 -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; bh=eyK1agq0qByFilV453qp7hI3zJXRBphtXIpHYC7Ycg0=; b=EEYL50FpuZo8GXF12UM2FWvspS8FC9RyJQxDmjVGrmtEmNiH8Y5rFAtf53IJN7QIMM YCCfsybBcM566ffeDCpnRQ4Il2bEMOnMI97lr2mb19q9l+smPC83kJDEXgUl7wWT0ppW j7FmPCLEMF68lXYcACC+d22nqBM8Hl8CZCgGqftBV7LVjX5Y22kgQGtzCCS44A+V8Bct GakYMZkfLauO1joYaV/rTFEbObKF/o6+TG9OcvReFygwyxdVdGPZD1Gvx2+pJoc1wB+b L4EEhwbujaj2SsvsHefP2GJN0aV1NBsB2m1UVRwv/42v+Q4DXOPjRvG3Bo4dVfrhxi4B VAYA== 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; bh=eyK1agq0qByFilV453qp7hI3zJXRBphtXIpHYC7Ycg0=; b=G8X7au/Tn6Z82bMaj3I1tl5JLTlAYFhnoML97ZNyzxQLkjVpOYSRWIdzuYAOIOmaBu VQitED+TMss/+g8FviAZ+n1pKT1XX7flSrpshcggYQtPTnMpirqaU6KiSNPRBG+iDEsg k9x6PPF6DAC246+z02H3PYXJ1wfTC+81TOVzXPpV6aHCtTvMBYA2CwYsSe1nmh0ZYgXi ivQGZbfifOmnl25QqaolSAO0N6kqyp0IT2luxgHqPKlDxDl4ME0x31mngtfeM8O4PaYV PZjepTjqj88YPPrGEpCcdTygdTpazGExe/w69FNj+zVzb/uBAMVx4BO89YtsoDcNce5P nzwA== X-Gm-Message-State: AOPr4FXoyteaYUdGWkWPgeeCr1j8kV5t0o7ix4+rvAcAzccSP3a7lg66J/ug8AtOHjTW/Q== X-Received: by 10.28.63.148 with SMTP id m142mr9759943wma.85.1463054978503; Thu, 12 May 2016 05:09:38 -0700 (PDT) Received: from localhost.localdomain ([5.2.198.78]) by smtp.gmail.com with ESMTPSA id m3sm12891266wjc.27.2016.05.12.05.09.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 May 2016 05:09:37 -0700 (PDT) From: Dan Bugnar X-Google-Original-From: Dan Bugnar To: lede-dev@lists.infradead.org Date: Thu, 12 May 2016 15:09:03 +0300 Message-Id: <1463054944-6207-1-git-send-email-dnbugnar@ocedo.com> X-Mailer: git-send-email 2.8.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160512_051000_641011_B8C3B301 X-CRM114-Status: GOOD ( 13.39 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.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:242 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 1/2] [ubox] syslog: use realloc to change log buffer size 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 Change the log buffer size and copy the messages. Signed-off-by: Dan Bugnar --- log/syslog.c | 37 +++++++++++++++---------------------- log/syslog.h | 2 +- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/log/syslog.c b/log/syslog.c index e8b6774..d6cb868 100644 --- a/log/syslog.c +++ b/log/syslog.c @@ -42,7 +42,7 @@ #define PAD(x) (x % 4) ? (((x) - (x % 4)) + 4) : (x) static char *log_dev = LOG_DEFAULT_SOCKET; -static int log_size = LOG_DEFAULT_SIZE; +static int log_size = 0; static struct log_head *log, *log_end, *oldest, *newest; static int current_id = 0; static regex_t pat_prio; @@ -237,34 +237,30 @@ log_list(int count, struct log_head *h) } int -log_buffer_init(int size) +log_buffer_reinit(int size) { - struct log_head *_log = malloc(size); + if (size <= 0) + size = LOG_DEFAULT_SIZE; + if (log_size == size) + return 0; + + struct log_head *_log = realloc(log, size); if (!_log) { + oldest = newest = log = NULL; fprintf(stderr, "Failed to initialize log buffer with size %d\n", log_size); return -1; } - memset(_log, 0, size); - if (log && ((log_size + sizeof(struct log_head)) < size)) { - struct log_head *start = _log; - struct log_head *end = ((void*) _log) + size; - struct log_head *l; - - l = log_list(0, NULL); - while ((start < end) && l && l->size) { - memcpy(start, l, PAD(sizeof(struct log_head) + l->size)); - start = (struct log_head *) &l->data[PAD(l->size)]; - l = log_list(0, l); - } - free(log); - newest = start; + newest = (_log + (newest - log)); newest->size = 0; - oldest = log = _log; + memset(newest, 0, size - log_size); + oldest = (_log + (oldest - log)); + log = _log; log_end = ((void*) log) + size; } else { + memset(_log, 0, size); oldest = newest = log = _log; log_end = ((void*) log) + size; } @@ -276,13 +272,10 @@ log_buffer_init(int size) 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); - if (log_buffer_init(log_size)) { + if (log_buffer_reinit(_log_size)) { fprintf(stderr, "Failed to allocate log memory\n"); exit(-1); } diff --git a/log/syslog.h b/log/syslog.h index 81a039f..ed5a41b 100644 --- a/log/syslog.h +++ b/log/syslog.h @@ -35,7 +35,7 @@ void log_shutdown(void); typedef void (*log_list_cb)(struct log_head *h); struct log_head* log_list(int count, struct log_head *h); -int log_buffer_init(int size); +int log_buffer_reinit(int size); void log_add(char *buf, int size, int source); void ubus_notify_log(struct log_head *l);