From 72a5162ef9e746b153e1b6b648b7800d41ad7090 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 5 May 2024 12:03:19 +0200 Subject: system: support activating extra consoles at the service level In addition to autodetected consoles, we can now activate extra consoles using the extra_consoles variable. It's multi-valued so it can get multiple consoles either on one or multiple lines, all are cumulated. Since they're all processed in order, it's even possible to redefine an already defined console. The syntax for each of them is: device[:[speed][:[term]]] The default speed will continue to be "-s" (don't change) if unspecified or empty. The default term will remain "linux". But for example it's possible to change the ttyS0 speed even if it's the console: extra_consoles ttyS0:115200 or to just change the terminal type: extra_consoles ttyS0::vt320 Since these consoles are processed just like the default ones, passing any "tty[0-9]" will be sufficient to immediately enable the VTs with the configured number of VTs or 4 by default. It can make sense to have: extra_consoles tty0 ttyUSB0 in the defaults of a headless system to which connections may happen once in a while by bringing a monitor or by connecting a USB adapter for example. --- sbin/init.d/system | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/sbin/init.d/system b/sbin/init.d/system index e94be46..e5c9cd4 100755 --- a/sbin/init.d/system +++ b/sbin/init.d/system @@ -17,6 +17,7 @@ option rtc_mode standard_option "direct" # "direct", "kernel" option nv_auto_mount boolean_option option nv_auto_format boolean_option option vt_consoles standard_option # 0..63 or leave empty for auto +option extra_consoles multiple_option # ttyS0:9600:vt100 tty0 ttyUSB1 function do_help { @@ -33,6 +34,7 @@ function do_help { echo " - nv_auto_mount : boolean ; default= ; cur=$opt_nv_auto_mount" echo " - nv_auto_format : boolean ; default= ; cur=$opt_nv_auto_format" echo " - vt_consoles : integer ; default= ; cur=$opt_vt_consoles" + echo " - extra_consoles : names ; eg: ttyS0:9600 ; cur=${opt_extra_consoles[@]}" echo exit 1 } @@ -77,7 +79,7 @@ function do_date_from_hw { function update_consoles { local consoles=( ) local ser_consoles=( ) - local line num name path dev + local line num name path dev spd term local touched=0 local use_vt=0 @@ -97,8 +99,9 @@ function update_consoles { use_vt=1 fi - # consoles[@] is of the form "name [major:minor]" for each line - for line in "${consoles[@]}"; do + # consoles[@] is of the form "name[:spd[:term]] [major:minor]" for each line + # Note that we may have multiple entries in one extra_console line. + for line in "${consoles[@]}" ${opt_extra_consoles[*]}; do set -- $line name="$1" dev="${!#}" @@ -118,7 +121,7 @@ function update_consoles { [ -z "$path" ] || name="$path" fi - path="/dev/${name}" + path="/dev/${name%%:*}" if [ ! -e "${path}" ]; then mkdir -p "${path%/*}" mknod c "${path}" "${dev%:*}" "${dev#*:}" @@ -158,9 +161,15 @@ function update_consoles { # Then we'll add all remaining consoles that were passed by the boot # loader. Since they may collide with already configured ones and we have 4 - # chars for the IDs, we'll name them from s100 to s999. + # chars for the IDs, we'll name them from s100 to s999. Serial terms may + # optionally have a baud rate after a first colon, and a term type after + # the second colon. num=0 for name in "${ser_consoles[@]}"; do + name="${name}:" + spd="${name#*:}"; name="${name%%:*}" + term="${spd#*:}"; spd="${spd%%:*}" + term="${term%%:*}" sed -i -e "/^[^:]*:[^:]*:[^:]*:\([^/]*\/\)*agetty.*\b${name##*/}\b/d" /etc/inittab # missing entries in /dev for existing devices will not magically # appear under us so we must create them. Other ones are not a @@ -174,8 +183,9 @@ function update_consoles { chown root:tty "${path}" chmod 620 "${path}" fi - # all console devices keep their original speed. - echo "s$((100+num)):1245:respawn:/sbin/agetty -L -s $name linux" >> /etc/inittab + # all console devices keep their original speed if not set, and have + # the term type "linux" by default. + echo "s$((100+num)):1245:respawn:/sbin/agetty -L ${spd:--s} $name ${term:-linux}" >> /etc/inittab ((num++)) touched=1 done -- 2.17.5