modemmanager: improve cleanup of ifaces
authorOliver Sedlbauer <osedlbauer@tdt.de>
Tue, 17 Oct 2023 15:13:37 +0000 (17:13 +0200)
committerOliver Sedlbauer <osedlbauer@tdt.de>
Mon, 30 Oct 2023 07:53:10 +0000 (08:53 +0100)
Change workflow to cleanup interfaces using the sysfscache.
The sysfscache stores the processed sysfs-paths. Using this
instead of mmcli -L, the interfaces can be properly cleaned
up even if, for example, ModemManager crashes and mmcli is
no longer usable.

Signed-off-by: Oliver Sedlbauer <osedlbauer@tdt.de>
net/modemmanager/Makefile
net/modemmanager/files/modemmanager.common

index 82216ae4c1123be77a9b600f03895b9852290e14..bef514550df4cff0e4974916c9f07b0f2f72cd26 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=modemmanager
 PKG_SOURCE_VERSION:=1.22.0
-PKG_RELEASE:=3
+PKG_RELEASE:=4
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL:=https://gitlab.freedesktop.org/mobile-broadband/ModemManager.git
index d157cebf86cde524ad157460da46aa5f40362e13..2ba2036ce9281b61364ebbff598e1fb5fa11b0a3 100644 (file)
@@ -235,24 +235,20 @@ mm_report_modem_wait() {
 # Cleanup interfaces
 
 mm_cleanup_interfaces() {
-       local modemlist modemlength idx modeminfo modemsysfspath
-
-       modemlist=$(mmcli --list-modems --output-keyvalue)
-       [ -n "${modemlist}" ] || return 0
-
-       modemlength=$(modemmanager_get_field "${modemlist}" "modem-list.length")
-
-       # do nothing if no modem reported
-       [ -n "${modemlength}" ] && [ "${modemlength}" -ge 1 ] && {
-               idx=1
-               while [ $idx -le "$modemlength" ]; do
-                       modempath=$(modemmanager_get_field "${modemlist}" "modem-list.value\[$idx\]")
-                       modeminfo=$(mmcli --modem "${modempath}" --output-keyvalue)
-                       modemsysfspath=$(modemmanager_get_field "${modeminfo}" "modem.generic.device")
-                       mm_cleanup_interface_by_sysfspath "${modemsysfspath}"
-                       idx=$((idx + 1))
-               done
-       }
+       local sysfs_path status
+
+       # Do nothing if there is no sysfs cache
+       [ -f "${MODEMMANAGER_SYSFS_CACHE}" ] || return
+
+       while IFS= read -r sysfs_cache_line; do
+               sysfs_path=$(echo "${sysfs_cache_line}" | awk '{print $1}')
+               status=$(echo "${sysfs_cache_line}" | awk '{print $2}')
+
+               if [ "${status}" = "processed" ]; then
+                       mm_log "debug" "call cleanup for: ${sysfs_path}"
+                       mm_cleanup_interface_by_sysfspath "${sysfs_path}"
+               fi
+       done < ${MODEMMANAGER_SYSFS_CACHE}
 }
 
 mm_cleanup_interface_by_sysfspath() {