[PATCH] procd: procd.sh: make no assumptions about init script path

Jo-Philipp Wich jo at mein.io
Tue Nov 23 10:39:00 PST 2021


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 <jo at mein.io>
---
 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
 }
-- 
2.30.2




More information about the openwrt-devel mailing list