#include <paths.h>
#include <sys/reboot.h>
#include <sys/resource.h>
+#ifdef __linux__
#include <linux/vt.h>
+#endif
#if ENABLE_FEATURE_UTMP
# include <utmp.h> /* DEAD_PROCESS */
#endif
+/* Used only for sanitizing purposes in set_sane_term() below. On systems where
+ * the baud rate is stored in a separate field, we can safely disable them. */
+#ifndef CBAUD
+# define CBAUD 0
+# define CBAUDEX 0
+#endif
/* Was a CONFIG_xxx option. A lot of people were building
* not fully functional init by switching it on! */
static void console_init(void)
{
+#ifdef VT_OPENQRY
int vtno;
+#endif
char *s;
s = getenv("CONSOLE");
}
s = getenv("TERM");
+#ifdef VT_OPENQRY
if (ioctl(STDIN_FILENO, VT_OPENQRY, &vtno) != 0) {
/* Not a linux terminal, probably serial console.
* Force the TERM setting to vt102
putenv((char*)"TERM=vt102");
if (!ENABLE_FEATURE_INIT_SYSLOG)
log_console = NULL;
- } else if (!s)
+ } else
+#endif
+ if (!s)
putenv((char*)"TERM=linux");
}
tty.c_cc[VSTOP] = 19; /* C-s */
tty.c_cc[VSUSP] = 26; /* C-z */
+#ifdef __linux__
/* use line discipline 0 */
tty.c_line = 0;
+#endif
/* Make it be sane */
tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD;
* reads will be done in raw mode anyway. Errors will be dealt with
* later on.
*/
-#ifdef __linux__
/* flush input and output queues, important for modems! */
- ioctl(0, TCFLSH, TCIOFLUSH); /* tcflush(0, TCIOFLUSH)? - same */
-#endif
+ tcflush(0, TCIOFLUSH);
ispeed = ospeed = speed;
if (speed == B0) {
/* Speed was specified as "0" on command line.
cfsetispeed(tp, ispeed);
cfsetospeed(tp, ospeed);
- tp->c_iflag = tp->c_lflag = tp->c_line = 0;
+ tp->c_iflag = tp->c_lflag = 0;
tp->c_oflag = OPOST | ONLCR;
tp->c_cc[VMIN] = 1;
tp->c_cc[VTIME] = 0;
+#ifdef __linux__
+ tp->c_line = 0;
+#endif
/* Optionally enable hardware flow control */
#ifdef CRTSCTS
for (bp = buf; bp < buf + nread; bp++) {
if (isdigit(*bp)) {
speed = bcode(bp);
- if (speed > 0) {
- tp->c_cflag &= ~CBAUD;
- tp->c_cflag |= speed;
- }
+ if (speed > 0)
+ cfsetspeed(tp, speed);
break;
}
}
/* Flush pending input (esp. after parsing or switching the baud rate). */
sleep(1);
- ioctl(0, TCFLSH, TCIFLUSH); /* tcflush(0, TCIOFLUSH)? - same */
+ tcflush(0, TCIOFLUSH);
/* Prompt for and read a login name. */
logname[0] = '\0';
tp->c_cc[VQUIT] = DEF_QUIT; /* default quit */
tp->c_cc[VEOF] = DEF_EOF; /* default EOF character */
tp->c_cc[VEOL] = DEF_EOL;
+#ifdef VSWTC
tp->c_cc[VSWTC] = DEF_SWITCH; /* default switch character */
+#endif
/* Account for special characters seen in input. */
if (cp->eol == CR) {
#endif
/* Finally, make the new settings effective */
- /* It's tcsetattr_stdin_TCSANOW() + error check */
- ioctl_or_perror_and_die(0, TCSETS, tp, "%s: TCSETS", op->tty);
+ if (tcsetattr_stdin_TCSANOW(tp) < 0)
+ bb_perror_msg_and_die("%s: tcsetattr", op->tty);
}
int getty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
* by patching the SunOS kernel variable "zsadtrlow" to a larger value;
* 5 seconds seems to be a good value.
*/
- /* tcgetattr() + error check */
- ioctl_or_perror_and_die(0, TCGETS, &termios, "%s: TCGETS", options.tty);
+ if (tcgetattr(0, &termios) < 0)
+ bb_perror_msg_and_die("%s: tcgetattr", options.tty);
pid = getpid();
#ifdef __linux__