From patchwork Tue Nov 21 19:19:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaev Ruslan X-Patchwork-Id: 1867015 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=xiHU+wxM; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=CYuBLBB1; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SZZ6H60x3z1yRg for ; Wed, 22 Nov 2023 06:23:19 +1100 (AEDT) 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=3Bb0Oy5d6wu3LD4AmrKKMwAOW+cXRRxo5QZRvfxJk7Q=; b=xiH U+wxMnkUCtZtHK5/JritAoUw1eNRtdMi5pCZNT2FWjo6wmQc6n5d7nQn2RIBRk8xlsR+KjhOQDeze Dni2+kDT/1o0fMQHYihWxxSM43kwqcjxyD+j1vkX0Czo9kwNsIYEV+LQ9LgpW02w6bBNSM/kzzmgB HOvPhV9jald0Lsx/+aBhKYjxtK7hDdBqIlQOJMN7RJ0uRSwAIxh19/zC7NfJfNq1MIKCkhBP7WJpZ trA3oMH1ZSB3RCXLToqQWphePdpYYC5EKslFssh51a4jzvkPS5RgZqx6cB+IpIippZJuhbhn5n6pT 1Qsg69ByODoBMbo4+BHiBIsuIAK5Imw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r5WHl-00HYMj-0L; Tue, 21 Nov 2023 19:19:49 +0000 Received: from mail-ua1-x929.google.com ([2607:f8b0:4864:20::929]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r5WHh-00HYLq-1a for openwrt-devel@lists.openwrt.org; Tue, 21 Nov 2023 19:19:46 +0000 Received: by mail-ua1-x929.google.com with SMTP id a1e0cc1a2514c-7bb44339bf7so1403128241.0 for ; Tue, 21 Nov 2023 11:19:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700594382; x=1701199182; darn=lists.openwrt.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=qAYudx1Se/gWi8MGKAuDfFosx1WkmWC7YIt0tJnkkb0=; b=CYuBLBB13LMTXLL4NeXbTD/6khXgMLfac1/dwvVBQnQZEr+Nf6ICyhI/tvKR6NYnbW b/0pRFzpEzHjFwnZ5phAPExEYLOHbp1Q4yeKZYHwG6EXfSh44JiE8aryLbj1hevM0pNB q12HDyk6BNv8mw63a8e8qWvqW4cdU202mj7vAJbFa7zL1ZL55nT9IT5U2M6vMQPTjybI AlROo/zteSoWhknvcoAdEbkeZtQdmXIg8LfiKQ/+BKv/BLz8k9Jthp5cT9IN3gDqdOc8 iYD+vYuBi6+DvXaPrkgFGHfHQ6y69+LaXVo69RSDF8hzYIxxkFTlFKRv2hwvE+FDJEhv HAWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700594382; x=1701199182; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qAYudx1Se/gWi8MGKAuDfFosx1WkmWC7YIt0tJnkkb0=; b=rHf4EL6S0rpEmZOd2jtgyezkygy4pJL9bBWNd3fE/VkRRalV6De5VyjWqFPw6GXQaa 7Z+CxU4kzqvxO9w8fDjyt1H818fakZPEgV+qcaAFfs0e03UCxBxIge5ju7R5neyVAXZb Hg9qrt3+7nCqL1MZA+KpjkvCBc+7v6QSLaLPgBW0iIBcTNZ6h93rb+ILBSfJTkJjnMuX wgwXbMj516Z/+2/6bpIjkYIipZYz7KsFMDlsJJ7bm5KVxmhefNJzBWj3FgvPfpWLN7uP M10QOW/yFAlrqLNEZEMYMyg4S2ivHyr0fGeWskjRLUOCEwtmHVK8XfP1fxO9B6QGn1IA qIkA== X-Gm-Message-State: AOJu0YyYQ++E/UYFCTOHIXyIUItmuTfIe7/keUzulIyNNZeu4O8kayuG 5lI0Bw5bXGVjKSzvlcsEvdf05px9ugAGv0eNf5STEN8Blw8ONoLI X-Google-Smtp-Source: AGHT+IEn14Xl0Q5+WhEoKYWaXqJpIpqXTTe2roYe4oIG28X96NXs/95EO9/QQkZKbrwEPSLtt1VKUMJUqnmnBC8p3Vo= X-Received: by 2002:a1f:4a42:0:b0:496:b3b7:5d4c with SMTP id x63-20020a1f4a42000000b00496b3b75d4cmr288363vka.16.1700594382631; Tue, 21 Nov 2023 11:19:42 -0800 (PST) MIME-Version: 1.0 From: Isaev Ruslan Date: Tue, 21 Nov 2023 22:19:32 +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-20231121_111945_563619_760C0E1F X-CRM114-Status: GOOD ( 10.64 ) 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:929 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(-) (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); 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" " -z handle only messages with given facility