Skip to content

Commit

Permalink
Merge pull request openwrt#22486 from osedl/modemmanager-improve-cleanup
Browse files Browse the repository at this point in the history
modemmanager improve cleanup
  • Loading branch information
feckert committed Oct 30, 2023
2 parents eb40c17 + 074741e commit ac9973b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion net/modemmanager/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk

PKG_NAME:=modemmanager
PKG_SOURCE_VERSION:=1.22.0
PKG_RELEASE:=3
PKG_RELEASE:=5

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://gitlab.freedesktop.org/mobile-broadband/ModemManager.git
Expand Down
32 changes: 14 additions & 18 deletions net/modemmanager/files/modemmanager.common
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 0 additions & 7 deletions net/modemmanager/files/modemmanager.init
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ START=70

LOG_LEVEL="INFO"

stop_service() {
# Load common utils
. /usr/share/ModemManager/modemmanager.common
# Set all configured interfaces as unavailable
mm_cleanup_interfaces
}

start_service() {
# Setup ModemManager service
#
Expand Down
4 changes: 3 additions & 1 deletion net/modemmanager/files/usr/sbin/ModemManager-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ main() {

mkdir -p "${MODEMMANAGER_RUNDIR}"
chmod 0755 "${MODEMMANAGER_RUNDIR}"
mm_cleanup_interfaces

/usr/sbin/ModemManager "$@" 1>/dev/null 2>/dev/null &
CHILD="$!"

mm_report_events_from_cache

wait "$CHILD"

# Set all configured interfaces as unavailable
mm_cleanup_interfaces
}

main "$@"

0 comments on commit ac9973b

Please sign in to comment.