aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremie Koenig <jk@jk.fr.eu.org>2010-05-27 15:37:32 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-07-19 00:45:42 +0200
commitf812eace1863feeac64dc8af27f4ab0f98119618 (patch)
treec43fa6cadcde7037f33dd774d4bb2128e5583c2a
parent1d7266d3b59be361763dab61f680103bbb70f3e9 (diff)
downloadbusybox-w32-f812eace1863feeac64dc8af27f4ab0f98119618.tar.gz
busybox-w32-f812eace1863feeac64dc8af27f4ab0f98119618.tar.bz2
busybox-w32-f812eace1863feeac64dc8af27f4ab0f98119618.zip
init,loginutils: termios portability fixes
Signed-off-by: Jeremie Koenig <jk@jk.fr.eu.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--init/init.c17
-rw-r--r--loginutils/Config.src2
-rw-r--r--loginutils/getty.c27
-rw-r--r--loginutils/login.c2
4 files changed, 31 insertions, 17 deletions
diff --git a/init/init.c b/init/init.c
index 2eb8f1a54..1388c75cc 100644
--- a/init/init.c
+++ b/init/init.c
@@ -14,11 +14,19 @@
14#include <paths.h> 14#include <paths.h>
15#include <sys/reboot.h> 15#include <sys/reboot.h>
16#include <sys/resource.h> 16#include <sys/resource.h>
17#ifdef __linux__
17#include <linux/vt.h> 18#include <linux/vt.h>
19#endif
18#if ENABLE_FEATURE_UTMP 20#if ENABLE_FEATURE_UTMP
19# include <utmp.h> /* DEAD_PROCESS */ 21# include <utmp.h> /* DEAD_PROCESS */
20#endif 22#endif
21 23
24/* Used only for sanitizing purposes in set_sane_term() below. On systems where
25 * the baud rate is stored in a separate field, we can safely disable them. */
26#ifndef CBAUD
27# define CBAUD 0
28# define CBAUDEX 0
29#endif
22 30
23/* Was a CONFIG_xxx option. A lot of people were building 31/* Was a CONFIG_xxx option. A lot of people were building
24 * not fully functional init by switching it on! */ 32 * not fully functional init by switching it on! */
@@ -166,7 +174,9 @@ static void message(int where, const char *fmt, ...)
166 174
167static void console_init(void) 175static void console_init(void)
168{ 176{
177#ifdef VT_OPENQRY
169 int vtno; 178 int vtno;
179#endif
170 char *s; 180 char *s;
171 181
172 s = getenv("CONSOLE"); 182 s = getenv("CONSOLE");
@@ -190,6 +200,7 @@ static void console_init(void)
190 } 200 }
191 201
192 s = getenv("TERM"); 202 s = getenv("TERM");
203#ifdef VT_OPENQRY
193 if (ioctl(STDIN_FILENO, VT_OPENQRY, &vtno) != 0) { 204 if (ioctl(STDIN_FILENO, VT_OPENQRY, &vtno) != 0) {
194 /* Not a linux terminal, probably serial console. 205 /* Not a linux terminal, probably serial console.
195 * Force the TERM setting to vt102 206 * Force the TERM setting to vt102
@@ -198,7 +209,9 @@ static void console_init(void)
198 putenv((char*)"TERM=vt102"); 209 putenv((char*)"TERM=vt102");
199 if (!ENABLE_FEATURE_INIT_SYSLOG) 210 if (!ENABLE_FEATURE_INIT_SYSLOG)
200 log_console = NULL; 211 log_console = NULL;
201 } else if (!s) 212 } else
213#endif
214 if (!s)
202 putenv((char*)"TERM=linux"); 215 putenv((char*)"TERM=linux");
203} 216}
204 217
@@ -220,8 +233,10 @@ static void set_sane_term(void)
220 tty.c_cc[VSTOP] = 19; /* C-s */ 233 tty.c_cc[VSTOP] = 19; /* C-s */
221 tty.c_cc[VSUSP] = 26; /* C-z */ 234 tty.c_cc[VSUSP] = 26; /* C-z */
222 235
236#ifdef __linux__
223 /* use line discipline 0 */ 237 /* use line discipline 0 */
224 tty.c_line = 0; 238 tty.c_line = 0;
239#endif
225 240
226 /* Make it be sane */ 241 /* Make it be sane */
227 tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD; 242 tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD;
diff --git a/loginutils/Config.src b/loginutils/Config.src
index 425d041b9..6ec289355 100644
--- a/loginutils/Config.src
+++ b/loginutils/Config.src
@@ -179,7 +179,6 @@ config DELUSER
179config GETTY 179config GETTY
180 bool "getty" 180 bool "getty"
181 default y 181 default y
182 depends on PLATFORM_LINUX
183 select FEATURE_SYSLOG 182 select FEATURE_SYSLOG
184 help 183 help
185 getty lets you log in on a tty, it is normally invoked by init. 184 getty lets you log in on a tty, it is normally invoked by init.
@@ -187,7 +186,6 @@ config GETTY
187config LOGIN 186config LOGIN
188 bool "login" 187 bool "login"
189 default y 188 default y
190 depends on PLATFORM_LINUX
191 select FEATURE_SUID 189 select FEATURE_SUID
192 select FEATURE_SYSLOG 190 select FEATURE_SYSLOG
193 help 191 help
diff --git a/loginutils/getty.c b/loginutils/getty.c
index a5e8e906a..7f04d33fb 100644
--- a/loginutils/getty.c
+++ b/loginutils/getty.c
@@ -282,10 +282,8 @@ static void termios_init(struct termios *tp, int speed, struct options *op)
282 * reads will be done in raw mode anyway. Errors will be dealt with 282 * reads will be done in raw mode anyway. Errors will be dealt with
283 * later on. 283 * later on.
284 */ 284 */
285#ifdef __linux__
286 /* flush input and output queues, important for modems! */ 285 /* flush input and output queues, important for modems! */
287 ioctl(0, TCFLSH, TCIOFLUSH); /* tcflush(0, TCIOFLUSH)? - same */ 286 tcflush(0, TCIOFLUSH);
288#endif
289 ispeed = ospeed = speed; 287 ispeed = ospeed = speed;
290 if (speed == B0) { 288 if (speed == B0) {
291 /* Speed was specified as "0" on command line. 289 /* Speed was specified as "0" on command line.
@@ -299,10 +297,13 @@ static void termios_init(struct termios *tp, int speed, struct options *op)
299 cfsetispeed(tp, ispeed); 297 cfsetispeed(tp, ispeed);
300 cfsetospeed(tp, ospeed); 298 cfsetospeed(tp, ospeed);
301 299
302 tp->c_iflag = tp->c_lflag = tp->c_line = 0; 300 tp->c_iflag = tp->c_lflag = 0;
303 tp->c_oflag = OPOST | ONLCR; 301 tp->c_oflag = OPOST | ONLCR;
304 tp->c_cc[VMIN] = 1; 302 tp->c_cc[VMIN] = 1;
305 tp->c_cc[VTIME] = 0; 303 tp->c_cc[VTIME] = 0;
304#ifdef __linux__
305 tp->c_line = 0;
306#endif
306 307
307 /* Optionally enable hardware flow control */ 308 /* Optionally enable hardware flow control */
308#ifdef CRTSCTS 309#ifdef CRTSCTS
@@ -360,10 +361,8 @@ static void auto_baud(char *buf, unsigned size_buf, struct termios *tp)
360 for (bp = buf; bp < buf + nread; bp++) { 361 for (bp = buf; bp < buf + nread; bp++) {
361 if (isdigit(*bp)) { 362 if (isdigit(*bp)) {
362 speed = bcode(bp); 363 speed = bcode(bp);
363 if (speed > 0) { 364 if (speed > 0)
364 tp->c_cflag &= ~CBAUD; 365 cfsetspeed(tp, speed);
365 tp->c_cflag |= speed;
366 }
367 break; 366 break;
368 } 367 }
369 } 368 }
@@ -417,7 +416,7 @@ static char *get_logname(char *logname, unsigned size_logname,
417 416
418 /* Flush pending input (esp. after parsing or switching the baud rate). */ 417 /* Flush pending input (esp. after parsing or switching the baud rate). */
419 sleep(1); 418 sleep(1);
420 ioctl(0, TCFLSH, TCIFLUSH); /* tcflush(0, TCIOFLUSH)? - same */ 419 tcflush(0, TCIOFLUSH);
421 420
422 /* Prompt for and read a login name. */ 421 /* Prompt for and read a login name. */
423 logname[0] = '\0'; 422 logname[0] = '\0';
@@ -526,7 +525,9 @@ static void termios_final(struct options *op, struct termios *tp, struct chardat
526 tp->c_cc[VQUIT] = DEF_QUIT; /* default quit */ 525 tp->c_cc[VQUIT] = DEF_QUIT; /* default quit */
527 tp->c_cc[VEOF] = DEF_EOF; /* default EOF character */ 526 tp->c_cc[VEOF] = DEF_EOF; /* default EOF character */
528 tp->c_cc[VEOL] = DEF_EOL; 527 tp->c_cc[VEOL] = DEF_EOL;
528#ifdef VSWTC
529 tp->c_cc[VSWTC] = DEF_SWITCH; /* default switch character */ 529 tp->c_cc[VSWTC] = DEF_SWITCH; /* default switch character */
530#endif
530 531
531 /* Account for special characters seen in input. */ 532 /* Account for special characters seen in input. */
532 if (cp->eol == CR) { 533 if (cp->eol == CR) {
@@ -572,8 +573,8 @@ static void termios_final(struct options *op, struct termios *tp, struct chardat
572#endif 573#endif
573 574
574 /* Finally, make the new settings effective */ 575 /* Finally, make the new settings effective */
575 /* It's tcsetattr_stdin_TCSANOW() + error check */ 576 if (tcsetattr_stdin_TCSANOW(tp) < 0)
576 ioctl_or_perror_and_die(0, TCSETS, tp, "%s: TCSETS", op->tty); 577 bb_perror_msg_and_die("%s: tcsetattr", op->tty);
577} 578}
578 579
579int getty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 580int getty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -650,8 +651,8 @@ int getty_main(int argc UNUSED_PARAM, char **argv)
650 * by patching the SunOS kernel variable "zsadtrlow" to a larger value; 651 * by patching the SunOS kernel variable "zsadtrlow" to a larger value;
651 * 5 seconds seems to be a good value. 652 * 5 seconds seems to be a good value.
652 */ 653 */
653 /* tcgetattr() + error check */ 654 if (tcgetattr(0, &termios) < 0)
654 ioctl_or_perror_and_die(0, TCGETS, &termios, "%s: TCGETS", options.tty); 655 bb_perror_msg_and_die("%s: tcgetattr", options.tty);
655 656
656 pid = getpid(); 657 pid = getpid();
657#ifdef __linux__ 658#ifdef __linux__
diff --git a/loginutils/login.c b/loginutils/login.c
index 88ed0af78..10012486f 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -264,7 +264,7 @@ int login_main(int argc UNUSED_PARAM, char **argv)
264 264
265 while (1) { 265 while (1) {
266 /* flush away any type-ahead (as getty does) */ 266 /* flush away any type-ahead (as getty does) */
267 ioctl(0, TCFLSH, TCIFLUSH); 267 tcflush(0, TCIFLUSH);
268 268
269 if (!username[0]) 269 if (!username[0])
270 get_username_or_die(username, sizeof(username)); 270 get_username_or_die(username, sizeof(username));