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), };