From: Etienne Champetier Date: Fri, 27 Jun 2025 23:18:52 +0000 (-0400) Subject: mwan3: return via variable X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=a6a7f0b21b0d5e954119dfa19cde1967dd07a617;p=feed%2Fpackages.git mwan3: return via variable Using $(...) to call an internal function causes a fork(). Pass the name of the return variable as first parameter, and write to it using 'export -n'. Signed-off-by: Etienne Champetier --- diff --git a/net/mwan3/files/lib/mwan3/common.sh b/net/mwan3/files/lib/mwan3/common.sh index caf546e665..b99ccfd0e8 100644 --- a/net/mwan3/files/lib/mwan3/common.sh +++ b/net/mwan3/files/lib/mwan3/common.sh @@ -94,7 +94,7 @@ readfile() { mwan3_get_mwan3track_status() { - local interface=$1 + local interface=$2 local track_ips pid cmdline started mwan3_list_track_ips() { @@ -103,29 +103,29 @@ mwan3_get_mwan3track_status() config_list_foreach "$interface" track_ip mwan3_list_track_ips if [ -z "$track_ips" ]; then - echo "disabled" + export -n "$1=disabled" return fi readfile pid $MWAN3TRACK_STATUS_DIR/$interface/PID 2>/dev/null if [ -z "$pid" ]; then - echo "down" + export -n "$1=down" return fi readfile cmdline /proc/$pid/cmdline 2>/dev/null if [ $cmdline != "/bin/sh/usr/sbin/mwan3track${interface}" ]; then - echo "down" + export -n "$1=down" return fi readfile started $MWAN3TRACK_STATUS_DIR/$interface/STARTED case "$started" in 0) - echo "paused" + export -n "$1=paused" ;; 1) - echo "active" + export -n "$1=active" ;; *) - echo "down" + export -n "$1=down" ;; esac } @@ -208,17 +208,21 @@ mwan3_count_one_bits() } get_uptime() { - local uptime - readfile uptime /proc/uptime - echo "${uptime%%.*}" + local _tmp + readfile _tmp /proc/uptime + if [ $# -eq 0 ]; then + echo "${_tmp%%.*}" + else + export -n "$1=${_tmp%%.*}" + fi } get_online_time() { local time_n time_u iface - iface="$1" + iface="$2" readfile time_u "$MWAN3TRACK_STATUS_DIR/${iface}/ONLINE" 2>/dev/null [ -z "${time_u}" ] || [ "${time_u}" = "0" ] || { - time_n="$(get_uptime)" - echo $((time_n-time_u)) + get_uptime time_n + export -n "$1=$((time_n-time_u))" } } diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index c270b8a0e1..8858f93121 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -1108,7 +1108,7 @@ mwan3_report_iface_status() fi if [ "$status" = "online" ]; then - online=$(get_online_time "$1") + get_online_time online "$1" network_get_uptime uptime "$1" online="$(printf '%02dh:%02dm:%02ds\n' $((online/3600)) $((online%3600/60)) $((online%60)))" uptime="$(printf '%02dh:%02dm:%02ds\n' $((uptime/3600)) $((uptime%3600/60)) $((uptime%60)))" @@ -1128,7 +1128,7 @@ mwan3_report_iface_status() [ "$result" = "0" ] && result="" fi - tracking="$(mwan3_get_mwan3track_status $1)" + mwan3_get_mwan3track_status tracking $1 if [ -n "$result" ]; then echo " interface $1 is $status and tracking is $tracking ($result)" else diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 index 30c2550160..dbc5f57640 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -67,21 +67,21 @@ report_policies_v6() { get_age() { local time_p time_u - iface="$1" + iface="$2" readfile time_p "$MWAN3TRACK_STATUS_DIR/${iface}/TIME" [ -z "${time_p}" ] || { - time_n="$(get_uptime)" - echo $((time_n-time_p)) + get_uptime time_n + export -n "$1=$((time_n-time_p))" } } get_offline_time() { local time_n time_d iface - iface="$1" + iface="$2" readfile time_d "$MWAN3TRACK_STATUS_DIR/${iface}/OFFLINE" [ -z "${time_d}" ] || [ "${time_d}" = "0" ] || { - time_n="$(get_uptime)" - echo $((time_n-time_d)) + get_uptime time_n + export -n "$1=$((time_n-time_d))" } } @@ -98,11 +98,11 @@ get_mwan3_status() { return fi - track_status="$(mwan3_get_mwan3track_status "$1")" + mwan3_get_mwan3track_status track_status "$1" [ "$track_status" = "active" ] && running="1" - age=$(get_age "$iface") - online=$(get_online_time "$iface") - offline=$(get_offline_time "$iface") + get_age age "$iface" + get_online_time online "$iface" + get_offline_time offline "$iface" config_get_bool enabled "$iface" enabled 0 diff --git a/net/mwan3/files/usr/sbin/mwan3rtmon b/net/mwan3/files/usr/sbin/mwan3rtmon index 5f21d0203c..cb7e3492f8 100755 --- a/net/mwan3/files/usr/sbin/mwan3rtmon +++ b/net/mwan3/files/usr/sbin/mwan3rtmon @@ -107,7 +107,10 @@ mwan3_rtmon_route_handle() local iface=$1 tbl=$($IP route list table $tid 2>/dev/null)$'\n' - if [ -n "$iface" ] && [ "$(mwan3_get_mwan3track_status $iface)" != "active" ]; then + local status + mwan3_get_mwan3track_status status $iface + + if [ -n "$iface" ] && [ "$status" != "active" ]; then LOG debug "interface $iface is disabled - skipping '$route_line'"; return fi