From patchwork Tue Jul 14 06:43:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 494880 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5C49E1402AE for ; Tue, 14 Jul 2015 16:45:00 +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=FKJ2Cyll; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 9AB8028C07A; Tue, 14 Jul 2015 08:43:57 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, T_DKIM_INVALID autolearn=no version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 8B7AE28C07A for ; Tue, 14 Jul 2015 08:43:52 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .gmail. - helo: .mail-lb0-f182.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -8.5 Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com [209.85.217.182]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Tue, 14 Jul 2015 08:43:51 +0200 (CEST) Received: by lblf12 with SMTP id f12so359061lbl.2 for ; Mon, 13 Jul 2015 23:44:13 -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:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=/+oyQdbJ71mrpk4UFhVuJ0q+05k8HS5WYBlCsQzP6mo=; b=FKJ2CyllBekgsrRVnyaz6mCQ4x/xtF4b+gjgCqi6w7V1yH3XYArnknOFwP9e11Y5Si kNCkwSxr17ZYLkJPbeZwNxywJsJR7JCAGuiT3KlPyCDiV6rHDiejGjnnmNDFG+OIZ/9u gWst2JZ/iTvWQPEi2f3qHC1oSpWMWkkt5FOgrorydTns7m+3EUSTAqyLSqlhmmHWd3CF K7oeqSZYfrN08k8PK68XocUT9Ub2oVBHrSMzYNU+DUcDlr+R0CpH+SKN66KJ+K1HHQrA Mjc32MAPX3hMVNrxBn7FL/Tb52/A2qAbOlV2W8xrlfL5jqGQFHV4el3hGVJIvUEjNy4X OULQ== X-Received: by 10.152.36.196 with SMTP id s4mr19856885laj.10.1436856253415; Mon, 13 Jul 2015 23:44:13 -0700 (PDT) Received: from linux-tdhb.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id l9sm13897laf.35.2015.07.13.23.44.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Jul 2015 23:44:12 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: Felix Fietkau , John Crispin , Jo-Philipp Wich Date: Tue, 14 Jul 2015 08:43:55 +0200 Message-Id: <1436856235-15031-1-git-send-email-zajec5@gmail.com> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1436706155-24725-1-git-send-email-zajec5@gmail.com> References: <1436706155-24725-1-git-send-email-zajec5@gmail.com> MIME-Version: 1.0 Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [PATCH V2 ubox] log: allow filtering messages with a regexp pattern X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" This allows printing/streaming/writing messages matching a specified basic regular expression only. Signed-off-by: Rafał Miłecki --- V2: Improve --help description of the new -e argument. --- log/logread.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/log/logread.c b/log/logread.c index 6255408..dcf3c08 100644 --- a/log/logread.c +++ b/log/logread.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -57,7 +58,8 @@ static const struct blobmsg_policy log_policy[] = { static struct uloop_timeout retry; static struct uloop_fd sender; -static const char *log_file, *log_ip, *log_port, *log_prefix, *pid_file, *hostname; +static regex_t regexp_preg; +static const char *log_file, *log_ip, *log_port, *log_prefix, *pid_file, *hostname, *regexp_pattern; static int log_type = LOG_STDOUT; static int log_size, log_udp, log_follow, log_trailer_null = 0; @@ -128,6 +130,9 @@ static int log_notify(struct blob_attr *msg) } m = blobmsg_get_string(tb[LOG_MSG]); + if (regexp_pattern && + regexec(®exp_preg, m, 0, NULL, 0) == REG_NOMATCH) + return 0; t = blobmsg_get_u64(tb[LOG_TIME]) / 1000; c = ctime(&t); p = blobmsg_get_u32(tb[LOG_PRIO]); @@ -186,6 +191,7 @@ static int usage(const char *prog) "Options:\n" " -s Path to ubus socket\n" " -l Got only the last 'count' messages\n" + " -e Filter messages with a regexp\n" " -r Stream message to a server\n" " -F Log file\n" " -S Log size\n" @@ -235,7 +241,7 @@ int main(int argc, char **argv) signal(SIGPIPE, SIG_IGN); - while ((ch = getopt(argc, argv, "u0fcs:l:r:F:p:S:P:h:")) != -1) { + while ((ch = getopt(argc, argv, "u0fcs:l:r:F:p:S:P:h:e:")) != -1) { switch (ch) { case 'u': log_udp = 1; @@ -274,6 +280,11 @@ int main(int argc, char **argv) case 'h': hostname = optarg; break; + case 'e': + if (!regcomp(®exp_preg, optarg, REG_NOSUB)) { + regexp_pattern = optarg; + } + break; default: return usage(*argv); }