From patchwork Fri Apr 5 03:36:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaev Ruslan X-Patchwork-Id: 1920033 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=qxA2ToDZ; 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=lUK8V7nz; 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 4V9l330KqYz1yZH for ; Fri, 5 Apr 2024 14:53:50 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Date:From:To: Message-ID: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=sGSjqEgeXkJPeQeGs+HR6xdJgyHxHKed/yA8Xl+I020=; b=qxA2ToDZ3wS2i0 Lr5UfwBZCN11uweCu2zCwEpZaPTjNNfOhpiF+LaRnXhq33FWCSX1n41o8PWtKDKf9qSB40pHsQzQD fNClU1+AzD/1G2Z+CKnZObSXIdfmukZ9ZXfVr//Taoo9iROiqIC7YSp9It80p8jf/yJuYDucWpHV3 9CWoM8xc4GHfyda39Dok2wwTC5433vZCwuHWQHmnjRRALc1H32lDjbsKEJmaPP65zAI7GifVcsqZs 5rDpWLM1cq7fd/FcflKSZSL2lZVfMkQDBN3h6L5NvkzeILd9HzQNN/RIM4573bkYn4T0diKSZOOQ9 tB+X5Zrm0Al4BnYHV9JQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsadF-000000055Jb-1Z8F; Fri, 05 Apr 2024 03:52:49 +0000 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsadC-000000055J5-0Nkb for openwrt-devel@lists.openwrt.org; Fri, 05 Apr 2024 03:52:47 +0000 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2d700beb6beso18933761fa.2 for ; Thu, 04 Apr 2024 20:52:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712289164; x=1712893964; darn=lists.openwrt.org; h=subject:date:from:to:message-id:from:to:cc:subject:date:message-id :reply-to; bh=auoDDrbpkZ9tKJO8KqQLYWyCKFVaS2Np4l077LiyR1I=; b=lUK8V7nzE1a9msM3y0NBd6D/vH50znkPBvGfZOcsdy3ed5Jxg2zj7rEw0nVrs/d5oW 5d2RPcjsRA57JzUFP9IOFdzucqDrOniuK3gwzf16clcUd/3uXOZj+j7x+56P4yLJ5R/u osP3tVDopNrgpWOTCvjqtLWMcwptgrL9zUgFaazSPRXqIbEbxZs/l7CwlIT3MHE03GFx YRw0/0C/kfyVa+zKyIcs28oFxA6XaFGSBnVvigIxoBWzchDL7EL3vOvHHrFDfgDjdvdW dCE4RiB3M0aYLFgkZ5wvYxxiemnOiDwRKRxywHd+KdWyBDlUCrV3qLJ/8v8MEUqs8h8q fxOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712289164; x=1712893964; h=subject:date:from:to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=auoDDrbpkZ9tKJO8KqQLYWyCKFVaS2Np4l077LiyR1I=; b=vPUY54JTTdXLOPEitjzmMS/EPf7Pz+SljYjvwOyhKctkpZ23gnpps+3+Jmk0/Fc1Y2 SlqT4iIlJsmBJJ2bQT0Rla41wNIfELCQmaMm7GXAsl2WnZriBMm4KHe0DRbpw9rTehEZ dAJUJ8wkc0Vn/oUh9d7vrmobKZxEdGAUBXMQo0bnfiUh7UYQiYkrb1Lyjh00km9y7n3Y d4TyXpzJVgde+rjOMlJTRTC/MRLfd3GzD01Zrjso5jim+7PFq5UebjUGTf5wU9wrC0ea ReNdlbpXkMvGW7xM3zEy30bMZKRopEsGNpJLHOl46XiWjrzG/2b1yR89q+H7dV991ZfI hu/Q== X-Gm-Message-State: AOJu0Yw1v1uj9Kme0VRG7kigk5ol5w40mZCb0z3N9vGvS2nDMEREPYHz onKzTquVBIFbYfd6XvRyVvSgxhga1Fk8yDyCudgfhzI3pfBrNDFr X-Google-Smtp-Source: AGHT+IE65ohUVQdKaxvAny2MKN0rMNKrEgDU/ZPfGevs4NpihxnaXnALzFm5rcGw9zCAqWESM9MaJQ== X-Received: by 2002:a19:ac07:0:b0:513:5fb0:c5ad with SMTP id g7-20020a19ac07000000b005135fb0c5admr133795lfc.17.1712289163851; Thu, 04 Apr 2024 20:52:43 -0700 (PDT) Received: from localhost (nat-inorg.chem.msu.ru. [93.180.12.29]) by smtp.gmail.com with ESMTPSA id f11-20020a05651201cb00b00516a8c43f93sm78265lfp.169.2024.04.04.20.52.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 20:52:43 -0700 (PDT) Message-ID: To: openwrt-devel@lists.openwrt.org, John Crispin From: Isaev Ruslan Date: Fri, 5 Apr 2024 06:36:38 +0300 Subject: [PATCH v3] ubox: libubox: logread: add filter logread messages by priority rsyslog related X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240404_205246_375506_0054E24B X-CRM114-Status: GOOD ( 11.74 ) 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: branch: master d413903 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 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 [2a00:1450:4864:20:0:0:0:22b 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.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [legale.legale(at)gmail.com] 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: , MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org branch: master d413903 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 This function is primarily needed to limit the messages sent to rsyslog from the system log (performed using logread) by message priority levels, for example, by sending messages only up to the LOG_ERR or LOG_WARNING levels. changes: v1: initial patch v2: whitespaces cleanup v3: change commit message topic Signed-off-by: Isaev Ruslan --- log/logread.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/log/logread.c b/log/logread.c index f48dd4b..87ec873 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; @@ -156,6 +168,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 && regexec(®exp_preg, m, 0, NULL, 0) == REG_NOMATCH) @@ -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 (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);