From f93b00fa686ad689a59484e4a2905c2fc9a6c875 Mon Sep 17 00:00:00 2001 From: Etienne Champetier Date: Fri, 11 Jul 2025 17:23:28 -0400 Subject: [PATCH] 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 --- net/mwan3/files/lib/mwan3/common.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/mwan3/files/lib/mwan3/common.sh b/net/mwan3/files/lib/mwan3/common.sh index ecd45026e8..953cd6665e 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 -- 2.30.2