From a11850cc45360d16dc879812377ef68a7d9210fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lesimple?= Date: Sat, 29 Oct 2016 02:21:05 +0200 Subject: [PATCH] rc: fix an infinite loop on tty close if the tty is closed while the script is running, it would previously go in an infinite loop trying to read from and write to the now-defunct tty. fixes: https://github.com/opnsense/core/issues/1240 --- src/etc/rc.initial | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/etc/rc.initial b/src/etc/rc.initial index f96fb07e0..bceb0ce98 100755 --- a/src/etc/rc.initial +++ b/src/etc/rc.initial @@ -18,6 +18,13 @@ fi # endless loop while : ; do +# We `set -e' to force exit if we encounter an error. +# This is mainly useful in case we lose our tty (happens when +# an ssh connection breaks, for example), in which case our stdout +# is closed and the `echo' commands in the while loop will silently fail. +# Failure to exit at that moment would lead to an infinite loop. +set -e + echo echo " 0) Logout 7) Ping host" @@ -32,6 +39,9 @@ echo read -p "Enter an option: " OPCODE echo +# The scripts we'll call below may return non-zero, don't exit if they do +set +e + # see what the user has chosen case ${OPCODE} in 0|exit|logout|quit)