From 0d855a83095adc953cc9a0df8998a2f916242695 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 4 May 2020 12:27:42 +0200 Subject: [PATCH] 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 --- term-utils/agetty.8 | 6 ++++-- term-utils/agetty.c | 14 +++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/term-utils/agetty.8 b/term-utils/agetty.8 index 1c9e38844..fa92df09c 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 861a56d12..46f1f2434 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]; }