summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-01-26 03:26:38 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-01-26 03:26:38 +0100
commitd8494934a7b7cb8063282b03a6b996c9b7cec42a (patch)
tree4a541ef2004496f918a310ab75690d147dcfe270
parentea023eacad23f6a30cffe4f255a050b91748fc2f (diff)
downloadbusybox-w32-d8494934a7b7cb8063282b03a6b996c9b7cec42a.tar.gz
busybox-w32-d8494934a7b7cb8063282b03a6b996c9b7cec42a.tar.bz2
busybox-w32-d8494934a7b7cb8063282b03a6b996c9b7cec42a.zip
getty: explain every bit in termios; remove redundant stuff in termios_final
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--console-tools/resize.c1
-rw-r--r--loginutils/getty.c67
2 files changed, 32 insertions, 36 deletions
diff --git a/console-tools/resize.c b/console-tools/resize.c
index fdfe2a6a0..ee0728b71 100644
--- a/console-tools/resize.c
+++ b/console-tools/resize.c
@@ -53,6 +53,7 @@ int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
53 */ 53 */
54 fprintf(stderr, ESC"7" ESC"[r" ESC"[999;999H" ESC"[6n"); 54 fprintf(stderr, ESC"7" ESC"[r" ESC"[999;999H" ESC"[6n");
55 alarm(3); /* Just in case terminal won't answer */ 55 alarm(3); /* Just in case terminal won't answer */
56//BUG: death by signal won't restore termios
56 scanf(ESC"[%hu;%huR", &w.ws_row, &w.ws_col); 57 scanf(ESC"[%hu;%huR", &w.ws_row, &w.ws_col);
57 fprintf(stderr, ESC"8"); 58 fprintf(stderr, ESC"8");
58 59
diff --git a/loginutils/getty.c b/loginutils/getty.c
index b71d68a1f..29d889f43 100644
--- a/loginutils/getty.c
+++ b/loginutils/getty.c
@@ -106,15 +106,15 @@ struct globals {
106//usage:#define getty_full_usage "\n\n" 106//usage:#define getty_full_usage "\n\n"
107//usage: "Open a tty, prompt for a login name, then invoke /bin/login\n" 107//usage: "Open a tty, prompt for a login name, then invoke /bin/login\n"
108//usage: "\nOptions:" 108//usage: "\nOptions:"
109//usage: "\n -h Enable hardware (RTS/CTS) flow control" 109//usage: "\n -h Enable hardware RTS/CTS flow control"
110//usage: "\n -i Don't display /etc/issue" 110//usage: "\n -L Set CLOCAL (ignore Carrier Detect state)"
111//usage: "\n -L Local line, set CLOCAL on it"
112//usage: "\n -m Get baud rate from modem's CONNECT status message" 111//usage: "\n -m Get baud rate from modem's CONNECT status message"
112//usage: "\n -n Don't prompt for login name"
113//usage: "\n -w Wait for CR or LF before sending /etc/issue" 113//usage: "\n -w Wait for CR or LF before sending /etc/issue"
114//usage: "\n -n Don't prompt for a login name" 114//usage: "\n -i Don't display /etc/issue"
115//usage: "\n -f ISSUE_FILE Display ISSUE_FILE instead of /etc/issue" 115//usage: "\n -f ISSUE_FILE Display ISSUE_FILE instead of /etc/issue"
116//usage: "\n -l LOGIN Invoke LOGIN instead of /bin/login" 116//usage: "\n -l LOGIN Invoke LOGIN instead of /bin/login"
117//usage: "\n -t SEC Terminate after SEC if no username is read" 117//usage: "\n -t SEC Terminate after SEC if no login name is read"
118//usage: "\n -I INITSTR Send INITSTR before anything else" 118//usage: "\n -I INITSTR Send INITSTR before anything else"
119//usage: "\n -H HOST Log HOST into the utmp file as the hostname" 119//usage: "\n -H HOST Log HOST into the utmp file as the hostname"
120//usage: "\n" 120//usage: "\n"
@@ -251,21 +251,28 @@ static void termios_init(int speed)
251 * reads will be done in raw mode anyway. Errors will be dealt with 251 * reads will be done in raw mode anyway. Errors will be dealt with
252 * later on. 252 * later on.
253 */ 253 */
254 /* 8 bits; hangup (drop DTR) on last close; enable receive */
254 G.termios.c_cflag = CS8 | HUPCL | CREAD; 255 G.termios.c_cflag = CS8 | HUPCL | CREAD;
255 if (option_mask32 & F_LOCAL) 256 if (option_mask32 & F_LOCAL) {
257 /* ignore Carrier Detect pin:
258 * opens don't block when CD is low,
259 * losing CD doesn't hang up processes whose ctty is this tty
260 */
256 G.termios.c_cflag |= CLOCAL; 261 G.termios.c_cflag |= CLOCAL;
262 }
263#ifdef CRTSCTS
264 if (option_mask32 & F_RTSCTS)
265 G.termios.c_cflag |= CRTSCTS; /* flow control using RTS/CTS pins */
266#endif
257 G.termios.c_iflag = 0; 267 G.termios.c_iflag = 0;
258 G.termios.c_lflag = 0; 268 G.termios.c_lflag = 0;
269 /* non-raw output; add CR to each NL */
259 G.termios.c_oflag = OPOST | ONLCR; 270 G.termios.c_oflag = OPOST | ONLCR;
260 G.termios.c_cc[VMIN] = 1; 271 G.termios.c_cc[VMIN] = 1; /* block reads if < 1 char is available */
261 G.termios.c_cc[VTIME] = 0; 272 G.termios.c_cc[VTIME] = 0; /* no timeout (reads block forever) */
262#ifdef __linux__ 273#ifdef __linux__
263 G.termios.c_line = 0; 274 G.termios.c_line = 0;
264#endif 275#endif
265#ifdef CRTSCTS
266 if (option_mask32 & F_RTSCTS)
267 G.termios.c_cflag |= CRTSCTS;
268#endif
269 276
270 tcsetattr_stdin_TCSANOW(&G.termios); 277 tcsetattr_stdin_TCSANOW(&G.termios);
271 278
@@ -274,12 +281,17 @@ static void termios_init(int speed)
274 281
275static void termios_final(void) 282static void termios_final(void)
276{ 283{
277 /* General terminal-independent stuff */ 284 /* software flow control on output; and on input */
278 G.termios.c_iflag |= IXON | IXOFF; /* 2-way flow control */ 285 G.termios.c_iflag |= IXON | IXOFF;
286 if (G.eol == '\r') {
287 G.termios.c_iflag |= ICRNL; /* map CR on input to NL */
288 }
289 /* non-raw input; enable SIGINT/QUIT/ec sigs; echo; echo NL on kill char;
290 * erase entire line via BS-space-BS on kill char */
279 G.termios.c_lflag |= ICANON | ISIG | ECHO | ECHOE | ECHOK | ECHOKE; 291 G.termios.c_lflag |= ICANON | ISIG | ECHO | ECHOE | ECHOK | ECHOKE;
280 /* no longer in lflag: | ECHOCTL | ECHOPRT */ 292 /* echo ctrl chars as ^c; (what is ECHOPRT?) */
281 G.termios.c_oflag |= OPOST; 293 /* no longer in c_lflag: | ECHOCTL | ECHOPRT */
282 /* G.termios.c_cflag = 0; */ 294
283 G.termios.c_cc[VINTR] = DEF_INTR; 295 G.termios.c_cc[VINTR] = DEF_INTR;
284 G.termios.c_cc[VQUIT] = DEF_QUIT; 296 G.termios.c_cc[VQUIT] = DEF_QUIT;
285 G.termios.c_cc[VEOF] = DEF_EOF; 297 G.termios.c_cc[VEOF] = DEF_EOF;
@@ -290,22 +302,8 @@ static void termios_final(void)
290#ifdef VSWTCH 302#ifdef VSWTCH
291 G.termios.c_cc[VSWTCH] = DEF_SWITCH; 303 G.termios.c_cc[VSWTCH] = DEF_SWITCH;
292#endif 304#endif
293
294 /* Account for special characters seen in input */
295 if (G.eol == '\r') {
296 G.termios.c_iflag |= ICRNL; /* map CR in input to NL */
297 /* already done by termios_init */
298 /* G.termios.c_oflag |= ONLCR; map NL in output to CR-NL */
299 }
300 G.termios.c_cc[VKILL] = DEF_KILL; 305 G.termios.c_cc[VKILL] = DEF_KILL;
301 306
302#ifdef CRTSCTS
303 /* Optionally enable hardware flow control */
304 if (option_mask32 & F_RTSCTS)
305 G.termios.c_cflag |= CRTSCTS;
306#endif
307
308 /* Finally, make the new settings effective */
309 if (tcsetattr_stdin_TCSANOW(&G.termios) < 0) 307 if (tcsetattr_stdin_TCSANOW(&G.termios) < 0)
310 bb_perror_msg_and_die("tcsetattr"); 308 bb_perror_msg_and_die("tcsetattr");
311} 309}
@@ -330,11 +328,7 @@ static void auto_baud(void)
330 * modem status messages is enabled. 328 * modem status messages is enabled.
331 */ 329 */
332 330
333 /* 331 G.termios.c_cc[VMIN] = 0; /* don't block reads (min read is 0 chars) */
334 * Don't block if input queue is empty.
335 * Errors will be dealt with later on.
336 */
337 G.termios.c_cc[VMIN] = 0; /* don't block if queue empty */
338 tcsetattr_stdin_TCSANOW(&G.termios); 332 tcsetattr_stdin_TCSANOW(&G.termios);
339 333
340 /* 334 /*
@@ -538,6 +532,7 @@ int getty_main(int argc UNUSED_PARAM, char **argv)
538 532
539 /* Set the optional timer */ 533 /* Set the optional timer */
540 alarm(G.timeout); /* if 0, alarm is not set */ 534 alarm(G.timeout); /* if 0, alarm is not set */
535//BUG: death by signal won't restore termios
541 536
542 /* Optionally wait for CR or LF before writing /etc/issue */ 537 /* Optionally wait for CR or LF before writing /etc/issue */
543 if (option_mask32 & F_WAITCRLF) { 538 if (option_mask32 & F_WAITCRLF) {