*: code shrink by adding a wrapper around very common tcsetattr(0, TCSANOW, xx) op
function old new delta tcsetattr_stdin_TCSANOW - 14 +14 set_sane_term 116 113 -3 top_main 1277 1273 -4 make_new_session 421 415 -6 rawmode 133 126 -7 reset_term 18 10 -8 die 43 35 -8 cookmode 62 54 -8 vlock_main 425 415 -10 read_line_input 3165 3155 -10 bb_askpass 357 347 -10 fsck_minix_main 3079 3065 -14 getty_main 2375 2332 -43 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/12 up/down: 14/-131) Total: -117 bytes
This commit is contained in:
parent
905ed8730f
commit
202ac504e1
@ -12281,7 +12281,7 @@ static int ask_yn(const char * string, int def)
|
|||||||
tmp.c_lflag &= ~(ICANON | ECHO);
|
tmp.c_lflag &= ~(ICANON | ECHO);
|
||||||
tmp.c_cc[VMIN] = 1;
|
tmp.c_cc[VMIN] = 1;
|
||||||
tmp.c_cc[VTIME] = 0;
|
tmp.c_cc[VTIME] = 0;
|
||||||
tcsetattr (0, TCSANOW, &tmp);
|
tcsetattr_stdin_TCSANOW(&tmp);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (def == 1)
|
if (def == 1)
|
||||||
@ -12297,7 +12297,7 @@ static int ask_yn(const char * string, int def)
|
|||||||
break;
|
break;
|
||||||
if (c == 3) {
|
if (c == 3) {
|
||||||
#ifdef HAVE_TERMIOS_H
|
#ifdef HAVE_TERMIOS_H
|
||||||
tcsetattr (0, TCSANOW, &termios);
|
tcsetattr_stdin_TCSANOW(&termios);
|
||||||
#endif
|
#endif
|
||||||
if (e2fsck_global_ctx &&
|
if (e2fsck_global_ctx &&
|
||||||
e2fsck_global_ctx->flags & E2F_FLAG_SETJMP_OK) {
|
e2fsck_global_ctx->flags & E2F_FLAG_SETJMP_OK) {
|
||||||
@ -12323,7 +12323,7 @@ static int ask_yn(const char * string, int def)
|
|||||||
else
|
else
|
||||||
puts ("no\n");
|
puts ("no\n");
|
||||||
#ifdef HAVE_TERMIOS_H
|
#ifdef HAVE_TERMIOS_H
|
||||||
tcsetattr (0, TCSANOW, &termios);
|
tcsetattr_stdin_TCSANOW(&termios);
|
||||||
#endif
|
#endif
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
@ -2106,13 +2106,13 @@ static void rawmode(void)
|
|||||||
term_vi.c_cc[VMIN] = 1;
|
term_vi.c_cc[VMIN] = 1;
|
||||||
term_vi.c_cc[VTIME] = 0;
|
term_vi.c_cc[VTIME] = 0;
|
||||||
erase_char = term_vi.c_cc[VERASE];
|
erase_char = term_vi.c_cc[VERASE];
|
||||||
tcsetattr(0, TCSANOW, &term_vi);
|
tcsetattr_stdin_TCSANOW(&term_vi);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cookmode(void)
|
static void cookmode(void)
|
||||||
{
|
{
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
tcsetattr(0, TCSANOW, &term_orig);
|
tcsetattr_stdin_TCSANOW(&term_orig);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----- Come here when we get a window resize signal ---------
|
//----- Come here when we get a window resize signal ---------
|
||||||
|
@ -1142,6 +1142,8 @@ extern void print_login_prompt(void) FAST_FUNC;
|
|||||||
/* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */
|
/* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */
|
||||||
int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FUNC;
|
int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FUNC;
|
||||||
|
|
||||||
|
int tcsetattr_stdin_TCSANOW(const struct termios *tp) FAST_FUNC;
|
||||||
|
|
||||||
/* NB: "unsigned request" is crucial! "int request" will break some arches! */
|
/* NB: "unsigned request" is crucial! "int request" will break some arches! */
|
||||||
int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC;
|
int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC;
|
||||||
int ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC;
|
int ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC;
|
||||||
|
@ -261,7 +261,7 @@ static void set_sane_term(void)
|
|||||||
tty.c_lflag =
|
tty.c_lflag =
|
||||||
ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN;
|
ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN;
|
||||||
|
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &tty);
|
tcsetattr_stdin_TCSANOW(&tty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open the new terminal device.
|
/* Open the new terminal device.
|
||||||
|
@ -37,7 +37,7 @@ char* FAST_FUNC bb_askpass(int timeout, const char *prompt)
|
|||||||
tio = oldtio;
|
tio = oldtio;
|
||||||
tio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
|
tio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
|
||||||
tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
|
tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &tio);
|
tcsetattr_stdin_TCSANOW(&tio);
|
||||||
|
|
||||||
memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
/* sa.sa_flags = 0; - no SA_RESTART! */
|
/* sa.sa_flags = 0; - no SA_RESTART! */
|
||||||
@ -70,7 +70,7 @@ char* FAST_FUNC bb_askpass(int timeout, const char *prompt)
|
|||||||
}
|
}
|
||||||
sigaction_set(SIGINT, &oldsa);
|
sigaction_set(SIGINT, &oldsa);
|
||||||
|
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldtio);
|
tcsetattr_stdin_TCSANOW(&oldtio);
|
||||||
bb_putchar('\n');
|
bb_putchar('\n');
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
/* From <linux/kd.h> */
|
/* From <linux/kd.h> */
|
||||||
enum { KDGKBTYPE = 0x4B33 }; /* get keyboard type */
|
enum { KDGKBTYPE = 0x4B33 }; /* get keyboard type */
|
||||||
|
|
||||||
|
|
||||||
static int open_a_console(const char *fnam)
|
static int open_a_console(const char *fnam)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
@ -37,7 +36,6 @@ static int open_a_console(const char *fnam)
|
|||||||
* We try several things because opening /dev/console will fail
|
* We try several things because opening /dev/console will fail
|
||||||
* if someone else used X (which does a chown on /dev/console).
|
* if someone else used X (which does a chown on /dev/console).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int FAST_FUNC get_console_fd_or_die(void)
|
int FAST_FUNC get_console_fd_or_die(void)
|
||||||
{
|
{
|
||||||
static const char *const console_names[] = {
|
static const char *const console_names[] = {
|
||||||
|
@ -1436,7 +1436,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
|
|||||||
#define _POSIX_VDISABLE '\0'
|
#define _POSIX_VDISABLE '\0'
|
||||||
#endif
|
#endif
|
||||||
new_settings.c_cc[VINTR] = _POSIX_VDISABLE;
|
new_settings.c_cc[VINTR] = _POSIX_VDISABLE;
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &new_settings);
|
tcsetattr_stdin_TCSANOW(&new_settings);
|
||||||
|
|
||||||
/* Now initialize things */
|
/* Now initialize things */
|
||||||
previous_SIGWINCH_handler = signal(SIGWINCH, win_changed);
|
previous_SIGWINCH_handler = signal(SIGWINCH, win_changed);
|
||||||
@ -1860,7 +1860,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* restore initial_settings */
|
/* restore initial_settings */
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &initial_settings);
|
tcsetattr_stdin_TCSANOW(&initial_settings);
|
||||||
/* restore SIGWINCH handler */
|
/* restore SIGWINCH handler */
|
||||||
signal(SIGWINCH, previous_SIGWINCH_handler);
|
signal(SIGWINCH, previous_SIGWINCH_handler);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
@ -289,3 +289,8 @@ int FAST_FUNC get_terminal_width_height(int fd, unsigned *width, unsigned *heigh
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp)
|
||||||
|
{
|
||||||
|
return tcsetattr(STDIN_FILENO, TCSANOW, tp);
|
||||||
|
}
|
||||||
|
@ -279,7 +279,7 @@ static void termios_init(struct termios *tp, int speed, struct options *op)
|
|||||||
*/
|
*/
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
/* flush input and output queues, important for modems! */
|
/* flush input and output queues, important for modems! */
|
||||||
ioctl(0, TCFLSH, TCIOFLUSH);
|
ioctl(0, TCFLSH, TCIOFLUSH); /* tcflush(0, TCIOFLUSH)? - same */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tp->c_cflag = CS8 | HUPCL | CREAD | speed;
|
tp->c_cflag = CS8 | HUPCL | CREAD | speed;
|
||||||
@ -297,7 +297,7 @@ static void termios_init(struct termios *tp, int speed, struct options *op)
|
|||||||
tp->c_cflag |= CRTSCTS;
|
tp->c_cflag |= CRTSCTS;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ioctl(0, TCSETS, tp);
|
tcsetattr_stdin_TCSANOW(tp);
|
||||||
|
|
||||||
debug("term_io 2\n");
|
debug("term_io 2\n");
|
||||||
}
|
}
|
||||||
@ -334,7 +334,7 @@ static void auto_baud(char *buf, unsigned size_buf, struct termios *tp)
|
|||||||
tp->c_iflag |= ISTRIP; /* enable 8th-bit stripping */
|
tp->c_iflag |= ISTRIP; /* enable 8th-bit stripping */
|
||||||
vmin = tp->c_cc[VMIN];
|
vmin = tp->c_cc[VMIN];
|
||||||
tp->c_cc[VMIN] = 0; /* don't block if queue empty */
|
tp->c_cc[VMIN] = 0; /* don't block if queue empty */
|
||||||
ioctl(0, TCSETS, tp);
|
tcsetattr_stdin_TCSANOW(tp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wait for a while, then read everything the modem has said so far and
|
* Wait for a while, then read everything the modem has said so far and
|
||||||
@ -359,7 +359,7 @@ static void auto_baud(char *buf, unsigned size_buf, struct termios *tp)
|
|||||||
/* Restore terminal settings. Errors will be dealt with later on. */
|
/* Restore terminal settings. Errors will be dealt with later on. */
|
||||||
tp->c_iflag = iflag;
|
tp->c_iflag = iflag;
|
||||||
tp->c_cc[VMIN] = vmin;
|
tp->c_cc[VMIN] = vmin;
|
||||||
ioctl(0, TCSETS, tp);
|
tcsetattr_stdin_TCSANOW(tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* do_prompt - show login prompt, optionally preceded by /etc/issue contents */
|
/* do_prompt - show login prompt, optionally preceded by /etc/issue contents */
|
||||||
@ -404,7 +404,7 @@ static char *get_logname(char *logname, unsigned size_logname,
|
|||||||
|
|
||||||
/* Flush pending input (esp. after parsing or switching the baud rate). */
|
/* Flush pending input (esp. after parsing or switching the baud rate). */
|
||||||
sleep(1);
|
sleep(1);
|
||||||
ioctl(0, TCFLSH, TCIFLUSH);
|
ioctl(0, TCFLSH, TCIFLUSH); /* tcflush(0, TCIOFLUSH)? - same */
|
||||||
|
|
||||||
/* Prompt for and read a login name. */
|
/* Prompt for and read a login name. */
|
||||||
logname[0] = '\0';
|
logname[0] = '\0';
|
||||||
@ -552,12 +552,13 @@ 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 (op->flags & F_RTSCTS)
|
||||||
tp->c_cflag |= CRTSCTS;
|
tp->c_cflag |= CRTSCTS;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Finally, make the new settings effective */
|
/* 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);
|
ioctl_or_perror_and_die(0, TCSETS, tp, "%s: TCSETS", op->tty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -689,6 +690,7 @@ int getty_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
* by patching the SunOS kernel variable "zsadtrlow" to a larger value;
|
* by patching the SunOS kernel variable "zsadtrlow" to a larger value;
|
||||||
* 5 seconds seems to be a good value.
|
* 5 seconds seems to be a good value.
|
||||||
*/
|
*/
|
||||||
|
/* tcgetattr() + error check */
|
||||||
ioctl_or_perror_and_die(0, TCGETS, &termios, "%s: TCGETS", options.tty);
|
ioctl_or_perror_and_die(0, TCGETS, &termios, "%s: TCGETS", options.tty);
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
@ -753,7 +755,7 @@ int getty_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
baud_index = (baud_index + 1) % options.numspeed;
|
baud_index = (baud_index + 1) % options.numspeed;
|
||||||
termios.c_cflag &= ~CBAUD;
|
termios.c_cflag &= ~CBAUD;
|
||||||
termios.c_cflag |= options.speeds[baud_index];
|
termios.c_cflag |= options.speeds[baud_index];
|
||||||
ioctl(0, TCSETS, &termios);
|
tcsetattr_stdin_TCSANOW(&termios);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ int vlock_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
term.c_iflag |= IGNBRK;
|
term.c_iflag |= IGNBRK;
|
||||||
term.c_lflag &= ~ISIG;
|
term.c_lflag &= ~ISIG;
|
||||||
term.c_lflag &= ~(ECHO | ECHOCTL);
|
term.c_lflag &= ~(ECHO | ECHOCTL);
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &term);
|
tcsetattr_stdin_TCSANOW(&term);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
printf("Virtual console%s locked by %s.\n",
|
printf("Virtual console%s locked by %s.\n",
|
||||||
@ -101,6 +101,6 @@ int vlock_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
} while (1);
|
} while (1);
|
||||||
|
|
||||||
ioctl(STDIN_FILENO, VT_SETMODE, &ovtm);
|
ioctl(STDIN_FILENO, VT_SETMODE, &ovtm);
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &oterm);
|
tcsetattr_stdin_TCSANOW(&oterm);
|
||||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ make_new_session(
|
|||||||
termbuf.c_iflag |= ICRNL;
|
termbuf.c_iflag |= ICRNL;
|
||||||
termbuf.c_iflag &= ~IXOFF;
|
termbuf.c_iflag &= ~IXOFF;
|
||||||
/*termbuf.c_lflag &= ~ICANON;*/
|
/*termbuf.c_lflag &= ~ICANON;*/
|
||||||
tcsetattr(0, TCSANOW, &termbuf);
|
tcsetattr_stdin_TCSANOW(&termbuf);
|
||||||
|
|
||||||
/* Uses FILE-based I/O to stdout, but does fflush(stdout),
|
/* Uses FILE-based I/O to stdout, but does fflush(stdout),
|
||||||
* so should be safe with vfork.
|
* so should be safe with vfork.
|
||||||
|
@ -649,7 +649,7 @@ static void clearmems(void)
|
|||||||
|
|
||||||
static void reset_term(void)
|
static void reset_term(void)
|
||||||
{
|
{
|
||||||
tcsetattr(0, TCSANOW, &initial_settings);
|
tcsetattr_stdin_TCSANOW(&initial_settings);
|
||||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||||
clearmems();
|
clearmems();
|
||||||
#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
@ -941,7 +941,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
new_settings.c_lflag &= ~(ISIG | ICANON | ECHO | ECHONL);
|
new_settings.c_lflag &= ~(ISIG | ICANON | ECHO | ECHONL);
|
||||||
|
|
||||||
bb_signals(BB_FATAL_SIGS, sig_catcher);
|
bb_signals(BB_FATAL_SIGS, sig_catcher);
|
||||||
tcsetattr(0, TCSANOW, (void *) &new_settings);
|
tcsetattr_stdin_TCSANOW(&new_settings);
|
||||||
#endif /* FEATURE_USE_TERMIOS */
|
#endif /* FEATURE_USE_TERMIOS */
|
||||||
|
|
||||||
#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
|
@ -293,7 +293,7 @@ static void die(const char *str) NORETURN;
|
|||||||
static void die(const char *str)
|
static void die(const char *str)
|
||||||
{
|
{
|
||||||
if (termios_set)
|
if (termios_set)
|
||||||
tcsetattr(0, TCSANOW, &sv_termios);
|
tcsetattr_stdin_TCSANOW(&sv_termios);
|
||||||
bb_error_msg_and_die("%s", str);
|
bb_error_msg_and_die("%s", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1254,7 +1254,7 @@ int fsck_minix_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
tcgetattr(0, &sv_termios);
|
tcgetattr(0, &sv_termios);
|
||||||
tmp = sv_termios;
|
tmp = sv_termios;
|
||||||
tmp.c_lflag &= ~(ICANON | ECHO);
|
tmp.c_lflag &= ~(ICANON | ECHO);
|
||||||
tcsetattr(0, TCSANOW, &tmp);
|
tcsetattr_stdin_TCSANOW(&tmp);
|
||||||
termios_set = 1;
|
termios_set = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1299,7 +1299,7 @@ int fsck_minix_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
write_superblock();
|
write_superblock();
|
||||||
|
|
||||||
if (OPT_manual)
|
if (OPT_manual)
|
||||||
tcsetattr(0, TCSANOW, &sv_termios);
|
tcsetattr_stdin_TCSANOW(&sv_termios);
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
retcode += 3;
|
retcode += 3;
|
||||||
|
Loading…
Reference in New Issue
Block a user