procd: procd.sh: make no assumptions about init script path
authorJo-Philipp Wich <jo@mein.io>
Thu, 20 Aug 2020 14:17:34 +0000 (16:17 +0200)
committerJo-Philipp Wich <jo@mein.io>
Wed, 21 Feb 2024 21:31:36 +0000 (22:31 +0100)
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@mein.io>
package/system/procd/files/procd.sh

index 8ee25f4f08b4715dd214623e3edba6d1db1379f9..8694e087fb7ad7f86c740507f4ed8fdd37f3a4fc 100644 (file)
@@ -298,11 +298,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
 }
 
@@ -420,13 +419,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
 }