From: Karel Zak Date: Mon, 4 May 2020 10:27:42 +0000 (+0200) Subject: agetty: save the original speed on --keep-baud X-Git-Tag: v2.36-rc1~120 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d855a83095adc953cc9a0df8998a2f916242695;p=thirdparty%2Futil-linux.git agetty: save the original speed on --keep-baud agetty cycling through the baud rates specified on command line (triggered by BREAK). Unfortunately, the original baud rate (probably the best one) is tried only first time on --keep-baud. Addresses: https://github.com/karelzak/util-linux/issues/1025 Signed-off-by: Karel Zak --- diff --git a/term-utils/agetty.8 b/term-utils/agetty.8 index 1c9e388448..fa92df09cb 100644 --- a/term-utils/agetty.8 +++ b/term-utils/agetty.8 @@ -238,8 +238,10 @@ Change root to the specified directory. Call vhangup() to do a virtual hangup of the specified terminal. .TP \-s, \-\-keep\-baud -Try to keep the existing baud rate. The baud rates from -the command line are used when agetty receives a BREAK character. +Try to keep the existing baud rate. The baud rates from the command line are +used when agetty receives a BREAK character. If another baud rates specified +then the original baud rate is also saved to the end of the wanted baud rates +list. It allows to return to the original baud rate after unexpected BREAKs. .TP \-t, \-\-timeout \fItimeout\fP Terminate if no user name could be read within \fItimeout\fP seconds. diff --git a/term-utils/agetty.c b/term-utils/agetty.c index 861a56d126..46f1f24343 100644 --- a/term-utils/agetty.c +++ b/term-utils/agetty.c @@ -1279,9 +1279,17 @@ static void termio_init(struct options *op, struct termios *tp) ispeed = cfgetispeed(tp); ospeed = cfgetospeed(tp); - if (!ispeed) ispeed = TTYDEF_SPEED; - if (!ospeed) ospeed = TTYDEF_SPEED; - + /* Save also the original speed to array of the speeds to make + * it possible to return the the original after unexpected BREAKs. + */ + if (op->numspeed) + op->speeds[op->numspeed++] = ispeed ? ispeed : + ospeed ? ospeed : + TTYDEF_SPEED; + if (!ispeed) + ispeed = TTYDEF_SPEED; + if (!ospeed) + ospeed = TTYDEF_SPEED; } else { ospeed = ispeed = op->speeds[FIRST_SPEED]; }