modemmanager: fix pending mmcli calls for ModemManager-monitor script
authorFlorian Eckert <[email protected]>
Tue, 4 Mar 2025 09:22:41 +0000 (10:22 +0100)
committerFlorian Eckert <[email protected]>
Tue, 1 Apr 2025 08:08:27 +0000 (10:08 +0200)
If the ModemManager is stopped via '/etc/init.d/modemmanager', mmcli calls
always remain in the process list. This is because the ModemManager-monitor
call is not terminated properly, as the kill signals are not handled
correctly in the startup script for mmcli.

To fix this, the signal handling is refactored.

Signed-off-by: Florian Eckert <[email protected]>
net/modemmanager/Makefile
net/modemmanager/files/usr/sbin/ModemManager-monitor

index 69d364a767b3ebfccabe88ffb7833f548531b177..2eb06ab4bb987375a8bfe043344a4fb1c22b6653 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=modemmanager
 PKG_VERSION:=1.22.0
-PKG_RELEASE:=22
+PKG_RELEASE:=23
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL:=https://gitlab.freedesktop.org/mobile-broadband/ModemManager.git
index 44fdab5949bc7974b7a61f5ffe71da2caaefdbd4..08509e7b7b3afb37d798272b1f53f999ac540143 100644 (file)
@@ -6,9 +6,10 @@
 
 trap_with_arg() {
        func="$1" ; shift
+       pid="$1" ; shift
        for sig ; do
                # shellcheck disable=SC2064
-               trap "$func $sig" "$sig"
+               trap "$func $sig $pid" "$sig"
        done
 }
 
@@ -23,7 +24,7 @@ func_trap() {
                mm_monitor_cache_remove "$object"
        done < ${MODEMMANAGER_MONITOR_CACHE}
 
-       kill "-${1}" "$CHILD" 2>/dev/null
+       kill "-${1}" "$2" 2>/dev/null
 }
 
 mm_monitor_get_sysfspath() {
@@ -116,8 +117,6 @@ main() {
        local step=1
        local mmrunning=0
 
-       trap_with_arg func_trap INT TERM KILL
-
        mkdir -p "${MODEMMANAGER_RUNDIR}"
        chmod 0755 "${MODEMMANAGER_RUNDIR}"
 
@@ -140,16 +139,18 @@ main() {
                return
        }
 
-       /usr/bin/mmcli -M | {
+       sh -c "echo \$\$; exec /usr/bin/mmcli -M" | {
+               read -r monitor_pid
+               trap_with_arg func_trap "$monitor_pid" SIGINT SIGTERM SIGKILL
                local line
                while read -r line; do
                        mm_log "debug" "Monitor cache line: ${line}"
                        mm_monitor_cache "$line"
                done
        } &
-       CHILD="$!"
-
-       wait $CHILD
+       child="$!"
+       trap_with_arg func_trap "$child" SIGINT SIGTERM SIGKILL
+       wait $child
 }
 
 main "$@"