From patchwork Mon Jun 6 15:59:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9158705 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A520F60573 for ; Mon, 6 Jun 2016 16:01:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96CF720700 for ; Mon, 6 Jun 2016 16:01:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B7E626B41; Mon, 6 Jun 2016 16:01:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 357FF20700 for ; Mon, 6 Jun 2016 16:01:52 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b9wwS-0007Lg-3P; Mon, 06 Jun 2016 15:59:52 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b9wwQ-0007KI-Ju for xen-devel@lists.xenproject.org; Mon, 06 Jun 2016 15:59:50 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id 93/4E-14119-5FD95575; Mon, 06 Jun 2016 15:59:49 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjkeJIrShJLcpLzFFi42JxWrrBXvfr3NB wgyedqhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8a3rQtYCt5JVEyZw9bAuF2ki5GTQ0LAX+JK 60tWEJtNQFniZ2cvG4gtIqAn0XTgOSOIzSzgJfFjRQ97FyMHh7CAo8TWpYUgYRYBFYk5x1czg 9i8As4SrWu2MUGMlJM4f/wnWJxTwEXifN9XdhBbCKhm7q15ULaCRMf0Y0wQvYISJ2c+YYFYJS Fx8MULZpBVEgLcEn+77Scw8s1CUjULSdUCRqZVjBrFqUVlqUW6hqZ6SUWZ6RkluYmZObqGBqZ 6uanFxYnpqTmJScV6yfm5mxiB4cQABDsYG7Z7HmKU5GBSEuXd0R8aLsSXlJ9SmZFYnBFfVJqT WnyIUYaDQ0mC1xgYnkKCRanpqRVpmTnAwIZJS3DwKInwloGkeYsLEnOLM9MhUqcYFaXEeR1BE gIgiYzSPLg2WDRdYpSVEuZlBDpEiKcgtSg3swRV/hWjOAejkjAvH8gUnsy8Erjpr4AWMwEtXn YtGGRxSSJCSqqBseDSLQZjP1450amr93xZzJlSvvnKT4f5xXfzbkXJeVfP366zhXlCRqDM0rv sz3+Jtyw81h7iqbeUs3f675u7500VsYp/OjHf7xmXSn3M9zSjQyet1eJvuC/wehojP2/q1WMF BheN+Js9Hu20m6u20tgk8mGjfuQTg9wlSX4yv9f1la734LoXpsRSnJFoqMVcVJwIAICVyV6hA gAA X-Env-Sender: prvs=9584f9c1d=wei.liu2@citrix.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1465228787!31248668!2 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 64047 invoked from network); 6 Jun 2016 15:59:49 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-11.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 6 Jun 2016 15:59:49 -0000 X-IronPort-AV: E=Sophos;i="5.26,427,1459814400"; d="scan'208";a="365531461" From: Wei Liu To: Xen-devel Date: Mon, 6 Jun 2016 16:59:40 +0100 Message-ID: <1465228781-22754-6-git-send-email-wei.liu2@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1465228781-22754-1-git-send-email-wei.liu2@citrix.com> References: <1465228781-22754-1-git-send-email-wei.liu2@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Wei Liu , Ian Jackson Subject: [Xen-devel] [PATCH 5/6] xenconsoled: options to control log rotation X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Provide two options: one to control the maximum number of copies kept and the other to control the maximum length of each log file. Signed-off-by: Wei Liu --- tools/console/daemon/logfile.c | 11 +++++++---- tools/console/daemon/main.c | 13 ++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tools/console/daemon/logfile.c b/tools/console/daemon/logfile.c index ad73f8e..3b95f84 100644 --- a/tools/console/daemon/logfile.c +++ b/tools/console/daemon/logfile.c @@ -25,6 +25,9 @@ #include "utils.h" #include "logfile.h" +extern unsigned int log_backups; +extern unsigned int log_max_len; + static void logfile_entry_free(struct logfile_entry *entry) { if (!entry) return; @@ -91,7 +94,7 @@ struct logfile *logfile_new(const char *path, mode_t mode) } logfile->mode = mode; - logfile->maxlen = LOGFILE_MAX_SIZE; + logfile->maxlen = log_max_len; logfile->entry = logfile_entry_new(logfile->basepath, mode); @@ -112,13 +115,13 @@ static int logfile_rollover(struct logfile *file) unsigned i; if (asprintf(&next, "%s.%u", file->basepath, - LOGFILE_MAX_BACKUP_NUM) < 0) { + log_backups) < 0) { dolog(LOG_ERR, "Failed to asprintf %s.%u", - file->basepath, LOGFILE_MAX_BACKUP_NUM); + file->basepath, log_backups); goto err; } - for (i = LOGFILE_MAX_BACKUP_NUM; i > 0; i--) { + for (i = log_backups; i > 0; i--) { if (i == 1) { this = strdup(file->basepath); if (!this) { diff --git a/tools/console/daemon/main.c b/tools/console/daemon/main.c index 23860d3..dd338ae 100644 --- a/tools/console/daemon/main.c +++ b/tools/console/daemon/main.c @@ -31,6 +31,7 @@ #include "utils.h" #include "io.h" +#include "logfile.h" int log_reload = 0; int log_guest = 0; @@ -39,6 +40,8 @@ int log_time_hv = 0; int log_time_guest = 0; char *log_dir = NULL; int discard_overflowed_data = 1; +unsigned int log_backups = LOGFILE_MAX_BACKUP_NUM; +unsigned int log_max_len = LOGFILE_MAX_SIZE; static void handle_hup(int sig) { @@ -47,7 +50,7 @@ static void handle_hup(int sig) static void usage(char *name) { - printf("Usage: %s [-h] [-V] [-v] [-i] [--log=none|guest|hv|all] [--log-dir=DIR] [--pid-file=PATH] [-t, --timestamp=none|guest|hv|all] [-o, --overflow-data=discard|keep]\n", name); + printf("Usage: %s [-h] [-V] [-v] [-i] [--log=none|guest|hv|all] [--log-dir=DIR] [--pid-file=PATH] [--log-backups=NUM] [--log-max-len=NUM] [-t, --timestamp=none|guest|hv|all] [-o, --overflow-data=discard|keep]\n", name); } static void version(char *name) @@ -100,6 +103,8 @@ int main(int argc, char **argv) { "interactive", 0, 0, 'i' }, { "log", 1, 0, 'l' }, { "log-dir", 1, 0, 'r' }, + { "log-backups", 1, 0, 'n' }, + { "log-max-len", 1, 0, 'm' }, { "pid-file", 1, 0, 'p' }, { "timestamp", 1, 0, 't' }, { "overflow-data", 1, 0, 'o'}, @@ -144,6 +149,12 @@ int main(int argc, char **argv) case 'r': log_dir = strdup(optarg); break; + case 'n': + log_backups = strtoul(optarg, 0, 0); + break; + case 'm': + log_max_len = strtoul(optarg, 0, 0); + break; case 'p': pidfile = strdup(optarg); break;