From patchwork Fri Sep 11 11:03:05 2020 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: 1362391 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=O66Ba01y; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Gzy7FFn5; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BntG0382jz9sRf for ; Fri, 11 Sep 2020 21:05:28 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject: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=382vyHkQTkwz72O5ucrMaRCGwEadrY0eXkcvYUCtLd4=; b=O66Ba01yVCevNlmDblf1E/Kp2B IGzUi0kgIj/vEqjN1OOvPVbPDTY16mu81/asLRW+2JDQT+FKmHyHR7DtfpI9dkSy/i5FNheJcCO7a nWO4v8+VxLdqrt2/VwaJsCcEJELen/bAfEgRjIg/q/Z1VJ5XE15yoEI3ZVpeHO6LvDwY9aXhOWA7t Gwp29Hh1ogqrKhhrFtWnX6/2HC+U4BausGAIu4hc2+IKHJvoVYbOOcIDzKmhBqa/Qie6gi0bdfTsc u87efMMMfdCwGHe5IxiR9EXzmW9sJZL+ojZnwCjEmBxmWrQbqTZrAuRfJnTMAHC3FKgnyRUUUTFCZ 37VW/qwA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kGgps-0008Dn-Fs; Fri, 11 Sep 2020 11:03:20 +0000 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kGgpq-0008DQ-FF for openwrt-devel@lists.openwrt.org; Fri, 11 Sep 2020 11:03:19 +0000 Received: by mail-lj1-x244.google.com with SMTP id n25so12063812ljj.4 for ; Fri, 11 Sep 2020 04:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=XQnk2IJRUmV2Ww2RvFkHcLlVzhIuZL1TOqV46fWm9OA=; b=Gzy7FFn5hSFkaChk0O+iDba5fvHnOSa1uvnfXWdM6h6nwafs46sr9b6nu7V3rQd5Uj nRdrrMUgb5ARP51iYiO4oPp5CwIFlq8I190Z73YfQw2zwNMeu0UQcny1YzOSYKrOGp0L 8anWVHiRHLuPqPITa/Vlzqold9ZL5wHNDMKaWMF+i5rkoGBFukcMsViV41rDDAagrdH2 k5qM2Y+UsoyCZA+wSRVhpJ1yDxSQKH/MNGG+ht10vNJwllvEgskYy77P5hI3eKPUqi0r 3M33GeLTinOoV6TrdmvF8Fklakw6slTmpOKg5Sybjr4WwHBitjF4k96FRAesFnTU2SNP Jbeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=XQnk2IJRUmV2Ww2RvFkHcLlVzhIuZL1TOqV46fWm9OA=; b=RRSUJwzX1z3JjQUulLaHUwB3pUnch1YXy2B3GpoAv63Z8itazAJ9pZyoLk7KHj6/1f 0OnQZ2ZIpRbAczV4Iyg1+1pVSBFid4ojC7ZYBeHWiXsd0KeKJfnsZBqDuXNE1pV2N7W7 fZ6XTQoqf6DbJGq3bzW/J6v2zvn9R4HlNDwUBPCg7o9lSnDkZrxofrCsBje8nRbZkh1a 3xQzvS61IxTdpRt8K+Wu22JDnMgWf6joOUyC1cI2SYMKWvXW8EFyl791sidJzhEaHV22 Avhfp10x8knJVASuPlFBf6dfXtNctkEVUfCr4vC98FFBczEzCwNCWdcbY0E5uxc9Frh9 6j3Q== X-Gm-Message-State: AOAM533pH82KO8ngoznP2mRMTOzUsvisLg7c87nyYceVF6Tv+vPMuM1N 5xADCIeif714om6c/KQXuc4OeIuMEqM= X-Google-Smtp-Source: ABdhPJy/c46wU0Lf1htrFYuPbdh27VmVczY5+AkyIvGfFnlGAHY7n9n3ce0/7GMXKvnarGzgum9f6A== X-Received: by 2002:a2e:7c09:: with SMTP id x9mr608007ljc.192.1599822194601; Fri, 11 Sep 2020 04:03:14 -0700 (PDT) Received: from localhost.localdomain (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id h13sm473680ljl.63.2020.09.11.04.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2020 04:03:13 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH rpcd] rc: support init.d scripts with START=0 Date: Fri, 11 Sep 2020 13:03:05 +0200 Message-Id: <20200911110305.14161-1-zajec5@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200911_070318_547554_1F44BB3F X-CRM114-Status: GOOD ( 14.37 ) X-Spam-Score: 0.1 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.1 points) 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:244 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [zajec5[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [zajec5[at]gmail.com] 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -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 X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Jo-Philipp Wich Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Rafał Miłecki Use negative value (instead of 0) to indicate missing START. Signed-off-by: Rafał Miłecki --- rc.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/rc.c b/rc.c index b4787d5..45fdc1a 100644 --- a/rc.c +++ b/rc.c @@ -43,8 +43,8 @@ struct rc_list_context { struct { char path[PATH_MAX]; const char *d_name; - unsigned int start; - unsigned int stop; + int start; + int stop; bool enabled; bool running; } entry; @@ -76,9 +76,9 @@ static void rc_list_add_table(struct rc_list_context *c) e = blobmsg_open_table(c->buf, c->entry.d_name); - if (c->entry.start) + if (c->entry.start >= 0) blobmsg_add_u16(c->buf, "start", c->entry.start); - if (c->entry.stop) + 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); @@ -174,6 +174,8 @@ static void rc_list_readdir(struct rc_list_context *c) goto next; memset(&c->entry, 0, sizeof(c->entry)); + c->entry.start = -1; + c->entry.stop = -1; snprintf(c->entry.path, sizeof(c->entry.path), "/etc/init.d/%s", e->d_name); if (rc_check_script(c->entry.path)) @@ -189,7 +191,7 @@ static void rc_list_readdir(struct rc_list_context *c) bool beginning; beginning = true; - while (!c->entry.start && !c->entry.stop && fgets(line, sizeof(line), fp)) { + while (c->entry.start < 0 && c->entry.stop < 0 && fgets(line, sizeof(line), fp)) { if (beginning) { if (!strncmp(line, "START=", 6)) { c->entry.start = strtoul(line + 6, NULL, 0); @@ -202,9 +204,11 @@ static void rc_list_readdir(struct rc_list_context *c) } fclose(fp); - snprintf(path, sizeof(path), "/etc/rc.d/S%02d%s", c->entry.start, c->entry.d_name); - if (!stat(path, &s) && (s.st_mode & S_IXUSR)) - c->entry.enabled = true; + if (c->entry.start >= 0) { + snprintf(path, sizeof(path), "/etc/rc.d/S%02d%s", c->entry.start, c->entry.d_name); + if (!stat(path, &s) && (s.st_mode & S_IXUSR)) + c->entry.enabled = true; + } } if (rc_list_exec(c, "running", rc_list_exec_running_cb))