From patchwork Tue Nov 23 18:39:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jo-Philipp Wich X-Patchwork-Id: 1558745 X-Patchwork-Delegate: jow@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=4Atzc4Cq; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HzCfS67sBz9s1l for ; Wed, 24 Nov 2021 05:41:52 +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=VNrgKsbW9cbXACN2XmKe8QP6WcpN0LBg5wTbe1O61Po=; b=4Atzc4CqYGzHmd 3zCzWVIa3evtGH0ZUUEe17nDR1GI/VbY8MI4mZ6a5WYF4T0KZtxbtB9xbpZrHkXxfvne5BZA4TZ++ tX0GLj4PcWgq4jLXf4wpgUaAe6fzblqZ89t1PdI4962UV7kZ1HSOo1Z5BkUpudrvnitUe+FNmyNS7 aUpAULYpmN22izYFVv+aD2/Rz7/7toXJk4+q6JDD+9hjKzrtkwGiZzUIQyxjSP2F2wibtxz99b8LC 9g1hVw7m24cOsa0ro8scyehD0P2A0Cf73WO//oMSgmBmV85z7zQPY+FAk60ZJbmgWki1eNr1CD9vp ZV0NXdgLRIfcrWvInQ4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpahK-003DsI-Pz; Tue, 23 Nov 2021 18:39:18 +0000 Received: from mxout01.bytecamp.net ([212.204.60.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpahF-003DqZ-MS for openwrt-devel@lists.openwrt.org; Tue, 23 Nov 2021 18:39:16 +0000 Received: by mxout01.bytecamp.net (Postfix, from userid 1001) id 011903044A; Tue, 23 Nov 2021 19:39:08 +0100 (CET) Received: from mail.bytecamp.net (mail.bytecamp.net [212.204.60.9]) by mxout01.bytecamp.net (Postfix) with ESMTP id B972F30448 for ; Tue, 23 Nov 2021 19:39:07 +0100 (CET) Received: (qmail 57220 invoked from network); 23 Nov 2021 19:39:07 +0100 Received: from unknown (HELO j7.lan) (jo%wwsnet.net@95.89.150.218) by mail.bytecamp.net with ESMTPS (DHE-RSA-AES128-GCM-SHA256 encrypted); 23 Nov 2021 19:39:07 +0100 From: Jo-Philipp Wich To: openwrt-devel@lists.openwrt.org Cc: Jo-Philipp Wich Subject: [PATCH] procd: procd.sh: make no assumptions about init script path Date: Tue, 23 Nov 2021 19:39:00 +0100 Message-Id: <20211123183900.1010072-1-jo@mein.io> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211123_103913_947417_CD2BD83B X-CRM114-Status: UNSURE ( 9.11 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.7 (/) 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: Init scripts in /etc/init.d/ may be symlinks pointing elsewhere, so it is not safe to assume that the basename of the real path is existing. Instead of trying to reassemble the target path from the basename when setting up triggers, trust the result of readlink and fall back to `$initscript` which corresponds to `argv[0]` when readlink fai [...] Content analysis details: (-0.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [212.204.60.217 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record 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 Init scripts in /etc/init.d/ may be symlinks pointing elsewhere, so it is not safe to assume that the basename of the real path is existing. Instead of trying to reassemble the target path from the basename when setting up triggers, trust the result of readlink and fall back to `$initscript` which corresponds to `argv[0]` when readlink failed. This fixes reload trigger setup for init script symlinks that point to files with different base names. Signed-off-by: Jo-Philipp Wich --- package/system/procd/files/procd.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh index 3549a5a914..5fc5441be0 100644 --- a/package/system/procd/files/procd.sh +++ b/package/system/procd/files/procd.sh @@ -299,11 +299,10 @@ _procd_add_interface_trigger() { } _procd_add_reload_interface_trigger() { - local script=$(readlink "$initscript") - local name=$(basename ${script:-$initscript}) + local script=$(readlink -f "$initscript") _procd_open_trigger - _procd_add_interface_trigger "interface.*" $1 /etc/init.d/$name reload + _procd_add_interface_trigger "interface.*" $1 "${script:-$initscript}" reload _procd_close_trigger } @@ -424,13 +423,12 @@ _procd_add_raw_trigger() { } _procd_add_reload_trigger() { - local script=$(readlink "$initscript") - local name=$(basename ${script:-$initscript}) + local script=$(readlink -f "$initscript") local file _procd_open_trigger for file in "$@"; do - _procd_add_config_trigger "config.change" "$file" /etc/init.d/$name reload + _procd_add_config_trigger "config.change" "$file" "${script:-$initscript}" reload done _procd_close_trigger }