From e9f64893ace549b019c1eceea1994a2f74574e8a Mon Sep 17 00:00:00 2001 From: Anatoly Mirin Date: Mon, 12 Jun 2023 23:48:08 +0300 Subject: [PATCH] mcastmngr: fix mcast stats script Fixed worng temp_igmp_file variable accessing, which caused the same 'temp_igmp_file' file to be used each time 'ubus call mcast stats' was called instead of /tmp/igmp_stats_ file. Because of this, temp file was sometimes overwritten by the next call before it had time to read and the IPTV_IGMP_4-12-1-24_2401.py test ended with an error. A waiting loop has also been added so that mcproxy has time to process the signal and write the dump to a file. --- mcastmngr/files/linux/usr/libexec/rpcd/mcast | 28 ++++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/mcastmngr/files/linux/usr/libexec/rpcd/mcast b/mcastmngr/files/linux/usr/libexec/rpcd/mcast index 4edf98120..62b399a4d 100755 --- a/mcastmngr/files/linux/usr/libexec/rpcd/mcast +++ b/mcastmngr/files/linux/usr/libexec/rpcd/mcast @@ -4,15 +4,27 @@ . /lib/functions.sh read_mcast_stats() { + local temp_igmp_file='/tmp/igmp_stats_'$$ + local snooping_stats='/tmp/igmp_snooping_stats' + local old_mod_time=$(date +%s 2>/dev/null -r "$snooping_stats") - temp_igmp_file='/tmp/igmp_stats_'$$ # Sending signal to mcproxy to dump multicast data in /tmp/igmp_snooping_stats - mcast_pids=$(pidof mcproxy) + local mcast_pids=$(pidof mcproxy) for pid in $mcast_pids do $(kill -10 $pid) done - cat /tmp/igmp_snooping_stats > temp_igmp_file + + # Wait for signal is being processed by mcproxy + if [ -n "$mcast_pids" ]; then + for i in 1 2 3; do + local new_mod_time=$(date +%s 2>/dev/null -r "$snooping_stats") + [ -n "$new_mod_time" ] && [ "$new_mod_time" != "$old_mod_time" ] && break + sleep 0.1 + done + fi + + cat "$snooping_stats" > "$temp_igmp_file" local mcast_addrs="" local ifaces="" @@ -42,7 +54,7 @@ read_mcast_stats() { fi ;; esac - done < temp_igmp_file + done < "$temp_igmp_file" while read line; do # reading each line @@ -69,7 +81,7 @@ read_mcast_stats() { fi ;; esac - done < temp_igmp_file + done < "$temp_igmp_file" json_init json_add_array "snooping" @@ -89,7 +101,7 @@ read_mcast_stats() { break ;; esac - done < temp_igmp_file + done < "$temp_igmp_file" IFS=" " for gip_addr in $mcast_addrs; do grp_obj_added=0 @@ -124,7 +136,7 @@ read_mcast_stats() { json_close_object #close the associated device object ;; esac - done < temp_igmp_file + done < "$temp_igmp_file" json_close_array #close the associated devices array json_close_object # close the groups object done # close the loop for group addresses @@ -134,7 +146,7 @@ read_mcast_stats() { json_close_array # close the snooping array json_dump - rm -f temp_igmp_file + rm -f "$temp_igmp_file" } case "$1" in