1303 files changed, 32187 insertions, 57138 deletions
diff --git a/loginutils/getty.c b/loginutils/getty.c index 6fd4ff2..e5a2533 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c @@ -21,6 +21,28 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config GETTY +//config: bool "getty" +//config: default y +//config: select FEATURE_SYSLOG +//config: help +//config: getty lets you log in on a tty. It is normally invoked by init. +//config: +//config: Note that you can save a few bytes by disabling it and +//config: using login applet directly. +//config: If you need to reset tty attributes before calling login, +//config: this script approximates getty: +//config: +//config: exec </dev/$1 >/dev/$1 2>&1 || exit 1 +//config: reset +//config: stty sane; stty ispeed 38400; stty ospeed 38400 +//config: printf "%s login: " "`hostname`" +//config: read -r login +//config: exec /bin/login "$login" + +//applet:IF_GETTY(APPLET(getty, BB_DIR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_GETTY) += getty.o #include "libbb.h" #include <syslog.h> @@ -114,7 +136,7 @@ struct globals { //usage: "\n" //usage: "\nBAUD_RATE of 0 leaves it unchanged" -static const char opt_string[] ALIGN1 = "I:LH:f:hil:mt:wn"; +static const char opt_string[] ALIGN1 = "I:LH:f:hil:mt:+wn"; #define F_INITSTRING (1 << 0) /* -I */ #define F_LOCAL (1 << 1) /* -L */ #define F_FAKEHOST (1 << 2) /* -H */ @@ -162,7 +184,7 @@ static void parse_args(char **argv) char *ts; int flags; - opt_complementary = "-2:t+"; /* at least 2 args; -t N */ + opt_complementary = "-2"; /* at least 2 args; -t N */ flags = getopt32(argv, opt_string, &G.initstring, &G.fakehost, &G.issue, &G.login, &G.timeout @@ -339,18 +361,19 @@ static void finalize_tty_attrs(void) * observed to improve backspacing through Unicode chars */ - /* line buffered input (NL or EOL or EOF chars end a line); - * recognize INT/QUIT/SUSP chars; - * echo input chars; - * echo BS-SP-BS on erase character; - * echo kill char specially, not as ^c (ECHOKE controls how exactly); - * erase all input via BS-SP-BS on kill char (else go to next line) + /* ICANON line buffered input (NL or EOL or EOF chars end a line); + * ISIG recognize INT/QUIT/SUSP chars; + * ECHO echo input chars; + * ECHOE echo BS-SP-BS on erase character; + * ECHOK echo kill char specially, not as ^c (ECHOKE controls how exactly); + * ECHOKE erase all input via BS-SP-BS on kill char (else go to next line) + * ECHOCTL Echo ctrl chars as ^c (else echo verbatim: + * e.g. up arrow emits "ESC-something" and thus moves cursor up!) */ - G.tty_attrs.c_lflag |= ICANON | ISIG | ECHO | ECHOE | ECHOK | ECHOKE; + G.tty_attrs.c_lflag |= ICANON | ISIG | ECHO | ECHOE | ECHOK | ECHOKE | ECHOCTL; /* Other bits in c_lflag: * XCASE Map uppercase to \lowercase [tried, doesn't work] * ECHONL Echo NL even if ECHO is not set - * ECHOCTL Echo ctrl chars as ^c (else don't echo) - maybe set this? * ECHOPRT On erase, echo erased chars * [qwe<BS><BS><BS> input looks like "qwe\ewq/" on screen] * NOFLSH Don't flush input buffer after interrupt or quit chars @@ -524,6 +547,11 @@ static void alarm_handler(int sig UNUSED_PARAM) _exit(EXIT_SUCCESS); } +static void sleep10(void) +{ + sleep(10); +} + int getty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int getty_main(int argc UNUSED_PARAM, char **argv) { @@ -561,6 +589,16 @@ int getty_main(int argc UNUSED_PARAM, char **argv) // pid, getppid(), // getsid(0), getpgid(0)); bb_perror_msg_and_die("setsid"); + /* + * When we can end up here? + * Example: setsid() fails when run alone in interactive shell: + * # getty 115200 /dev/tty2 + * because shell's child (getty) is put in a new process group. + * But doesn't fail if shell is not interactive + * (and therefore doesn't create process groups for pipes), + * or if getty is not the first process in the process group: + * # true | getty 115200 /dev/tty2 + */ } /* Looks like we are already a session leader. * In this case (setsid failed) we may still have ctty, @@ -593,7 +631,7 @@ int getty_main(int argc UNUSED_PARAM, char **argv) close(n--); /* Logging. We want special flavor of error_msg_and_die */ - die_sleep = 10; + die_func = sleep10; msg_eol = "\r\n"; /* most likely will internally use fd #3 in CLOEXEC mode: */ openlog(applet_name, LOG_PID, LOG_AUTH); |