Update modem status state on errors

If modemmonitor crash for some reason, status bar is not updated. The
reason is that statusbar check if modemmonitor is running, which it is
when trying to shutdown itself.

We change the way modemmonitor is detected using a single modem state
file. If the file is not present, then the monitor is considered not
running.

This single file permit to add more state in the future, without adding
any more files.

We also add a sleep 1, look like it is required to have instand status
bar update.

Signed-off-by: Stacy Harper <contact@stacyharper.net>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
This commit is contained in:
Stacy Harper 2021-04-05 11:40:18 +02:00 committed by Maarten van Gompel
parent d2d06ef65a
commit f9b96d2d28
3 changed files with 24 additions and 14 deletions

View file

@ -12,6 +12,9 @@ err() {
}
gracefulexit() {
rm "$MODEMSTATEFILE"
sxmo_statusbarupdate.sh
sleep 1
echo "sxmo_modemmonitor: gracefully exiting (on signal or after error)">&2
kill -9 0
}
@ -183,15 +186,17 @@ checkfornewtexts() {
}
initialmodemstatus() {
rm /tmp/modem.*.state 2>/dev/null
touch "$MODEMSTATEFILE"
state=$(mmcli -m "$(modem_n)")
if echo "$state" | grep -q -E "^.*state:.*connected.*$"; then
touch /tmp/modem.connected.state
echo connected > "$MODEMSTATEFILE"
elif echo "$state" | grep -q -E "^.*state:.*registered.*$"; then
touch /tmp/modem.registered.state
echo registered > "$MODEMSTATEFILE"
elif echo "$state" | grep -q -E "^.*state:.*locked.*$"; then
touch /tmp/modem.locked.state
echo locked > "$MODEMSTATEFILE"
pidof sxmo_unlocksim.sh || sxmo_unlocksim.sh &
else
echo unknown > "$MODEMSTATEFILE"
fi
}
@ -228,21 +233,22 @@ mainloop() {
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem',type='signal',member='StateChanged'" | \
while read -r line; do
if echo "$line" | grep -E "^signal.*StateChanged"; then
rm /tmp/modem.*.state 2>/dev/null
# shellcheck disable=SC2034
read -r oldstate #unused but we need to read past it
read -r newstate
if echo "$newstate" | grep "int32 2"; then
touch /tmp/modem.locked.state
echo locked > "$MODEMSTATEFILE"
pidof sxmo_unlocksim.sh || sxmo_unlocksim.sh &
elif echo "$newstate" | grep "int32 8"; then
touch /tmp/modem.registered.state
echo registered > "$MODEMSTATEFILE"
checkforfinishedcalls
checkforincomingcalls
checkfornewtexts
elif echo "$newstate" | grep "int32 11"; then
touch /tmp/modem.connected.state
echo connected > "$MODEMSTATEFILE"
#3G/2G/4G available
else
echo unknown > "$MODEMSTATEFILE"
fi
sxmo_statusbarupdate.sh
fi
@ -253,7 +259,7 @@ mainloop() {
wait
wait
rm /tmp/modem.*.state 2>/dev/null
rm "$MODEMSTATEFILE" 2>/dev/null
sxmo_statusbarupdate.sh
}