From patchwork Tue Jan 31 15:14:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 1734923 X-Patchwork-Delegate: ansuelsmth@gmail.com 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=MnajB7aV; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=XMIHXMvt; 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 4P5pZZ4stbz23gV for ; Wed, 1 Feb 2023 02:17:42 +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:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=E0lMbIrOiC13+D3d9FGxc5ioXwOBkFKbllcs8j6tJwQ=; b=MnajB7aVI3R2cQ Nm/0ZnHvqmaQXFomff7j+ZceHQW6kxeRh0xdYEDqtSYGQNlxPFYUylkjJBld0lgg6eTaTVhdi+MPt QstAXffvuzgl7BCz457XWIwpcw3gaRN+OFnNQhhKZ6nVOFYwSPilABFZIF2eitAdJURfHXHL1ELaN jfui8X6+iySnkQXqzRCTUKIZE3pvFg5FQTgAb7pW4g19OWagKkSoUP0F9eWRJoIYKUqSED9FNeVuY 3x3YYhXjTmaB5D9ZjeZwvqGv101Yj8qBIZJjDxSW0+hF2ihD3tpBSAeXsNzmTodilhOV3yTKIzLDu YNQ82EkEBxkwII8TjpIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMsLb-008SNt-Uw; Tue, 31 Jan 2023 15:15:00 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMsLQ-008SMM-6n for openwrt-devel@lists.openwrt.org; Tue, 31 Jan 2023 15:14:49 +0000 Received: by mail-wr1-x432.google.com with SMTP id q10so14530502wrm.4 for ; Tue, 31 Jan 2023 07:14:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+dshQu+tzv+1hl+T4UOr0shPrgCPYAKNq8jlPZ4qLQU=; b=XMIHXMvtea7bj2AlkR2H0iS2BtVbNtFsN0agjKGaZlj0BSbbSLQ3nZ7s4x4ql7uzBt qo7YcHt0kxTm/oLEU3JjDSHobAv2bYSQfXEkL0YBoRj2XQWhxmPNgenEephtLXNXrkxr daX0bPriSxlK5aViZuH2bgYTJBYMY4VTa09qv/2n4JULCs2X6E69TFS2TQtw97vkaxX+ QHW0TQ069dpvMIKQp3sv7HTSDZ/ORaLX0L67EmbcLPrFQW8h8e3GaOKz+anTYEURxKeG 6QWDkFSUSE0rCusC23WJUKIioA/bqv7jtFbOb9zwC18d5tuwSaq0lvOHLKPTEA9mtEOr 5dEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+dshQu+tzv+1hl+T4UOr0shPrgCPYAKNq8jlPZ4qLQU=; b=dQSDgxpuGh34X6WiyC4VOaSqdZbKfPJ7tut9gEdPl37M/xYi50sEdUMkUYkhl9LgZX S2Mhp/mkLfF3Q9g+Pt8DzkXs3QonaKXMDIkn6axBvc4QO8IABFDA5xgQRfcHJ06ySC71 wh1rJbR1RxKZV/jzNvK8VvV7ZOW5QEyvo9VM2/IFBBIw1VsvCDRhpxthPk1DJb7I9k01 FUNGxeOFYrgeWHT6T79jSCngHmC+0FjIt8LD5lxWZdDz5WDN+NMKM9IMPvbL0WEKw/on EEgjddd3gQ/KbwJOzpCkBiPj1HDAakHGJHH2ZCKHUlgwD44ASVnBUz2n96VJ/jIYYnem wOcw== X-Gm-Message-State: AO0yUKW1yu0K8QZHMJO/5C/jB8XZK1inhk/uGA+aiML5Yc7rQzzVoZFb EgBA9Jp5h8YuMte4atAtN8Y= X-Google-Smtp-Source: AK7set8KLMR3XWO61GYZIiJNYu5YfNLL2Vjv5p5zrnfhWpxkcbz5lAxpl7YTKeGH1wJpMWgsPwroUQ== X-Received: by 2002:adf:f70e:0:b0:2bf:de0b:7009 with SMTP id r14-20020adff70e000000b002bfde0b7009mr10952461wrp.23.1675178084195; Tue, 31 Jan 2023 07:14:44 -0800 (PST) Received: from localhost.localdomain (93-34-88-241.ip49.fastwebnet.it. [93.34.88.241]) by smtp.googlemail.com with ESMTPSA id z2-20020a5d6542000000b00267bcb1bbe5sm14942811wrv.56.2023.01.31.07.14.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 07:14:43 -0800 (PST) From: Christian Marangi To: Jo-Philipp Wich , OpenWrt Development List Cc: Christian Marangi Subject: [rpcd PATCH 1/4] rc: fix and improve script scanning START and STOP Date: Tue, 31 Jan 2023 16:14:28 +0100 Message-Id: <20230131151431.15949-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230131_071448_271424_3ADD86B5 X-CRM114-Status: GOOD ( 13.19 ) 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: Currently we stop searching at the first occurence of START or STOP entry. This is wrong since we totally miss the other data (START or STOP) in the occurence of the other. Fix and improve script scanning by: - Increase the line max length to 255 char to read it in one go. - Scan only the first 10 lines. - Don't stop at the first occurence and try to search also for the [...] 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:432 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 [ansuelsmth[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 Currently we stop searching at the first occurence of START or STOP entry. This is wrong since we totally miss the other data (START or STOP) in the occurence of the other. Fix and improve script scanning by: - Increase the line max length to 255 char to read it in one go. - Scan only the first 10 lines. - Don't stop at the first occurence and try to search also for the other data. Signed-off-by: Christian Marangi --- rc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rc.c b/rc.c index 45fdc1a..431d3a5 100644 --- a/rc.c +++ b/rc.c @@ -187,17 +187,20 @@ static void rc_list_readdir(struct rc_list_context *c) if (fp) { struct stat s; char path[PATH_MAX]; - char line[32]; + char line[255]; bool beginning; + int count = 0; beginning = true; - while (c->entry.start < 0 && c->entry.stop < 0 && fgets(line, sizeof(line), fp)) { + while ((c->entry.start < 0 || c->entry.stop < 0) && + count <= 10 && fgets(line, sizeof(line), fp)) { if (beginning) { if (!strncmp(line, "START=", 6)) { c->entry.start = strtoul(line + 6, NULL, 0); } else if (!strncmp(line, "STOP=", 5)) { c->entry.stop = strtoul(line + 5, NULL, 0); } + count++; } beginning = !!strchr(line, '\n'); From patchwork Tue Jan 31 15:14:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 1734926 X-Patchwork-Delegate: ansuelsmth@gmail.com 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=rEIBDZXW; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=g6yiDC+4; 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 4P5pZl4LzWz23gV for ; Wed, 1 Feb 2023 02:17:51 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DCAGFHMpWlocvy4Kzw12wkzY+814EbKAnWXcFledRgE=; b=rEIBDZXW2pteKC n2kDpwXs7oeZXKWrlSI1Yer9qnPgBn0UVFz+PIjLIl3QCJ5Pt6w0ZkRvmaRbm0+957AsQXAw6kQpF LPnOEJrnBbdyyzTntE6spQdwETSAkhJLJEa5hCkkTAhl2DsQHIrBnK8fd8KTL1TvrWkMTiTyPqK3I wYyli/rWb3SHHZv35/IbXV4Nk6rFYCFKxcaI6ANsXKtUgs889swH8C8UY/yv4f14XFiPqV8NZolFV SzZ6afExY8R0ZVhu7FZ+2D9igCTS/fp9rdVlnRU8LbaN65u0hjGubSrbHSVKMw05L1pLpOVhLkGwU FwCyQETrrQ+BmIcus/5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMsLo-008SRV-8T; Tue, 31 Jan 2023 15:15:12 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMsLQ-008SMW-AC for openwrt-devel@lists.openwrt.org; Tue, 31 Jan 2023 15:14:49 +0000 Received: by mail-wr1-x436.google.com with SMTP id bk16so14509999wrb.11 for ; Tue, 31 Jan 2023 07:14:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bAb/7LvteuKDWR2a+GGZcqr+IK2io0JZOzhsBMSLzAc=; b=g6yiDC+4FrvK+YqZLoIkb5AckNYwS++9X4w9AUjtPfgoFipB8N+ThTJe7fsm+PTRaV qh75726hA0nmVOdkCgxFG/fmZFDUNyx7mRB2ALWXCVRGPeWusowDAUuTou9CEX5cUoHe w/upb1DDIsDPugRoNg1d6CVLxaiF0OENXIhBjoHcO12dHanZF2yZy641H4WQYaimZNve +z57aYc+aWiM4cSFXjMoWTwIKjrLzWgKqNQdvA4C1W+Pc7VzKT8WHDXVzWkCiRJ1RdcS QbNmLhKFvsKZ+y6bg9VLqt78Mcq0c2tQhz26yLLC2VG6b71tzd9/N1X5eRi692kuwgcv cuCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bAb/7LvteuKDWR2a+GGZcqr+IK2io0JZOzhsBMSLzAc=; b=lLsFI8tM4Y0/IPEADbXsUhSk+viGKwpcMU3JRLWjeemeNPMjesnt3i7qgR6MTJ5rrC 4WgBZz/TklkD2fnRJdq/jx1IsIeNQVPbi1ay/8qBfL+HCPaOeK9rUQ1Ys+bhOl/7hmOU Cfgh4KFezpySBvb0JWBlI6L3lX9c3fo8wf7tVHmJFfsCxp5sSEaC0tFJfekCio1bVDSF DaVKlNHarWdEOABfc92i/N+DFivzyz7nMqfeee3UtEnFlQxeSDkoNnYNztzlbW04Cjr7 tCiOzEWE6QolDoTk6V0R2Poys1PG1//qOVxDO2fEkhvKWQ4qnY6W9BXapjYH7cfhNvII unOw== X-Gm-Message-State: AO0yUKUT9CWdc3qk/Xu7JjwITT5UHFXnrj3aGMahKLuLOZ8J9Nb8/Gwx RpPBJtRSsCF05VMjCMccFNA= X-Google-Smtp-Source: AK7set+0LEi5AiU2F1EYatNi0oIO2wjvXcfWSr/Mbzyt60Ga7eBiBZh+yWBv2QrzvNtH+KmxNKSVNg== X-Received: by 2002:adf:a1dc:0:b0:2bf:b4ca:6bac with SMTP id v28-20020adfa1dc000000b002bfb4ca6bacmr21791079wrv.59.1675178084907; Tue, 31 Jan 2023 07:14:44 -0800 (PST) Received: from localhost.localdomain (93-34-88-241.ip49.fastwebnet.it. [93.34.88.241]) by smtp.googlemail.com with ESMTPSA id z2-20020a5d6542000000b00267bcb1bbe5sm14942811wrv.56.2023.01.31.07.14.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 07:14:44 -0800 (PST) From: Christian Marangi To: Jo-Philipp Wich , OpenWrt Development List Cc: Christian Marangi Subject: [rpcd PATCH 2/4] rc: add support for scanning USE_PROCD and skip running if not supported Date: Tue, 31 Jan 2023 16:14:29 +0100 Message-Id: <20230131151431.15949-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230131151431.15949-1-ansuelsmth@gmail.com> References: <20230131151431.15949-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230131_071448_374972_0D397059 X-CRM114-Status: GOOD ( 14.76 ) 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: Running check is supported only in procd scripts. This cause prolonged execution time since the function needs to timeout. To fix this check if the script USE_PROCD and run running check only if supported. 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:436 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 [ansuelsmth[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 Running check is supported only in procd scripts. This cause prolonged execution time since the function needs to timeout. To fix this check if the script USE_PROCD and run running check only if supported. Also provide running info only if the running check is supported. Signed-off-by: Christian Marangi --- rc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rc.c b/rc.c index 431d3a5..35b47e9 100644 --- a/rc.c +++ b/rc.c @@ -47,6 +47,7 @@ struct rc_list_context { int stop; bool enabled; bool running; + bool use_procd; } entry; }; @@ -81,7 +82,8 @@ static void rc_list_add_table(struct rc_list_context *c) if (c->entry.stop >= 0) blobmsg_add_u16(c->buf, "stop", c->entry.stop); blobmsg_add_u8(c->buf, "enabled", c->entry.enabled); - blobmsg_add_u8(c->buf, "running", c->entry.running); + if (c->entry.use_procd) + blobmsg_add_u8(c->buf, "running", c->entry.running); blobmsg_close_table(c->buf, e); } @@ -112,6 +114,9 @@ static int rc_list_exec(struct rc_list_context *c, const char *action, uloop_pro case -1: return -errno; case 0: + if (!c->entry.use_procd) + exit(-EOPNOTSUPP); + /* Set stdin, stdout & stderr to /dev/null */ fd = open("/dev/null", O_RDWR); if (fd >= 0) { @@ -192,13 +197,15 @@ static void rc_list_readdir(struct rc_list_context *c) int count = 0; beginning = true; - while ((c->entry.start < 0 || c->entry.stop < 0) && + while ((c->entry.start < 0 || c->entry.stop < 0 || !c->entry.use_procd) && count <= 10 && fgets(line, sizeof(line), fp)) { if (beginning) { if (!strncmp(line, "START=", 6)) { c->entry.start = strtoul(line + 6, NULL, 0); } else if (!strncmp(line, "STOP=", 5)) { c->entry.stop = strtoul(line + 5, NULL, 0); + } else if (!c->skip_running_check && !strncmp(line, "USE_PROCD=", 10)) { + c->entry.use_procd = !!strtoul(line + 10, NULL, 0); } count++; } From patchwork Tue Jan 31 15:14:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 1734924 X-Patchwork-Delegate: ansuelsmth@gmail.com 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=WbHC9qUj; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Iw1icHli; 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 4P5pZZ5ZFgz23jC for ; Wed, 1 Feb 2023 02:17:42 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VFKwyZWHVSOTs8cYzCQvVyHmzMTZPR1Pg6YLU5X7DSM=; b=WbHC9qUjjyEKzc EjNOfTeROyRltHk1Wz6LH2N9mIsz/eAS6KftjWn0m+HXTzlGJfL2ZtzxdKG+58GgLK4p6eN9LEIs1 U/VGjBxa3J+6Zm7w9AeGjGqf8lglevEnXnoYT1hxcgYL/MUvLTYRrjL5/RLi6ymsWi2FXgTqQnhIV VGiIu4oCqS+m7kZMl0SsyKlv6o1kbd6NQT3icobe3LEmUBpO8k/oksTmFAgrX7vr4uBFcpsGeWqFA FvQzfE2EagJ6kcoC8HlSEbdlIVig25RItdNBzSEDQrpbBk1htfDsCco68WKlVb8UpDw9qlzYthQoZ UJLYg8jW+Uc3RncVlFmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMsM0-008SU4-VI; Tue, 31 Jan 2023 15:15:25 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMsLR-008SMZ-IU for openwrt-devel@lists.openwrt.org; Tue, 31 Jan 2023 15:14:50 +0000 Received: by mail-wm1-x329.google.com with SMTP id m5-20020a05600c4f4500b003db03b2559eso10853379wmq.5 for ; Tue, 31 Jan 2023 07:14:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ei5t02/XJswgg/YFXA79C6WsueV4fRDliJKwCfmoO+w=; b=Iw1icHliLNWAOuvxaztxeVqmSECznL4ZaR5GYcr/lL9vQ7HmKllcHDDVR2hYkqWXjK g9EFbCG0a+5YTt9OBxmMsbTgxrSVnsdq6QQZiWGbfr9EEiZp4jLHwLiLLfqcn7InjwU+ +1YjifB+6xSpNE/JBjEL9AO1sQn6aoyPNbCnssRmkdhuozQeFkff8/ITYS256rfPC2hY x/HSIKqLLo4pkg6Ip0fZjDgzCm50YGvMe9a9PYq8fUA4xdQrgkzGeBaLkkNCXw8Y0f9g 6wvHmASI8Zs2Xam08WBZ2jTPYCc6XD9GBIQ+mSxZBfSXTMDIq1xcWiE0Tm0hTOf6OpeT hSvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ei5t02/XJswgg/YFXA79C6WsueV4fRDliJKwCfmoO+w=; b=33D14c4Tj60edGh+9bF7yILAjyYkSDQ9vJ5VxsymDae2GuGJtShb8pZto0VRSwR9AV KiZ4lA2zP+StvT/06uSRyeR33RSAUO5WYjYNax5VI+TE0wugBnyT8J58i1ejDf9m/Cnu RLshruKfa3k1sroYZ1UEkbYBunCJP6wpdstMtoIsWiuR5QwbvMJJ5ZOi8wzUiu4uLJB5 BFXyExOHnagSVJdZmyWacgZokKLICcjuK3+R4fkr3eXcordG5bqSBz9WH4YNpPYSxsS8 8tosyWs3lJ4PowaZdds4rH4V0pQBy17QgI2JVuADbolSgPX9La/TTZwpdLAnxw9bBAi8 3sig== X-Gm-Message-State: AO0yUKVKALEy6wGnDJELl8j5KO54qrQLQFZIVGIezAxRxfo74gRz7sEg 4CFe6/kyP/UhvMmEuUP2PMw= X-Google-Smtp-Source: AK7set94Vg7d87VcDHtSalw3sz6c+v+YQvsvygDsck66tEmjYrRrt/oYhE0+2Wei5R7erRmjed0EKQ== X-Received: by 2002:a05:600c:1c23:b0:3dd:1bd3:4f6d with SMTP id j35-20020a05600c1c2300b003dd1bd34f6dmr3589225wms.32.1675178085745; Tue, 31 Jan 2023 07:14:45 -0800 (PST) Received: from localhost.localdomain (93-34-88-241.ip49.fastwebnet.it. [93.34.88.241]) by smtp.googlemail.com with ESMTPSA id z2-20020a5d6542000000b00267bcb1bbe5sm14942811wrv.56.2023.01.31.07.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 07:14:45 -0800 (PST) From: Christian Marangi To: Jo-Philipp Wich , OpenWrt Development List Cc: Christian Marangi Subject: [rpcd PATCH 3/4] rc: add option to skip running check for list method Date: Tue, 31 Jan 2023 16:14:30 +0100 Message-Id: <20230131151431.15949-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230131151431.15949-1-ansuelsmth@gmail.com> References: <20230131151431.15949-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230131_071449_632500_FD6496C1 X-CRM114-Status: GOOD ( 16.66 ) 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: Running check may be slow and increase result time in the other of 70ms for the list method. Add an option to skip running check by passing the skip_running_check as true in the list method args to speedup execution if the running info is not needed. 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:329 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 [ansuelsmth[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 Running check may be slow and increase result time in the other of 70ms for the list method. Add an option to skip running check by passing the skip_running_check as true in the list method args to speedup execution if the running info is not needed. With the option set to true the execution time lower to just 5ms. Signed-off-by: Christian Marangi --- rc.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/rc.c b/rc.c index 35b47e9..60ec4bf 100644 --- a/rc.c +++ b/rc.c @@ -20,6 +20,15 @@ #define RC_LIST_EXEC_TIMEOUT_MS 3000 +enum { + RC_LIST_SKIP_RUNNING_CHECK, + __RC_LIST_MAX +}; + +static const struct blobmsg_policy rc_list_policy[] = { + [RC_LIST_SKIP_RUNNING_CHECK] = { "skip_running_check", BLOBMSG_TYPE_BOOL }, +}; + enum { RC_INIT_NAME, RC_INIT_ACTION, @@ -38,6 +47,7 @@ struct rc_list_context { struct ubus_request_data req; struct blob_buf *buf; DIR *dir; + bool skip_running_check; /* Info about currently processed init.d entry */ struct { @@ -82,7 +92,7 @@ static void rc_list_add_table(struct rc_list_context *c) if (c->entry.stop >= 0) blobmsg_add_u16(c->buf, "stop", c->entry.stop); blobmsg_add_u8(c->buf, "enabled", c->entry.enabled); - if (c->entry.use_procd) + if (!c->skip_running_check && c->entry.use_procd) blobmsg_add_u8(c->buf, "running", c->entry.running); blobmsg_close_table(c->buf, e); @@ -114,6 +124,9 @@ static int rc_list_exec(struct rc_list_context *c, const char *action, uloop_pro case -1: return -errno; case 0: + if (c->skip_running_check) + exit(-EFAULT); + if (!c->entry.use_procd) exit(-EOPNOTSUPP); @@ -197,7 +210,8 @@ static void rc_list_readdir(struct rc_list_context *c) int count = 0; beginning = true; - while ((c->entry.start < 0 || c->entry.stop < 0 || !c->entry.use_procd) && + while ((c->entry.start < 0 || c->entry.stop < 0 || + (!c->skip_running_check && !c->entry.use_procd)) && count <= 10 && fgets(line, sizeof(line), fp)) { if (beginning) { if (!strncmp(line, "START=", 6)) { @@ -236,9 +250,12 @@ static int rc_list(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { + struct blob_attr *tb[__RC_LIST_MAX]; static struct blob_buf buf; struct rc_list_context *c; + blobmsg_parse(rc_list_policy, __RC_LIST_MAX, tb, blobmsg_data(msg), blobmsg_data_len(msg)); + blob_buf_init(&buf, 0); c = calloc(1, sizeof(*c)); @@ -252,6 +269,8 @@ static int rc_list(struct ubus_context *ctx, struct ubus_object *obj, free(c); return UBUS_STATUS_UNKNOWN_ERROR; } + if (tb[RC_LIST_SKIP_RUNNING_CHECK]) + c->skip_running_check = blobmsg_get_bool(tb[RC_LIST_SKIP_RUNNING_CHECK]); ubus_defer_request(ctx, req, &c->req); @@ -359,7 +378,7 @@ static int rc_init(struct ubus_context *ctx, struct ubus_object *obj, int rpc_rc_api_init(struct ubus_context *ctx) { static const struct ubus_method rc_methods[] = { - UBUS_METHOD_NOARG("list", rc_list), + UBUS_METHOD("list", rc_list, rc_list_policy), UBUS_METHOD("init", rc_init, rc_init_policy), }; From patchwork Tue Jan 31 15:14:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 1734925 X-Patchwork-Delegate: ansuelsmth@gmail.com 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=4uU3SE8d; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=LztZ0fXA; 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 4P5pZf4HVWz23gV for ; Wed, 1 Feb 2023 02:17:46 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+0dekTbUqumpMcbpEHgEkABGtXo9uQxO30SEW8ed3Ek=; b=4uU3SE8dLIECKr TYsWEJtt3TbScrRv2ajWgOEDzXGegq+OwFY/otLITbtY9zYKlqiDS+YGj9HyNrWvRpKw17hMrgkIH rnYRCUhypBS6V6/zjGqlj3kU4AwozQZ30oj1PbF2O9wmZ227SOQmIBveRx4XoOAYJ2+H19LR8YtXT eayH7OYS87jJmwiYo546nj4bNkfZ0G1O8t/AGeSoHbf5TZF4h9eXMOgB9J/DDY0qD5H2SikMFby+3 DM6xnWcLvQ2use3q5SHkurlP0EBAYuSORdk/fa3Eco04vtBlcQjz+L/V1MiQE8DBn9uB9AhnZilHD VvVndOLNIXo/eC7beAIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMsME-008SXn-Gy; Tue, 31 Jan 2023 15:15:38 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMsLZ-008SMi-Ox for openwrt-devel@lists.openwrt.org; Tue, 31 Jan 2023 15:14:59 +0000 Received: by mail-wr1-x429.google.com with SMTP id t18so14550109wro.1 for ; Tue, 31 Jan 2023 07:14:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QNu155T4xrY8S60x1InTtJ7UKhsb92AqHpEt0f8hFwU=; b=LztZ0fXAwC1PpkgWgiKKXXMas+MTRLzRl2zJzNNolrypRTsZKAfcorUGNfZNKfsh8e Nu2dA0TQvT0E8piGpk3DzU7wDTCrfvI6yDo93TXkA9IMRslt/jqLAM5ywYpg0/XC+04E pEgddQeKO+w8vOGZcSLKeBjGzG5Wk9OR8WNCFJ2eb/nn6sXaoSnd+PD3fRxWMmO5T/8Q 3gq0UcYR/9I3aNSyXfMJQtpfGr/ADyR316wGbN6MO5pdb2MluUlre4qagfQ3jdoDeZzi hHSqLFD0LHe82W1Iq3g91VSppbvHn1V+r2sY8jiINcQJGcJwrYWjB5DgXMWGnCzAHMIt 00aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QNu155T4xrY8S60x1InTtJ7UKhsb92AqHpEt0f8hFwU=; b=eIREIK5Uf1NDwmHevW+4hV5a8rC8yHxx9VHbAphdW3/7D9G8bRqBlLOeOMDQWGwjWS GTcITDukixcor1DJvdfauHWQzFs1LgD39pXkw63QPlnh/n/J5brk5nyBt2Y9oSBrf2sZ +AsfGGC7Gtwx/YbyQornsUrRXPF1sHjjlk8bniqvPweahlyCbkmphYdMcEEcfPCDYyqW 95DnWzTTjyH0ORdhdSr/fFCB1Gv/ppMZiGsuYoOZFoujOpXmw/ra8U/Fjbpwm6jaNTZl NAzz62+3+xwTmI9ejfYu4ukXKBARvXXoihHUJcYAr7ABmegx42yoQJqzrwZ8e5HfVles rODw== X-Gm-Message-State: AFqh2krnwkmaqAbC7WfmccwWWpdo8mnf1JFV2AjzR85KEvf7h+yarPWW r77Mg52j1sAO0/ECBKyol/g6rH41ZbQ= X-Google-Smtp-Source: AMrXdXtev0KucYsVjh9i+NDdjKNqY7dciYCcLrprxzn/ZbXaOYt51nH4zsLa/kA/y7mh6emN8nNP1Q== X-Received: by 2002:a5d:4350:0:b0:2be:5366:8cdf with SMTP id u16-20020a5d4350000000b002be53668cdfmr34171536wrr.20.1675178086670; Tue, 31 Jan 2023 07:14:46 -0800 (PST) Received: from localhost.localdomain (93-34-88-241.ip49.fastwebnet.it. [93.34.88.241]) by smtp.googlemail.com with ESMTPSA id z2-20020a5d6542000000b00267bcb1bbe5sm14942811wrv.56.2023.01.31.07.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 07:14:46 -0800 (PST) From: Christian Marangi To: Jo-Philipp Wich , OpenWrt Development List Cc: Christian Marangi Subject: [rpcd PATCH 4/4] rc: add option to get info for a single script in list method Date: Tue, 31 Jan 2023 16:14:31 +0100 Message-Id: <20230131151431.15949-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230131151431.15949-1-ansuelsmth@gmail.com> References: <20230131151431.15949-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230131_071457_829311_70D43ED9 X-CRM114-Status: GOOD ( 16.28 ) 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: Add option to get info for a single script in list method. To get info of a particular script pass the name arg to the list method. If the script doesn't exist an empty table is returned. 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:429 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 [ansuelsmth[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 Add option to get info for a single script in list method. To get info of a particular script pass the name arg to the list method. If the script doesn't exist an empty table is returned. Signed-off-by: Christian Marangi --- rc.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/rc.c b/rc.c index 60ec4bf..3d192f1 100644 --- a/rc.c +++ b/rc.c @@ -21,11 +21,13 @@ #define RC_LIST_EXEC_TIMEOUT_MS 3000 enum { + RC_LIST_NAME, RC_LIST_SKIP_RUNNING_CHECK, __RC_LIST_MAX }; static const struct blobmsg_policy rc_list_policy[] = { + [RC_LIST_NAME] = { "name", BLOBMSG_TYPE_STRING }, [RC_LIST_SKIP_RUNNING_CHECK] = { "skip_running_check", BLOBMSG_TYPE_BOOL }, }; @@ -48,6 +50,7 @@ struct rc_list_context { struct blob_buf *buf; DIR *dir; bool skip_running_check; + const char *req_name; /* Info about currently processed init.d entry */ struct { @@ -181,7 +184,12 @@ static void rc_list_readdir(struct rc_list_context *c) FILE *fp; e = readdir(c->dir); - if (!e) { + /* + * If scanning for a specific script and entry.d_name is set + * we can assume we found a matching one in the previous + * iteration since entry.d_name is set only if a match is found. + */ + if (!e || (c->req_name && c->entry.d_name)) { closedir(c->dir); ubus_send_reply(c->ctx, &c->req, c->buf->head); ubus_complete_deferred_request(c->ctx, &c->req, UBUS_STATUS_OK); @@ -191,6 +199,9 @@ static void rc_list_readdir(struct rc_list_context *c) if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, "..")) goto next; + if (c->req_name && strcmp(e->d_name, c->req_name)) + goto next; + memset(&c->entry, 0, sizeof(c->entry)); c->entry.start = -1; c->entry.stop = -1; @@ -271,6 +282,8 @@ static int rc_list(struct ubus_context *ctx, struct ubus_object *obj, } if (tb[RC_LIST_SKIP_RUNNING_CHECK]) c->skip_running_check = blobmsg_get_bool(tb[RC_LIST_SKIP_RUNNING_CHECK]); + if (tb[RC_LIST_NAME]) + c->req_name = blobmsg_get_string(tb[RC_LIST_NAME]); ubus_defer_request(ctx, req, &c->req);