getty: fix -i (was ignored)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
e9d12b57bf
commit
bcdb9b8762
@ -1394,23 +1394,6 @@ INSERT
|
|||||||
#define getsebool_full_usage "\n\n" \
|
#define getsebool_full_usage "\n\n" \
|
||||||
" -a Show all selinux booleans"
|
" -a Show all selinux booleans"
|
||||||
|
|
||||||
#define getty_trivial_usage \
|
|
||||||
"[OPTIONS] BAUD_RATE TTY [TERMTYPE]"
|
|
||||||
#define getty_full_usage "\n\n" \
|
|
||||||
"Open a tty, prompt for a login name, then invoke /bin/login\n" \
|
|
||||||
"\nOptions:" \
|
|
||||||
"\n -h Enable hardware (RTS/CTS) flow control" \
|
|
||||||
"\n -i Don't display /etc/issue before running login" \
|
|
||||||
"\n -L Local line, don't do carrier detect" \
|
|
||||||
"\n -m Get baud rate from modem's CONNECT status message" \
|
|
||||||
"\n -w Wait for a CR or LF before sending /etc/issue" \
|
|
||||||
"\n -n Don't prompt the user for a login name" \
|
|
||||||
"\n -f ISSUE_FILE Display ISSUE_FILE instead of /etc/issue" \
|
|
||||||
"\n -l LOGIN Invoke LOGIN instead of /bin/login" \
|
|
||||||
"\n -t SEC Terminate after SEC if no username is read" \
|
|
||||||
"\n -I INITSTR Send INITSTR before anything else" \
|
|
||||||
"\n -H HOST Log HOST into the utmp file as the hostname" \
|
|
||||||
|
|
||||||
#define gunzip_trivial_usage \
|
#define gunzip_trivial_usage \
|
||||||
"[-cft] [FILE]..."
|
"[-cft] [FILE]..."
|
||||||
#define gunzip_full_usage "\n\n" \
|
#define gunzip_full_usage "\n\n" \
|
||||||
|
@ -31,14 +31,25 @@
|
|||||||
* System V, assume it is SunOS 4.
|
* System V, assume it is SunOS 4.
|
||||||
*/
|
*/
|
||||||
#ifdef LOGIN_PROCESS /* defined in System V utmp.h */
|
#ifdef LOGIN_PROCESS /* defined in System V utmp.h */
|
||||||
#include <sys/utsname.h>
|
# include <sys/utsname.h>
|
||||||
#else /* if !sysV style, wtmp/utmp code is off */
|
#else /* if !sysV style, wtmp/utmp code is off */
|
||||||
#undef ENABLE_FEATURE_UTMP
|
# undef ENABLE_FEATURE_UTMP
|
||||||
#undef ENABLE_FEATURE_WTMP
|
# undef ENABLE_FEATURE_WTMP
|
||||||
#define ENABLE_FEATURE_UTMP 0
|
# define ENABLE_FEATURE_UTMP 0
|
||||||
#define ENABLE_FEATURE_WTMP 0
|
# define ENABLE_FEATURE_WTMP 0
|
||||||
#endif /* LOGIN_PROCESS */
|
#endif /* LOGIN_PROCESS */
|
||||||
|
|
||||||
|
|
||||||
|
/* The following is used for understandable diagnostics. */
|
||||||
|
#ifdef DEBUGGING
|
||||||
|
static FILE *dbf;
|
||||||
|
# define DEBUGTERM "/dev/ttyp0"
|
||||||
|
# define debug(...) do { fprintf(dbf, __VA_ARGS__); fflush(dbf); } while (0)
|
||||||
|
#else
|
||||||
|
# define debug(...) ((void)0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Things you may want to modify.
|
* Things you may want to modify.
|
||||||
*
|
*
|
||||||
@ -51,13 +62,15 @@
|
|||||||
#undef HANDLE_ALLCAPS
|
#undef HANDLE_ALLCAPS
|
||||||
#undef ANCIENT_BS_KILL_CHARS
|
#undef ANCIENT_BS_KILL_CHARS
|
||||||
|
|
||||||
|
#undef _PATH_LOGIN
|
||||||
#define _PATH_LOGIN "/bin/login"
|
#define _PATH_LOGIN "/bin/login"
|
||||||
|
|
||||||
/* If ISSUE is not defined, getty will never display the contents of the
|
/* Displayed before the login prompt.
|
||||||
|
* If ISSUE is not defined, getty will never display the contents of the
|
||||||
* /etc/issue file. You will not want to spit out large "issue" files at the
|
* /etc/issue file. You will not want to spit out large "issue" files at the
|
||||||
* wrong baud rate.
|
* wrong baud rate.
|
||||||
*/
|
*/
|
||||||
#define ISSUE "/etc/issue" /* displayed before the login prompt */
|
#define ISSUE "/etc/issue"
|
||||||
|
|
||||||
/* Some shorthands for control characters. */
|
/* Some shorthands for control characters. */
|
||||||
#define CTL(x) ((x) ^ 0100) /* Assumes ASCII dialect */
|
#define CTL(x) ((x) ^ 0100) /* Assumes ASCII dialect */
|
||||||
@ -83,7 +96,6 @@
|
|||||||
|
|
||||||
/* Storage for command-line options. */
|
/* Storage for command-line options. */
|
||||||
struct options {
|
struct options {
|
||||||
int flags; /* toggle switches, see below */
|
|
||||||
unsigned timeout; /* time-out period */
|
unsigned timeout; /* time-out period */
|
||||||
const char *login; /* login program */
|
const char *login; /* login program */
|
||||||
const char *tty; /* name of tty */
|
const char *tty; /* name of tty */
|
||||||
@ -111,7 +123,6 @@ struct chardata {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Initial values for the above. */
|
/* Initial values for the above. */
|
||||||
static const struct chardata init_chardata = {
|
static const struct chardata init_chardata = {
|
||||||
DEF_ERASE, /* default erase character */
|
DEF_ERASE, /* default erase character */
|
||||||
@ -123,30 +134,37 @@ static const struct chardata init_chardata = {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char opt_string[] ALIGN1 = "I:LH:f:hil:mt:wn";
|
|
||||||
#define F_INITSTRING (1 << 0) /* -I initstring is set */
|
|
||||||
#define F_LOCAL (1 << 1) /* -L force local */
|
|
||||||
#define F_FAKEHOST (1 << 2) /* -H fake hostname */
|
|
||||||
#define F_CUSTISSUE (1 << 3) /* -f give alternative issue file */
|
|
||||||
#define F_RTSCTS (1 << 4) /* -h enable RTS/CTS flow control */
|
|
||||||
#define F_ISSUE (1 << 5) /* -i display /etc/issue */
|
|
||||||
#define F_LOGIN (1 << 6) /* -l non-default login program */
|
|
||||||
#define F_PARSE (1 << 7) /* -m process modem status messages */
|
|
||||||
#define F_TIMEOUT (1 << 8) /* -t time out */
|
|
||||||
#define F_WAITCRLF (1 << 9) /* -w wait for CR or LF */
|
|
||||||
#define F_NOPROMPT (1 << 10) /* -n don't ask for login name */
|
|
||||||
|
|
||||||
|
|
||||||
#define line_buf bb_common_bufsiz1
|
#define line_buf bb_common_bufsiz1
|
||||||
|
|
||||||
/* The following is used for understandable diagnostics. */
|
//usage:#define getty_trivial_usage
|
||||||
#ifdef DEBUGGING
|
//usage: "[OPTIONS] BAUD_RATE TTY [TERMTYPE]"
|
||||||
static FILE *dbf;
|
//usage:#define getty_full_usage "\n\n"
|
||||||
#define DEBUGTERM "/dev/ttyp0"
|
//usage: "Open a tty, prompt for a login name, then invoke /bin/login\n"
|
||||||
#define debug(...) do { fprintf(dbf, __VA_ARGS__); fflush(dbf); } while (0)
|
//usage: "\nOptions:"
|
||||||
#else
|
//usage: "\n -h Enable hardware (RTS/CTS) flow control"
|
||||||
#define debug(...) ((void)0)
|
//usage: "\n -i Don't display /etc/issue"
|
||||||
#endif
|
//usage: "\n -L Local line, don't do carrier detect"
|
||||||
|
//usage: "\n -m Get baud rate from modem's CONNECT status message"
|
||||||
|
//usage: "\n -w Wait for a CR or LF before sending /etc/issue"
|
||||||
|
//usage: "\n -n Don't prompt the user for a login name"
|
||||||
|
//usage: "\n -f ISSUE_FILE Display ISSUE_FILE instead of /etc/issue"
|
||||||
|
//usage: "\n -l LOGIN Invoke LOGIN instead of /bin/login"
|
||||||
|
//usage: "\n -t SEC Terminate after SEC if no username is read"
|
||||||
|
//usage: "\n -I INITSTR Send INITSTR before anything else"
|
||||||
|
//usage: "\n -H HOST Log HOST into the utmp file as the hostname"
|
||||||
|
|
||||||
|
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 */
|
||||||
|
#define F_CUSTISSUE (1 << 3) /* -f */
|
||||||
|
#define F_RTSCTS (1 << 4) /* -h */
|
||||||
|
#define F_NOISSUE (1 << 5) /* -i */
|
||||||
|
#define F_LOGIN (1 << 6) /* -l */
|
||||||
|
#define F_PARSE (1 << 7) /* -m */
|
||||||
|
#define F_TIMEOUT (1 << 8) /* -t */
|
||||||
|
#define F_WAITCRLF (1 << 9) /* -w */
|
||||||
|
#define F_NOPROMPT (1 << 10) /* -n */
|
||||||
|
|
||||||
|
|
||||||
/* bcode - convert speed string to speed code; return <= 0 on failure */
|
/* bcode - convert speed string to speed code; return <= 0 on failure */
|
||||||
@ -181,18 +199,18 @@ static void parse_speeds(struct options *op, char *arg)
|
|||||||
static void parse_args(char **argv, struct options *op, char **fakehost_p)
|
static void parse_args(char **argv, struct options *op, char **fakehost_p)
|
||||||
{
|
{
|
||||||
char *ts;
|
char *ts;
|
||||||
|
int flags;
|
||||||
|
|
||||||
opt_complementary = "-2:t+"; /* at least 2 args; -t N */
|
opt_complementary = "-2:t+"; /* at least 2 args; -t N */
|
||||||
op->flags = getopt32(argv, opt_string,
|
flags = getopt32(argv, opt_string,
|
||||||
&(op->initstring), fakehost_p, &(op->issue),
|
&(op->initstring), fakehost_p, &(op->issue),
|
||||||
&(op->login), &op->timeout);
|
&(op->login), &op->timeout);
|
||||||
argv += optind;
|
if (flags & F_INITSTRING) {
|
||||||
if (op->flags & F_INITSTRING) {
|
|
||||||
op->initstring = xstrdup(op->initstring);
|
op->initstring = xstrdup(op->initstring);
|
||||||
/* decode \ddd octal codes into chars */
|
/* decode \ddd octal codes into chars */
|
||||||
strcpy_and_process_escape_sequences((char*)op->initstring, op->initstring);
|
strcpy_and_process_escape_sequences((char*)op->initstring, op->initstring);
|
||||||
}
|
}
|
||||||
op->flags ^= F_ISSUE; /* invert flag "show /etc/issue" */
|
argv += optind;
|
||||||
debug("after getopt\n");
|
debug("after getopt\n");
|
||||||
|
|
||||||
/* we loosen up a bit and accept both "baudrate tty" and "tty baudrate" */
|
/* we loosen up a bit and accept both "baudrate tty" and "tty baudrate" */
|
||||||
@ -217,17 +235,6 @@ static void open_tty(const char *tty)
|
|||||||
{
|
{
|
||||||
/* Set up new standard input, unless we are given an already opened port. */
|
/* Set up new standard input, unless we are given an already opened port. */
|
||||||
if (NOT_LONE_DASH(tty)) {
|
if (NOT_LONE_DASH(tty)) {
|
||||||
// struct stat st;
|
|
||||||
// int cur_dir_fd;
|
|
||||||
// int fd;
|
|
||||||
|
|
||||||
/* Sanity checks... */
|
|
||||||
// cur_dir_fd = xopen(".", O_DIRECTORY | O_NONBLOCK);
|
|
||||||
// xchdir("/dev");
|
|
||||||
// xstat(tty, &st);
|
|
||||||
// if (!S_ISCHR(st.st_mode))
|
|
||||||
// bb_error_msg_and_die("not a character device");
|
|
||||||
|
|
||||||
if (tty[0] != '/')
|
if (tty[0] != '/')
|
||||||
tty = xasprintf("/dev/%s", tty); /* will leak it */
|
tty = xasprintf("/dev/%s", tty); /* will leak it */
|
||||||
|
|
||||||
@ -236,15 +243,6 @@ static void open_tty(const char *tty)
|
|||||||
close(0);
|
close(0);
|
||||||
/*fd =*/ xopen(tty, O_RDWR | O_NONBLOCK); /* uses fd 0 */
|
/*fd =*/ xopen(tty, O_RDWR | O_NONBLOCK); /* uses fd 0 */
|
||||||
|
|
||||||
// /* Restore current directory */
|
|
||||||
// fchdir(cur_dir_fd);
|
|
||||||
|
|
||||||
/* Open the tty as standard input, continued */
|
|
||||||
// xmove_fd(fd, 0);
|
|
||||||
// /* fd is >= cur_dir_fd, and cur_dir_fd gets closed too here: */
|
|
||||||
// while (fd > 2)
|
|
||||||
// close(fd--);
|
|
||||||
|
|
||||||
/* Set proper protections and ownership. */
|
/* Set proper protections and ownership. */
|
||||||
fchown(0, 0, 0); /* 0:0 */
|
fchown(0, 0, 0); /* 0:0 */
|
||||||
fchmod(0, 0620); /* crw--w---- */
|
fchmod(0, 0620); /* crw--w---- */
|
||||||
@ -259,7 +257,7 @@ static void open_tty(const char *tty)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* termios_init - initialize termios settings */
|
/* termios_init - initialize termios settings */
|
||||||
static void termios_init(struct termios *tp, int speed, struct options *op)
|
static void termios_init(struct termios *tp, int speed)
|
||||||
{
|
{
|
||||||
speed_t ispeed, ospeed;
|
speed_t ispeed, ospeed;
|
||||||
/*
|
/*
|
||||||
@ -278,7 +276,7 @@ static void termios_init(struct termios *tp, int speed, struct options *op)
|
|||||||
ospeed = cfgetospeed(tp);
|
ospeed = cfgetospeed(tp);
|
||||||
}
|
}
|
||||||
tp->c_cflag = CS8 | HUPCL | CREAD;
|
tp->c_cflag = CS8 | HUPCL | CREAD;
|
||||||
if (op->flags & F_LOCAL)
|
if (option_mask32 & F_LOCAL)
|
||||||
tp->c_cflag |= CLOCAL;
|
tp->c_cflag |= CLOCAL;
|
||||||
cfsetispeed(tp, ispeed);
|
cfsetispeed(tp, ispeed);
|
||||||
cfsetospeed(tp, ospeed);
|
cfsetospeed(tp, ospeed);
|
||||||
@ -293,7 +291,7 @@ static void termios_init(struct termios *tp, int speed, struct options *op)
|
|||||||
|
|
||||||
/* Optionally enable hardware flow control */
|
/* Optionally enable hardware flow control */
|
||||||
#ifdef CRTSCTS
|
#ifdef CRTSCTS
|
||||||
if (op->flags & F_RTSCTS)
|
if (option_mask32 & F_RTSCTS)
|
||||||
tp->c_cflag |= CRTSCTS;
|
tp->c_cflag |= CRTSCTS;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -364,7 +362,8 @@ static void auto_baud(char *buf, unsigned size_buf, struct termios *tp)
|
|||||||
static void do_prompt(struct options *op)
|
static void do_prompt(struct options *op)
|
||||||
{
|
{
|
||||||
#ifdef ISSUE
|
#ifdef ISSUE
|
||||||
print_login_issue(op->issue, op->tty);
|
if (!(option_mask32 & F_NOISSUE))
|
||||||
|
print_login_issue(op->issue, op->tty);
|
||||||
#endif
|
#endif
|
||||||
print_login_prompt();
|
print_login_prompt();
|
||||||
}
|
}
|
||||||
@ -429,7 +428,7 @@ static char *get_logname(char *logname, unsigned size_logname,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Do parity bit handling. */
|
/* Do parity bit handling. */
|
||||||
if (!(op->flags & F_LOCAL) && (c & 0x80)) { /* "parity" bit on? */
|
if (!(option_mask32 & F_LOCAL) && (c & 0x80)) { /* "parity" bit on? */
|
||||||
bits = 1;
|
bits = 1;
|
||||||
mask = 1;
|
mask = 1;
|
||||||
while (mask & 0x7f) {
|
while (mask & 0x7f) {
|
||||||
@ -499,7 +498,7 @@ static char *get_logname(char *logname, unsigned size_logname,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* termios_final - set the final tty mode bits */
|
/* termios_final - set the final tty mode bits */
|
||||||
static void termios_final(struct options *op, struct termios *tp, struct chardata *cp)
|
static void termios_final(struct termios *tp, struct chardata *cp)
|
||||||
{
|
{
|
||||||
/* General terminal-independent stuff. */
|
/* General terminal-independent stuff. */
|
||||||
tp->c_iflag |= IXON | IXOFF; /* 2-way flow control */
|
tp->c_iflag |= IXON | IXOFF; /* 2-way flow control */
|
||||||
@ -554,7 +553,7 @@ static void termios_final(struct options *op, struct termios *tp, struct chardat
|
|||||||
#endif
|
#endif
|
||||||
/* Optionally enable hardware flow control */
|
/* Optionally enable hardware flow control */
|
||||||
#ifdef CRTSCTS
|
#ifdef CRTSCTS
|
||||||
if (op->flags & F_RTSCTS)
|
if (option_mask32 & F_RTSCTS)
|
||||||
tp->c_cflag |= CRTSCTS;
|
tp->c_cflag |= CRTSCTS;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -655,24 +654,24 @@ int getty_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
/* Initialize the termios settings (raw mode, eight-bit, blocking i/o). */
|
/* Initialize the termios settings (raw mode, eight-bit, blocking i/o). */
|
||||||
debug("calling termios_init\n");
|
debug("calling termios_init\n");
|
||||||
termios_init(&termios, options.speeds[0], &options);
|
termios_init(&termios, options.speeds[0]);
|
||||||
|
|
||||||
/* Write the modem init string and DON'T flush the buffers */
|
/* Write the modem init string and DON'T flush the buffers */
|
||||||
if (options.flags & F_INITSTRING) {
|
if (option_mask32 & F_INITSTRING) {
|
||||||
debug("writing init string\n");
|
debug("writing init string\n");
|
||||||
full_write1_str(options.initstring);
|
full_write1_str(options.initstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Optionally detect the baud rate from the modem status message */
|
/* Optionally detect the baud rate from the modem status message */
|
||||||
debug("before autobaud\n");
|
debug("before autobaud\n");
|
||||||
if (options.flags & F_PARSE)
|
if (option_mask32 & F_PARSE)
|
||||||
auto_baud(line_buf, sizeof(line_buf), &termios);
|
auto_baud(line_buf, sizeof(line_buf), &termios);
|
||||||
|
|
||||||
/* Set the optional timer */
|
/* Set the optional timer */
|
||||||
alarm(options.timeout); /* if 0, alarm is not set */
|
alarm(options.timeout); /* if 0, alarm is not set */
|
||||||
|
|
||||||
/* Optionally wait for CR or LF before writing /etc/issue */
|
/* Optionally wait for CR or LF before writing /etc/issue */
|
||||||
if (options.flags & F_WAITCRLF) {
|
if (option_mask32 & F_WAITCRLF) {
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
debug("waiting for cr-lf\n");
|
debug("waiting for cr-lf\n");
|
||||||
@ -685,7 +684,7 @@ int getty_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
logname = NULL;
|
logname = NULL;
|
||||||
if (!(options.flags & F_NOPROMPT)) {
|
if (!(option_mask32 & F_NOPROMPT)) {
|
||||||
/* NB:termios_init already set line speed
|
/* NB:termios_init already set line speed
|
||||||
* to options.speeds[0] */
|
* to options.speeds[0] */
|
||||||
int baud_index = 0;
|
int baud_index = 0;
|
||||||
@ -709,7 +708,7 @@ int getty_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
alarm(0);
|
alarm(0);
|
||||||
|
|
||||||
/* Finalize the termios settings. */
|
/* Finalize the termios settings. */
|
||||||
termios_final(&options, &termios, &chardata);
|
termios_final(&termios, &chardata);
|
||||||
|
|
||||||
/* Now the newline character should be properly written. */
|
/* Now the newline character should be properly written. */
|
||||||
full_write(STDOUT_FILENO, "\n", 1);
|
full_write(STDOUT_FILENO, "\n", 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user