Skip to content

Commit 696ca45

Browse files
committed
app: script: Don't try to restart PPP if UART disappear
If the USB serial device is removed while PPP is running the script might try to restart the connection or try to run shutdown script and end up writing to a device files that don't exist. Add check, if devices are still present. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
1 parent 892c18d commit 696ca45

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

app/scripts/sm_start_ppp.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,20 @@ echo "Connect and wait for PPP link..."
254254

255255
chat $CHATOPT -t$TIMEOUT "${CHAT_SCRIPT[@]}" >$AT_CMUX <$AT_CMUX
256256

257+
check_devices_or_exit() {
258+
# Verify that UART devices are still present
259+
if [ ! -c $PPP_CMUX ] || [ ! -c $AT_CMUX ] || [ ! -c $MODEM ]; then
260+
echo "Error: UART devices not found, exiting..."
261+
start-stop-daemon --stop --pidfile $TRACE_PID_FILE --remove-pidfile \
262+
--oknodo --retry 1
263+
pkill ldattach
264+
exit 1
265+
fi
266+
}
267+
257268
shutdown_modem() {
258269
set +eu
270+
check_devices_or_exit
259271
start-stop-daemon --stop --pidfile $TRACE_PID_FILE --remove-pidfile --oknodo --retry 1
260272
chat $CHATOPT -t5 '' $SHUTDOWN_SCRIPT >$AT_CMUX <$AT_CMUX
261273
CHAT_ERR=$?
@@ -275,6 +287,7 @@ shutdown_modem() {
275287
ppp_start() {
276288
set +eu
277289
set -x
290+
check_devices_or_exit
278291
pppd $PPP_CMUX $PPP_OPTIONS
279292
if [ "$?" -eq 5 ]; then
280293
echo "pppd terminated with signal, shutting down modem..."
@@ -300,6 +313,7 @@ export TRACE_PID_FILE
300313
export -f ppp_start
301314
export -f shutdown_modem
302315
export -f cmux_close
316+
export -f check_devices_or_exit
303317

304318
# Start PPPD in a subshell
305319
# Logs go to syslog so redirect output to /dev/null

0 commit comments

Comments
 (0)