From: Etienne Champetier Date: Fri, 11 Jul 2025 21:23:28 +0000 (-0400) Subject: mwan3: add new readfile function to speedup variable read from file X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=f93b00fa686ad689a59484e4a2905c2fc9a6c875;p=openwrt-packages.git mwan3: add new readfile function to speedup variable read from file This is a preparation for adding an utility function readfile() to read directly to a variable. Using '$(cat ...)' causes a fork/execve which is extremely slow just to read '~2' chars. (commit message from Florian Eckert) Signed-off-by: Etienne Champetier --- diff --git a/net/mwan3/files/lib/mwan3/common.sh b/net/mwan3/files/lib/mwan3/common.sh index ecd45026e..953cd6665 100644 --- a/net/mwan3/files/lib/mwan3/common.sh +++ b/net/mwan3/files/lib/mwan3/common.sh @@ -86,6 +86,12 @@ mwan3_get_src_ip() export "$1=$_src_ip" } +readfile() { + [ -f "$2" ] || return 1 + # read returns 1 on EOF + read -d'\0' $1 <"$2" || : +} + mwan3_get_mwan3track_status() { local track_ips pid