From: Karel Zak Date: Wed, 18 Aug 2010 07:02:03 +0000 (+0200) Subject: agetty: add -s to reuse existing baud rate X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=848e5e6ce3978d921366b799d907a78a12299924;p=util-linux agetty: add -s to reuse existing baud rate For example: /sbin/agetty -s /dev/ttyS0 9600 will reuse the speed the kernel configured on the port. If the setting from kernel is useless (tty returns BREAK character) then the baud rate from command line (9600) is used. Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=623685 Signed-off-by: Karel Zak --- diff --git a/login-utils/agetty.8 b/login-utils/agetty.8 index 87613747..53037dda 100644 --- a/login-utils/agetty.8 +++ b/login-utils/agetty.8 @@ -3,7 +3,7 @@ agetty \- alternative Linux getty .SH SYNOPSIS -.BR "agetty " [\-8ihLmnUw] +.BR "agetty " [\-8ihLmnsUw] .RI "[-f " issue_file ] .RI "[-l " login_program ] .RI "[-I " init ] @@ -12,16 +12,6 @@ agetty \- alternative Linux getty .I port .I baud_rate,... .RI [ term ] -.br -.BR "agetty " [\-8ihLmnw] -.RI "[-f " issue_file ] -.RI "[-l " login_program ] -.RI "[-I " init ] -.RI "[-t " timeout ] -.RI "[-H " login_host ] -.I baud_rate,... -.I port -.RI [ term ] .SH DESCRIPTION .ad @@ -163,6 +153,10 @@ Force the line to be a local line with no need for carrier detect. This can be useful when you have a locally attached terminal where the serial line does not set the carrier detect signal. .TP +\-s +Try to keep the existing baud rate. The baud rates from +the command line are used when agetty receives a BREAK character. +.TP \-U Turn on support for detecting an uppercase only terminal. This setting will detect a login name containing only capitals as indicating an uppercase diff --git a/login-utils/agetty.c b/login-utils/agetty.c index 39a1fd3e..9fc389b8 100644 --- a/login-utils/agetty.c +++ b/login-utils/agetty.c @@ -133,6 +133,7 @@ struct options { #define F_CUSTISSUE (1<<6) /* give alternative issue file */ #define F_NOPROMPT (1<<7) /* don't ask for login name! */ #define F_LCUC (1<<8) /* Support for *LCUC stty modes */ +#define F_KEEPSPEED (1<<9) /* Follow baud rate from kernel */ /* Storage for things detected while the login name was read. */ @@ -203,7 +204,7 @@ void parse_args P_((int argc, char **argv, struct options *op)); void parse_speeds P_((struct options *op, char *arg)); void update_utmp P_((char *line)); void open_tty P_((char *tty, struct termios *tp, int local)); -void termio_init P_((struct termios *tp, int speed, struct options *op)); +void termio_init P_((struct termios *tp, struct options *op)); void auto_baud P_((struct termios *tp)); void do_prompt P_((struct options *op, struct termios *tp)); void next_speed P_((struct termios *tp, struct options *op)); @@ -297,7 +298,7 @@ main(argc, argv) tcsetpgrp(0, getpid()); /* Initialize the termios settings (raw mode, eight-bit, blocking i/o). */ debug("calling termio_init\n"); - termio_init(&termios, options.speeds[FIRST_SPEED], &options); + termio_init(&termios, &options); /* write the modem init string and DON'T flush the buffers */ if (options.flags & F_INITSTRING) { @@ -373,7 +374,7 @@ parse_args(argc, argv, op) extern int optind; /* getopt */ int c; - while (isascii(c = getopt(argc, argv, "8I:LH:f:hil:mt:wUn"))) { + while (isascii(c = getopt(argc, argv, "8I:LH:f:hil:mst:wUn"))) { switch (c) { case '8': op->eightbits = 1; @@ -443,6 +444,9 @@ parse_args(argc, argv, op) case 'n': op->flags |= F_NOPROMPT; break; + case 's': + op->flags |= F_KEEPSPEED; /* keep kernel defined speed */ + break; case 't': /* time out */ if ((op->timeout = atoi(optarg)) <= 0) error(_("bad timeout value: %s"), optarg); @@ -691,9 +695,8 @@ char gbuf[1024]; char area[1024]; void -termio_init(tp, speed, op) +termio_init(tp, op) struct termios *tp; - int speed; struct options *op; { @@ -707,8 +710,11 @@ termio_init(tp, speed, op) (void) tcflush(0, TCIOFLUSH); tp->c_cflag = CS8 | HUPCL | CREAD; - cfsetispeed(tp, speed); - cfsetospeed(tp, speed); + + if (!(op->flags & F_KEEPSPEED)) { + cfsetispeed(tp, op->speeds[FIRST_SPEED]); + cfsetospeed(tp, op->speeds[FIRST_SPEED]); + } if (op->flags & F_LOCAL) { tp->c_cflag |= CLOCAL; } @@ -1203,7 +1209,7 @@ bcode(s) void usage() { - fprintf(stderr, _("Usage: %s [-8hiLmUw] [-l login_program] [-t timeout] [-I initstring] [-H login_host] baud_rate,... line [termtype]\nor\t[-hiLmw] [-l login_program] [-t timeout] [-I initstring] [-H login_host] line baud_rate,... [termtype]\n"), progname); + fprintf(stderr, _("Usage: %s [-8hiLmsUw] [-l login_program] [-t timeout] [-I initstring] [-H login_host] baud_rate,... line [termtype]\nor\t[-hiLmw] [-l login_program] [-t timeout] [-I initstring] [-H login_host] line baud_rate,... [termtype]\n"), progname); exit(1); }