From patchwork Sat Jul 22 15:43:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaev Ruslan X-Patchwork-Id: 1811300 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ktgBSmjl; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=Rwe8xbXW; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R7W4D1lLyz20FK for ; Sun, 23 Jul 2023 01:46:19 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=6k/ezMnNxz6DdC/Pp6SrQib95Ght1d2ro03Xg33Szmw=; b=ktg BSmjlaZFWX7i6Y4k1kFDd/Pgy3Ly2fHgN+OAp7w7nO5XbFoPtybSyBe+vvMEKBw4BSnOXVyE0C5DJ 56kDa/E3v3IYRu+fdCMYCaiTACWFqGzIliK7XPfKzyKLP8tP6nAH1YnDJwXB5jJL8AF2QRqL7df0T KqRvUOp7YuSqPyDIlAsPMpmgzETXX4WErrMmQMkqhLfnKc0ug/YoyLrLgKtfUsTJu3anktD8OdSCI V8iDc0tMa0twduyJRK+n7TxvPh/v93xw0A27784HLTCi9doEGnwB1Nnv9R/KFU87tCtapJP97c1nh EnyENe2Hp24zYd1+DdSKwdEvRkF0qqQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qNEmC-00GwMa-1v; Sat, 22 Jul 2023 15:44:12 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qNEmA-00GwM5-0E for openwrt-devel@lists.openwrt.org; Sat, 22 Jul 2023 15:44:11 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-668704a5b5bso2700831b3a.0 for ; Sat, 22 Jul 2023 08:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690040647; x=1690645447; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=IL+rbkp/kOxQh+RZ3ldcgHUp4gtCwN3rWkNOYpWJpp4=; b=Rwe8xbXW065uCND4tFemKH0jV1B0sS+jOluhoIpx0AbtQN0sjK51vjF1jIuk3+cc0R DSjppCLI4cnNH/z6pX1tfsp2NHwkgs8YnqzsdFwe75Etx9/ftcnFFU0bPZLVH/zC6p+y yFqbPZ2CfESvtV9EAYcDiDezClqMnBSPeRs4CWfu2lbz9XwKRQZcb7KotDcgDrTXQT8z HiQZSBwSn199+j5T7pnv0wPbzIdrXUSxkbbuHNKbrUKt1hJFlPOSZ/6FiUiFBVC/7bkG 0nQKucwifauvIxJF8Njl+wG4OrriNzlPOb5bAaXD2duIvG1n8bdrB8Mr8/QnGq2NZhq7 7hoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690040647; x=1690645447; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=IL+rbkp/kOxQh+RZ3ldcgHUp4gtCwN3rWkNOYpWJpp4=; b=TFLP8x6uNrTI8xzaHRCg1d4KcYooA+spK8j9il5JeIHY8m/xYSytABsUfKyToXlH4f /08QuiPJj4AkeP60A523/AwjnXIfIU1M4CcUZTw+jJn+vcAqD/enhFshQN/UTARA+nJb wSVUn2/jtSDNNJB/oG3vsMEX3/TlJlAR8XcstFtNYK8PZwhIgL7a7fkzDSqw8WOFX8w2 RfS16Vk+tXdYtfdHwncYSnWTsI60m9H/eOBnBZ+DY+URU0amnhE+kwn97UwSPVX11YOq PmdFAQWKAHMADbpsuhsaXjJ7JRm1Rtw0lBSyKCApYzCOdfZfldnvAaWF2gcezfdxZTA5 69cw== X-Gm-Message-State: ABy/qLa7v/cCtjkzZhcMSGhqUfzqnYF1CYi2LpzWVJa+2QCVK9zyXKat /ZD9xpQifcuW/Xg1y7a0QiS6fWpvxAmjgbfgUd6Vjymz90oeBGIi X-Google-Smtp-Source: APBJJlFUDya61/9nU/aP0oHg6uPmAGk1EmrG1gmsW1SI7es6kC7SaC/e/ZP75H1N16XFKZ0Mz2cQ/TXpu6+T6dLRVL4= X-Received: by 2002:a17:90a:d710:b0:267:f703:8de with SMTP id y16-20020a17090ad71000b00267f70308demr1945160pju.17.1690040647584; Sat, 22 Jul 2023 08:44:07 -0700 (PDT) MIME-Version: 1.0 From: Legale Legale Date: Sat, 22 Jul 2023 18:43:55 +0300 Message-ID: Subject: [PATCH] ubox: logread add option to filter priority (log level) To: openwrt-devel@lists.openwrt.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230722_084410_132704_12020A8A X-CRM114-Status: GOOD ( 10.79 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This adds an ability to filter log messages priority: -v handle only messages with given log level (0-7), repeatable -V ignore messages with given log level (0-7), repeatable Signed-off-by: Isaev Ruslan --- log/logread.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42e listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [legale.legale[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This adds an ability to filter log messages priority: -v handle only messages with given log level (0-7), repeatable -V ignore messages with given log level (0-7), repeatable Signed-off-by: Isaev Ruslan --- log/logread.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) " -z handle only messages with given facility (0-23), repeatable\n" " -Z ignore messages with given facility (0-23), repeatable\n" " -f Follow log messages\n" @@ -313,7 +330,7 @@ int main(int argc, char **argv) signal(SIGPIPE, SIG_IGN); - while ((ch = getopt(argc, argv, "u0fcs:l:z:Z:r:F:p:S:P:h:e:t")) != -1) { + while ((ch = getopt(argc, argv, "u0fcs:l:v:V:z:Z:r:F:p:S:P:h:e:t")) != -1) { switch (ch) { case 'u': log_udp = 1; @@ -343,6 +360,14 @@ int main(int argc, char **argv) case 'l': lines = atoi(optarg); break; + case 'v': + id = strtoul(optarg, NULL, 0) & 0x1f; + loglevel_include |= (1 << id); + break; + case 'V': + id = strtoul(optarg, NULL, 0) & 0x1f; + loglevel_exclude |= (1 << id); + break; case 'z': id = strtoul(optarg, NULL, 0) & 0x1f; facility_include |= (1 << id); -- 2.30.2 diff --git a/log/logread.c b/log/logread.c index f48dd4b..91aae00 100644 --- a/log/logread.c +++ b/log/logread.c @@ -66,6 +66,8 @@ static int log_type = LOG_STDOUT; static int log_size, log_udp, log_follow, log_trailer_null = 0; static int log_timestamp; static int logd_conn_tries = LOGD_CONNECT_RETRY; +static int loglevel_include; +static int loglevel_exclude; static int facility_include; static int facility_exclude; @@ -79,6 +81,16 @@ static int check_facility_filter(int f) return 1; } +/* check for loglevel filter; return 0 if message shall be dropped */ +static int check_loglevel_filter(int f) +{ + if (loglevel_include) + return !!(loglevel_include & (1 << f)); + if (loglevel_exclude) + return !(loglevel_exclude & (1 << f)); + return 1; +} + static const char* getcodetext(int value, CODE *codetable) { CODE *i; @@ -155,6 +167,9 @@ static int log_notify(struct blob_attr *msg) if (!check_facility_filter(LOG_FAC(p))) return 0; + + if (!check_loglevel_filter(LOG_PRI(p))) + return 0; m = blobmsg_get_string(tb[LOG_MSG]); if (regexp_pattern && @@ -233,6 +248,8 @@ static int usage(const char *prog) " -p PID file\n" " -h Add hostname to the message\n" " -P Prefix custom text to streamed messages\n" + " -v handle only messages with given log level (0-7), repeatable\n" + " -V ignore messages with given log level (0-7), repeatable\n"