diff options
author | Ron Yorston <rmy@pobox.com> | 2017-09-27 10:08:12 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2017-09-27 10:11:19 +0100 |
commit | d9383e984da8de72e61e5094a3cf6404c5707ddc (patch) | |
tree | dd42825854fc42aea40d4f7a95548d53721d1733 /libbb | |
parent | 166b3e4e82799f87d3b002c7177891111eff079e (diff) | |
parent | 0c4dbd481aedb5d22c1048e7f7eb547a3b5e50a5 (diff) | |
download | busybox-w32-d9383e984da8de72e61e5094a3cf6404c5707ddc.tar.gz busybox-w32-d9383e984da8de72e61e5094a3cf6404c5707ddc.tar.bz2 busybox-w32-d9383e984da8de72e61e5094a3cf6404c5707ddc.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/getopt32.c | 2 | ||||
-rw-r--r-- | libbb/lineedit.c | 26 | ||||
-rw-r--r-- | libbb/u_signal_names.c | 1 | ||||
-rw-r--r-- | libbb/xfuncs.c | 55 |
4 files changed, 48 insertions, 36 deletions
diff --git a/libbb/getopt32.c b/libbb/getopt32.c index f778c6e89..378510063 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c | |||
@@ -517,7 +517,7 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options, | |||
517 | } | 517 | } |
518 | 518 | ||
519 | /* In case getopt32 was already called: | 519 | /* In case getopt32 was already called: |
520 | * reset the libc getopt() function, which keeps internal state. | 520 | * reset libc getopt() internal state. |
521 | * run_nofork_applet() does this, but we might end up here | 521 | * run_nofork_applet() does this, but we might end up here |
522 | * also via gunzip_main() -> gzip_main(). Play safe. | 522 | * also via gunzip_main() -> gzip_main(). Play safe. |
523 | */ | 523 | */ |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index c2b0a3842..d85057e72 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -2321,7 +2321,7 @@ static int32_t reverse_i_search(int timeout) | |||
2321 | */ | 2321 | */ |
2322 | int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize) | 2322 | int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize) |
2323 | { | 2323 | { |
2324 | int len; | 2324 | int len, n; |
2325 | int timeout; | 2325 | int timeout; |
2326 | #if ENABLE_FEATURE_TAB_COMPLETION | 2326 | #if ENABLE_FEATURE_TAB_COMPLETION |
2327 | smallint lastWasTab = 0; | 2327 | smallint lastWasTab = 0; |
@@ -2336,15 +2336,15 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2336 | 2336 | ||
2337 | INIT_S(); | 2337 | INIT_S(); |
2338 | 2338 | ||
2339 | n = get_termios_and_make_raw(STDIN_FILENO, &new_settings, &initial_settings, 0 | ||
2340 | | TERMIOS_CLEAR_ISIG /* turn off INTR (ctrl-C), QUIT, SUSP */ | ||
2341 | ); | ||
2339 | #if ENABLE_PLATFORM_MINGW32 | 2342 | #if ENABLE_PLATFORM_MINGW32 |
2340 | memset(initial_settings.c_cc, 0, sizeof(initial_settings.c_cc)); | ||
2341 | initial_settings.c_cc[VINTR] = CTRL('C'); | 2343 | initial_settings.c_cc[VINTR] = CTRL('C'); |
2342 | initial_settings.c_cc[VEOF] = CTRL('D'); | 2344 | initial_settings.c_cc[VEOF] = CTRL('D'); |
2343 | if (!isatty(0) || !isatty(1)) { | 2345 | if (n > 0 || !isatty(0) || !isatty(1)) { |
2344 | #else | 2346 | #else |
2345 | if (tcgetattr(STDIN_FILENO, &initial_settings) < 0 | 2347 | if (n != 0 || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON) { |
2346 | || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON | ||
2347 | ) { | ||
2348 | #endif | 2348 | #endif |
2349 | /* Happens when e.g. stty -echo was run before. | 2349 | /* Happens when e.g. stty -echo was run before. |
2350 | * But if ICANON is not set, we don't come here. | 2350 | * But if ICANON is not set, we don't come here. |
@@ -2398,18 +2398,6 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2398 | #endif | 2398 | #endif |
2399 | #define command command_must_not_be_used | 2399 | #define command command_must_not_be_used |
2400 | 2400 | ||
2401 | new_settings = initial_settings; | ||
2402 | /* ~ICANON: unbuffered input (most c_cc[] are disabled, VMIN/VTIME are enabled) */ | ||
2403 | /* ~ECHO, ~ECHONL: turn off echoing, including newline echoing */ | ||
2404 | /* ~ISIG: turn off INTR (ctrl-C), QUIT, SUSP */ | ||
2405 | new_settings.c_lflag &= ~(ICANON | ECHO | ECHONL | ISIG); | ||
2406 | /* reads will block only if < 1 char is available */ | ||
2407 | new_settings.c_cc[VMIN] = 1; | ||
2408 | /* no timeout (reads block forever) */ | ||
2409 | new_settings.c_cc[VTIME] = 0; | ||
2410 | /* Should be not needed if ISIG is off: */ | ||
2411 | /* Turn off CTRL-C */ | ||
2412 | /* new_settings.c_cc[VINTR] = _POSIX_VDISABLE; */ | ||
2413 | tcsetattr_stdin_TCSANOW(&new_settings); | 2401 | tcsetattr_stdin_TCSANOW(&new_settings); |
2414 | 2402 | ||
2415 | #if ENABLE_USERNAME_OR_HOMEDIR | 2403 | #if ENABLE_USERNAME_OR_HOMEDIR |
@@ -2942,7 +2930,7 @@ int main(int argc, char **argv) | |||
2942 | #if ENABLE_FEATURE_EDITING_FANCY_PROMPT | 2930 | #if ENABLE_FEATURE_EDITING_FANCY_PROMPT |
2943 | "\\[\\033[32;1m\\]\\u@\\[\\x1b[33;1m\\]\\h:" | 2931 | "\\[\\033[32;1m\\]\\u@\\[\\x1b[33;1m\\]\\h:" |
2944 | "\\[\\033[34;1m\\]\\w\\[\\033[35;1m\\] " | 2932 | "\\[\\033[34;1m\\]\\w\\[\\033[35;1m\\] " |
2945 | "\\!\\[\\e[36;1m\\]\\$ \\[\\E[0m\\]"; | 2933 | "\\!\\[\\e[36;1m\\]\\$ \\[\\E[m\\]"; |
2946 | #else | 2934 | #else |
2947 | "% "; | 2935 | "% "; |
2948 | #endif | 2936 | #endif |
diff --git a/libbb/u_signal_names.c b/libbb/u_signal_names.c index b82a706d8..b3038e32d 100644 --- a/libbb/u_signal_names.c +++ b/libbb/u_signal_names.c | |||
@@ -6,7 +6,6 @@ | |||
6 | * | 6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
8 | */ | 8 | */ |
9 | |||
10 | //config:config FEATURE_RTMINMAX | 9 | //config:config FEATURE_RTMINMAX |
11 | //config: bool "Support RTMIN[+n] and RTMAX[-n] signal names" | 10 | //config: bool "Support RTMIN[+n] and RTMAX[-n] signal names" |
12 | //config: default y | 11 | //config: default y |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 1b3a1667b..0dfb3e2d9 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -311,40 +311,65 @@ int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp) | |||
311 | return tcsetattr(STDIN_FILENO, TCSANOW, tp); | 311 | return tcsetattr(STDIN_FILENO, TCSANOW, tp); |
312 | } | 312 | } |
313 | 313 | ||
314 | int FAST_FUNC set_termios_to_raw(int fd, struct termios *oldterm, int flags) | 314 | int FAST_FUNC get_termios_and_make_raw(int fd, struct termios *newterm, struct termios *oldterm, int flags) |
315 | { | 315 | { |
316 | //TODO: lineedit, microcom, slattach, less might be adapted to use this too: | 316 | //TODO: slattach, shell read might be adapted to use this too: grep for "tcsetattr", "[VTIME] = 0" |
317 | // grep for "tcsetattr" | 317 | int r; |
318 | |||
319 | struct termios newterm; | ||
320 | 318 | ||
321 | tcgetattr(fd, oldterm); | 319 | memset(oldterm, 0, sizeof(*oldterm)); /* paranoia */ |
322 | newterm = *oldterm; | 320 | r = tcgetattr(fd, oldterm); |
321 | *newterm = *oldterm; | ||
323 | 322 | ||
324 | /* Turn off buffered input (ICANON) | 323 | /* Turn off buffered input (ICANON) |
325 | * Turn off echoing (ECHO) | 324 | * Turn off echoing (ECHO) |
326 | * and separate echoing of newline (ECHONL, normally off anyway) | 325 | * and separate echoing of newline (ECHONL, normally off anyway) |
327 | */ | 326 | */ |
328 | newterm.c_lflag &= ~(ICANON | ECHO | ECHONL); | 327 | newterm->c_lflag &= ~(ICANON | ECHO | ECHONL); |
329 | if (flags & TERMIOS_CLEAR_ISIG) { | 328 | if (flags & TERMIOS_CLEAR_ISIG) { |
330 | /* dont recognize INT/QUIT/SUSP chars */ | 329 | /* dont recognize INT/QUIT/SUSP chars */ |
331 | newterm.c_lflag &= ~ISIG; | 330 | newterm->c_lflag &= ~ISIG; |
332 | } | 331 | } |
333 | /* reads will block only if < 1 char is available */ | 332 | /* reads will block only if < 1 char is available */ |
334 | newterm.c_cc[VMIN] = 1; | 333 | newterm->c_cc[VMIN] = 1; |
335 | /* no timeout (reads block forever) */ | 334 | /* no timeout (reads block forever) */ |
336 | newterm.c_cc[VTIME] = 0; | 335 | newterm->c_cc[VTIME] = 0; |
337 | if (flags & TERMIOS_RAW_CRNL) { | 336 | if (flags & TERMIOS_RAW_CRNL) { |
337 | /* IXON, IXOFF, and IXANY: | ||
338 | * IXOFF=1: sw flow control is enabled on input queue: | ||
339 | * tty transmits a STOP char when input queue is close to full | ||
340 | * and transmits a START char when input queue is nearly empty. | ||
341 | * IXON=1: sw flow control is enabled on output queue: | ||
342 | * tty will stop sending if STOP char is received, | ||
343 | * and resume sending if START is received, or if any char | ||
344 | * is received and IXANY=1. | ||
345 | */ | ||
346 | /* IXON=0: XON/XOFF chars are treated as normal chars (why we do this?) */ | ||
338 | /* dont convert CR to NL on input */ | 347 | /* dont convert CR to NL on input */ |
339 | newterm.c_iflag &= ~(IXON | ICRNL); | 348 | newterm->c_iflag &= ~(IXON | ICRNL); |
340 | /* dont convert NL to CR on output */ | 349 | /* dont convert NL to CR+NL on output */ |
341 | newterm.c_oflag &= ~(ONLCR); | 350 | newterm->c_oflag &= ~(ONLCR); |
351 | /* Maybe clear more c_oflag bits? Usually, only OPOST and ONLCR are set. | ||
352 | * OPOST Enable output processing (reqd for OLCUC and *NL* bits to work) | ||
353 | * OLCUC Map lowercase characters to uppercase on output. | ||
354 | * OCRNL Map CR to NL on output. | ||
355 | * ONOCR Don't output CR at column 0. | ||
356 | * ONLRET Don't output CR. | ||
357 | */ | ||
342 | } | 358 | } |
343 | if (flags & TERMIOS_RAW_INPUT) { | 359 | if (flags & TERMIOS_RAW_INPUT) { |
360 | /* IXOFF=0: disable sending XON/XOFF if input buf is full */ | ||
361 | /* IXON=0: input XON/XOFF chars are not special */ | ||
344 | /* dont convert anything on input */ | 362 | /* dont convert anything on input */ |
345 | newterm.c_iflag &= ~(BRKINT|INLCR|ICRNL|IXON|IXOFF|IUCLC|IXANY|IMAXBEL); | 363 | newterm->c_iflag &= ~(IXOFF|IXON|IXANY|BRKINT|INLCR|ICRNL|IUCLC|IMAXBEL); |
346 | } | 364 | } |
365 | return r; | ||
366 | } | ||
367 | |||
368 | int FAST_FUNC set_termios_to_raw(int fd, struct termios *oldterm, int flags) | ||
369 | { | ||
370 | struct termios newterm; | ||
347 | 371 | ||
372 | get_termios_and_make_raw(fd, &newterm, oldterm, flags); | ||
348 | return tcsetattr(fd, TCSANOW, &newterm); | 373 | return tcsetattr(fd, TCSANOW, &newterm); |
349 | } | 374 | } |
350 | 375 | ||