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>
Sun, 26 Jan 2025 13:07:08 +0000 (14:07 +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 0f9405a2220007fc6225e3d3fa45dff5d6c578d3..45ee9e3184695d4984393de4f2ab3c0117d03304 100644 (file)
@@ -300,11 +300,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
 }
 
@@ -452,13 +451,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
 }