From 7e8218f9b26946ec3b411bc25a62b6b4278f2386 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 18 Nov 2016 21:42:44 +0100 Subject: Fix allnoconfig warnings Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'libbb') diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 2d01a3ae7..bb7e905db 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -883,20 +883,21 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) } # endif /* NUM_APPLETS > 0 */ +# if ENABLE_BUSYBOX || NUM_APPLETS > 0 static NORETURN void run_applet_and_exit(const char *name, char **argv) { -# if ENABLE_BUSYBOX +# if ENABLE_BUSYBOX if (is_prefixed_with(name, "busybox")) exit(busybox_main(argv)); -# endif -# if NUM_APPLETS > 0 +# endif +# if NUM_APPLETS > 0 /* find_applet_by_name() search is more expensive, so goes second */ { int applet = find_applet_by_name(name); if (applet >= 0) run_applet_no_and_exit(applet, argv); } -# endif +# endif /*bb_error_msg_and_die("applet not found"); - links in printf */ full_write2_str(applet_name); @@ -904,11 +905,11 @@ static NORETURN void run_applet_and_exit(const char *name, char **argv) /* POSIX: "If a command is not found, the exit status shall be 127" */ exit(127); } +# endif #endif /* !defined(SINGLE_APPLET_MAIN) */ - #if ENABLE_BUILD_LIBBUSYBOX int lbb_main(char **argv) #else @@ -960,6 +961,7 @@ int main(int argc UNUSED_PARAM, char **argv) #endif #if defined(SINGLE_APPLET_MAIN) + /* Only one applet is selected in .config */ if (argv[1] && is_prefixed_with(argv[0], "busybox")) { /* "busybox " should still work as expected */ @@ -968,9 +970,16 @@ int main(int argc UNUSED_PARAM, char **argv) /* applet_names in this case is just "applet\0\0" */ lbb_prepare(applet_names IF_FEATURE_INDIVIDUAL(, argv)); return SINGLE_APPLET_MAIN(argc, argv); + +#elif !ENABLE_BUSYBOX && NUM_APPLETS == 0 + + full_write2_str(bb_basename(argv[0])); + full_write2_str(": no applets enabled\n"); + exit(127); + #else - lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv)); + lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv)); # if !ENABLE_BUSYBOX if (argv[1] && is_prefixed_with(bb_basename(argv[0]), "busybox")) argv++; @@ -979,9 +988,8 @@ int main(int argc UNUSED_PARAM, char **argv) if (applet_name[0] == '-') applet_name++; applet_name = bb_basename(applet_name); - parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ - run_applet_and_exit(applet_name, argv); + #endif } -- cgit v1.2.3-55-g6feb From 2e4ef38743c3d4aef109b5cc04429ec1f0e2f6c8 Mon Sep 17 00:00:00 2001 From: Rostislav Skudnov Date: Thu, 24 Nov 2016 15:04:00 +0100 Subject: lineedit: fix handling of repeating Alt-b, Alt-f, Alt-d, Alt-Backspace These key combinations should repeat correctly when the keys are pressed and held. Before this change, they do this erratically - many repeats are "eaten" because they are treated as unrecognized ESC seqs: ESC 0x7f is treated by Alt+baskspace, but ESC 0x7f ESC 0x7f ESC 0x7f is unrecognized. Escape sequences corresponding to these key combinations are moved from read_line_input to lineedit_read_key. Also, these key sequences are now enabled regardless of whether FEATURE_EDITING_VI is set, since Vim does not actually support these key combinations, but they are present in readline library. function old new delta static.esccmds 93 103 +10 read_line_input 3737 3687 -50 Signed-off-by: Rostislav Skudnov Signed-off-by: Denys Vlasenko --- include/libbb.h | 76 ++++++++++++++++++++++++++++---------------------------- libbb/lineedit.c | 60 ++++++++++++++------------------------------ libbb/read_key.c | 12 +++++++++ 3 files changed, 68 insertions(+), 80 deletions(-) (limited to 'libbb') diff --git a/include/libbb.h b/include/libbb.h index 20fc7329f..bdafcf5a6 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1463,46 +1463,46 @@ unsigned long long bb_makedev(unsigned major, unsigned minor) FAST_FUNC; * yet doesn't represent any valid Unicode character. * Also, -1 is reserved for error indication and we don't use it. */ enum { - KEYCODE_UP = -2, - KEYCODE_DOWN = -3, - KEYCODE_RIGHT = -4, - KEYCODE_LEFT = -5, - KEYCODE_HOME = -6, - KEYCODE_END = -7, - KEYCODE_INSERT = -8, - KEYCODE_DELETE = -9, - KEYCODE_PAGEUP = -10, - KEYCODE_PAGEDOWN = -11, - // -12 is reserved for Alt/Ctrl/Shift-TAB + KEYCODE_UP = -2, + KEYCODE_DOWN = -3, + KEYCODE_RIGHT = -4, + KEYCODE_LEFT = -5, + KEYCODE_HOME = -6, + KEYCODE_END = -7, + KEYCODE_INSERT = -8, + KEYCODE_DELETE = -9, + KEYCODE_PAGEUP = -10, + KEYCODE_PAGEDOWN = -11, + KEYCODE_BACKSPACE = -12, /* Used only if Alt/Ctrl/Shifted */ + KEYCODE_D = -13, /* Used only if Alted */ #if 0 - KEYCODE_FUN1 = -13, - KEYCODE_FUN2 = -14, - KEYCODE_FUN3 = -15, - KEYCODE_FUN4 = -16, - KEYCODE_FUN5 = -17, - KEYCODE_FUN6 = -18, - KEYCODE_FUN7 = -19, - KEYCODE_FUN8 = -20, - KEYCODE_FUN9 = -21, - KEYCODE_FUN10 = -22, - KEYCODE_FUN11 = -23, - KEYCODE_FUN12 = -24, -#endif - /* Be sure that last defined value is small enough - * to not interfere with Alt/Ctrl/Shift bits. - * So far we do not exceed -31 (0xfff..fffe1), - * which gives us three upper bits in LSB to play with. + KEYCODE_FUN1 = , + KEYCODE_FUN2 = , + KEYCODE_FUN3 = , + KEYCODE_FUN4 = , + KEYCODE_FUN5 = , + KEYCODE_FUN6 = , + KEYCODE_FUN7 = , + KEYCODE_FUN8 = , + KEYCODE_FUN9 = , + KEYCODE_FUN10 = , + KEYCODE_FUN11 = , + KEYCODE_FUN12 = , +#endif + /* ^^^^^ Be sure that last defined value is small enough. + * Current read_key() code allows going up to -32 (0xfff..fffe0). + * This gives three upper bits in LSB to play with: + * KEYCODE_foo values are 0xfff..fffXX, lowest XX bits are: scavvvvv, + * s=0 if SHIFT, c=0 if CTRL, a=0 if ALT, + * vvvvv bits are the same for same key regardless of "shift bits". */ - //KEYCODE_SHIFT_TAB = (-12) & ~0x80, - //KEYCODE_SHIFT_... = KEYCODE_... & ~0x80, - //KEYCODE_CTRL_UP = KEYCODE_UP & ~0x40, - //KEYCODE_CTRL_DOWN = KEYCODE_DOWN & ~0x40, - KEYCODE_CTRL_RIGHT = KEYCODE_RIGHT & ~0x40, - KEYCODE_CTRL_LEFT = KEYCODE_LEFT & ~0x40, - //KEYCODE_ALT_UP = KEYCODE_UP & ~0x20, - //KEYCODE_ALT_DOWN = KEYCODE_DOWN & ~0x20, - KEYCODE_ALT_RIGHT = KEYCODE_RIGHT & ~0x20, - KEYCODE_ALT_LEFT = KEYCODE_LEFT & ~0x20, + //KEYCODE_SHIFT_... = KEYCODE_... & ~0x80, + KEYCODE_CTRL_RIGHT = KEYCODE_RIGHT & ~0x40, + KEYCODE_CTRL_LEFT = KEYCODE_LEFT & ~0x40, + KEYCODE_ALT_RIGHT = KEYCODE_RIGHT & ~0x20, + KEYCODE_ALT_LEFT = KEYCODE_LEFT & ~0x20, + KEYCODE_ALT_BACKSPACE = KEYCODE_BACKSPACE & ~0x20, + KEYCODE_ALT_D = KEYCODE_D & ~0x20, KEYCODE_CURSOR_POS = -0x100, /* 0xfff..fff00 */ /* How long is the longest ESC sequence we know? diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 2cc61db40..ac049f57d 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -13,7 +13,6 @@ * * This code is 'as is' with no warranty. */ - /* * Usage and known bugs: * Terminal key codes are not extensive, more needs to be added. @@ -23,9 +22,6 @@ * Ctrl-E also works as End. * * The following readline-like commands are not implemented: - * ESC-b -- Move back one word - * ESC-f -- Move forward one word - * ESC-d -- Delete forward one word * CTL-t -- Transpose two characters * * lineedit does not know that the terminal escape sequences do not @@ -2483,6 +2479,24 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman while (cursor > 0 && !BB_isspace(command_ps[cursor-1])) input_backspace(); break; + case KEYCODE_ALT_D: { + /* Delete word forward */ + int nc, sc = cursor; + ctrl_right(); + nc = cursor - sc; + input_backward(nc); + while (--nc >= 0) + input_delete(1); + break; + } + case KEYCODE_ALT_BACKSPACE: { + /* Delete word backward */ + int sc = cursor; + ctrl_left(); + while (sc-- > cursor) + input_delete(1); + break; + } #if ENABLE_FEATURE_REVERSE_SEARCH case CTRL('R'): ic = ic_raw = reverse_i_search(); @@ -2625,44 +2639,6 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman vi_cmdmode = 1; input_backward(1); } - /* Handle a few ESC- combinations the same way - * standard readline bindings (IOW: bash) do. - * Often, Alt- generates ESC-. - */ - ic = lineedit_read_key(read_key_buffer, 50); - switch (ic) { - //case KEYCODE_LEFT: - bash doesn't do this - case 'b': - ctrl_left(); - break; - //case KEYCODE_RIGHT: - bash doesn't do this - case 'f': - ctrl_right(); - break; - //case KEYCODE_DELETE: - bash doesn't do this - case 'd': /* Alt-D */ - { - /* Delete word forward */ - int nc, sc = cursor; - ctrl_right(); - nc = cursor - sc; - input_backward(nc); - while (--nc >= 0) - input_delete(1); - break; - } - case '\b': /* Alt-Backspace(?) */ - case '\x7f': /* Alt-Backspace(?) */ - //case 'w': - bash doesn't do this - { - /* Delete word backward */ - int sc = cursor; - ctrl_left(); - while (sc-- > cursor) - input_delete(1); - break; - } - } break; #endif /* FEATURE_COMMAND_EDITING_VI */ diff --git a/libbb/read_key.c b/libbb/read_key.c index ace23defb..951786869 100644 --- a/libbb/read_key.c +++ b/libbb/read_key.c @@ -18,8 +18,20 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) /* Known escape sequences for cursor and function keys. * See "Xterm Control Sequences" * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html + * Array should be sorted from shortest to longest. */ static const char esccmds[] ALIGN1 = { + '\x7f' |0x80,KEYCODE_ALT_BACKSPACE, + '\b' |0x80,KEYCODE_ALT_BACKSPACE, + 'd' |0x80,KEYCODE_ALT_D , + /* lineedit mimics bash: Alt-f and Alt-b are forward/backward + * word jumps. We cheat here and make them return ALT_LEFT/RIGHT + * keycodes. This way, lineedit need no special code to handle them. + * If we'll need to distinguish them, introduce new ALT_F/B keycodes, + * and update lineedit to react to them. + */ + 'f' |0x80,KEYCODE_ALT_RIGHT, + 'b' |0x80,KEYCODE_ALT_LEFT, 'O','A' |0x80,KEYCODE_UP , 'O','B' |0x80,KEYCODE_DOWN , 'O','C' |0x80,KEYCODE_RIGHT , -- cgit v1.2.3-55-g6feb From 1255925a6121cc5f2f09fbe40f2434ab11cc84f7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 24 Nov 2016 22:18:55 +0100 Subject: Move locale, unicode, and "use sendfile?" options to library tuning Signed-off-by: Denys Vlasenko --- Config.in | 138 ------------------------------------------------------- libbb/Config.src | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 138 deletions(-) (limited to 'libbb') diff --git a/Config.in b/Config.in index 089879914..3d1759e21 100644 --- a/Config.in +++ b/Config.in @@ -147,131 +147,6 @@ config INSTALL_NO_USR will install applets only to /bin and /sbin, never to /usr/bin or /usr/sbin. -config LOCALE_SUPPORT - bool "Enable locale support (system needs locale for this to work)" - default n - help - Enable this if your system has locale support and you would like - busybox to support locale settings. - -config UNICODE_SUPPORT - bool "Support Unicode" - default y - help - This makes various applets aware that one byte is not - one character on screen. - - Busybox aims to eventually work correctly with Unicode displays. - Any older encodings are not guaranteed to work. - Probably by the time when busybox will be fully Unicode-clean, - other encodings will be mainly of historic interest. - -config UNICODE_USING_LOCALE - bool "Use libc routines for Unicode (else uses internal ones)" - default n - depends on UNICODE_SUPPORT && LOCALE_SUPPORT - help - With this option on, Unicode support is implemented using libc - routines. Otherwise, internal implementation is used. - Internal implementation is smaller. - -config FEATURE_CHECK_UNICODE_IN_ENV - bool "Check $LC_ALL, $LC_CTYPE and $LANG environment variables" - default n - depends on UNICODE_SUPPORT && !UNICODE_USING_LOCALE - help - With this option on, Unicode support is activated - only if locale-related variables have the value of the form - "xxxx.utf8" - - Otherwise, Unicode support will be always enabled and active. - -config SUBST_WCHAR - int "Character code to substitute unprintable characters with" - depends on UNICODE_SUPPORT - default 63 - help - Typical values are 63 for '?' (works with any output device), - 30 for ASCII substitute control code, - 65533 (0xfffd) for Unicode replacement character. - -config LAST_SUPPORTED_WCHAR - int "Range of supported Unicode characters" - depends on UNICODE_SUPPORT - default 767 - help - Any character with Unicode value bigger than this is assumed - to be non-printable on output device. Many applets replace - such characters with substitution character. - - The idea is that many valid printable Unicode chars - nevertheless are not displayed correctly. Think about - combining charachers, double-wide hieroglyphs, obscure - characters in dozens of ancient scripts... - Many terminals, terminal emulators, xterms etc will fail - to handle them correctly. Choose the smallest value - which suits your needs. - - Typical values are: - 126 - ASCII only - 767 (0x2ff) - there are no combining chars in [0..767] range - (the range includes Latin 1, Latin Ext. A and B), - code is ~700 bytes smaller for this case. - 4351 (0x10ff) - there are no double-wide chars in [0..4351] range, - code is ~300 bytes smaller for this case. - 12799 (0x31ff) - nearly all non-ideographic characters are - available in [0..12799] range, including - East Asian scripts like katakana, hiragana, hangul, - bopomofo... - 0 - off, any valid printable Unicode character will be printed. - -config UNICODE_COMBINING_WCHARS - bool "Allow zero-width Unicode characters on output" - default n - depends on UNICODE_SUPPORT - help - With this option off, any Unicode char with width of 0 - is substituted on output. - -config UNICODE_WIDE_WCHARS - bool "Allow wide Unicode characters on output" - default n - depends on UNICODE_SUPPORT - help - With this option off, any Unicode char with width > 1 - is substituted on output. - -config UNICODE_BIDI_SUPPORT - bool "Bidirectional character-aware line input" - default n - depends on UNICODE_SUPPORT && !UNICODE_USING_LOCALE - help - With this option on, right-to-left Unicode characters - are treated differently on input (e.g. cursor movement). - -config UNICODE_NEUTRAL_TABLE - bool "In bidi input, support non-ASCII neutral chars too" - default n - depends on UNICODE_BIDI_SUPPORT - help - In most cases it's enough to treat only ASCII non-letters - (i.e. punctuation, numbers and space) as characters - with neutral directionality. - With this option on, more extensive (and bigger) table - of neutral chars will be used. - -config UNICODE_PRESERVE_BROKEN - bool "Make it possible to enter sequences of chars which are not Unicode" - default n - depends on UNICODE_SUPPORT - help - With this option on, on line-editing input (such as used by shells) - invalid UTF-8 bytes are not substituted with the selected - substitution character. - For example, this means that entering 'l', 's', ' ', 0xff, [Enter] - at shell prompt will list file named 0xff (single char name - with char value 255), not file named '?'. - config PAM bool "Support for PAM (Pluggable Authentication Modules)" default n @@ -279,19 +154,6 @@ config PAM Use PAM in some busybox applets (currently login and httpd) instead of direct access to password database. -config FEATURE_USE_SENDFILE - bool "Use sendfile system call" - default y - select PLATFORM_LINUX - help - When enabled, busybox will use the kernel sendfile() function - instead of read/write loops to copy data between file descriptors - (for example, cp command does this a lot). - If sendfile() doesn't work, copying code falls back to read/write - loop. sendfile() was originally implemented for faster I/O - from files to sockets, but since Linux 2.6.33 it was extended - to work for many more file types. - config LONG_OPTS bool "Support for --long-options" default y diff --git a/libbb/Config.src b/libbb/Config.src index 6ba256290..18a40f2ac 100644 --- a/libbb/Config.src +++ b/libbb/Config.src @@ -153,6 +153,131 @@ config FEATURE_EDITING_ASK_TERMINAL correctly, or want to save on code size (about 400 bytes), then do not turn this option on. +config LOCALE_SUPPORT + bool "Enable locale support (system needs locale for this to work)" + default n + help + Enable this if your system has locale support and you would like + busybox to support locale settings. + +config UNICODE_SUPPORT + bool "Support Unicode" + default y + help + This makes various applets aware that one byte is not + one character on screen. + + Busybox aims to eventually work correctly with Unicode displays. + Any older encodings are not guaranteed to work. + Probably by the time when busybox will be fully Unicode-clean, + other encodings will be mainly of historic interest. + +config UNICODE_USING_LOCALE + bool "Use libc routines for Unicode (else uses internal ones)" + default n + depends on UNICODE_SUPPORT && LOCALE_SUPPORT + help + With this option on, Unicode support is implemented using libc + routines. Otherwise, internal implementation is used. + Internal implementation is smaller. + +config FEATURE_CHECK_UNICODE_IN_ENV + bool "Check $LC_ALL, $LC_CTYPE and $LANG environment variables" + default n + depends on UNICODE_SUPPORT && !UNICODE_USING_LOCALE + help + With this option on, Unicode support is activated + only if locale-related variables have the value of the form + "xxxx.utf8" + + Otherwise, Unicode support will be always enabled and active. + +config SUBST_WCHAR + int "Character code to substitute unprintable characters with" + depends on UNICODE_SUPPORT + default 63 + help + Typical values are 63 for '?' (works with any output device), + 30 for ASCII substitute control code, + 65533 (0xfffd) for Unicode replacement character. + +config LAST_SUPPORTED_WCHAR + int "Range of supported Unicode characters" + depends on UNICODE_SUPPORT + default 767 + help + Any character with Unicode value bigger than this is assumed + to be non-printable on output device. Many applets replace + such characters with substitution character. + + The idea is that many valid printable Unicode chars + nevertheless are not displayed correctly. Think about + combining charachers, double-wide hieroglyphs, obscure + characters in dozens of ancient scripts... + Many terminals, terminal emulators, xterms etc will fail + to handle them correctly. Choose the smallest value + which suits your needs. + + Typical values are: + 126 - ASCII only + 767 (0x2ff) - there are no combining chars in [0..767] range + (the range includes Latin 1, Latin Ext. A and B), + code is ~700 bytes smaller for this case. + 4351 (0x10ff) - there are no double-wide chars in [0..4351] range, + code is ~300 bytes smaller for this case. + 12799 (0x31ff) - nearly all non-ideographic characters are + available in [0..12799] range, including + East Asian scripts like katakana, hiragana, hangul, + bopomofo... + 0 - off, any valid printable Unicode character will be printed. + +config UNICODE_COMBINING_WCHARS + bool "Allow zero-width Unicode characters on output" + default n + depends on UNICODE_SUPPORT + help + With this option off, any Unicode char with width of 0 + is substituted on output. + +config UNICODE_WIDE_WCHARS + bool "Allow wide Unicode characters on output" + default n + depends on UNICODE_SUPPORT + help + With this option off, any Unicode char with width > 1 + is substituted on output. + +config UNICODE_BIDI_SUPPORT + bool "Bidirectional character-aware line input" + default n + depends on UNICODE_SUPPORT && !UNICODE_USING_LOCALE + help + With this option on, right-to-left Unicode characters + are treated differently on input (e.g. cursor movement). + +config UNICODE_NEUTRAL_TABLE + bool "In bidi input, support non-ASCII neutral chars too" + default n + depends on UNICODE_BIDI_SUPPORT + help + In most cases it's enough to treat only ASCII non-letters + (i.e. punctuation, numbers and space) as characters + with neutral directionality. + With this option on, more extensive (and bigger) table + of neutral chars will be used. + +config UNICODE_PRESERVE_BROKEN + bool "Make it possible to enter sequences of chars which are not Unicode" + default n + depends on UNICODE_SUPPORT + help + With this option on, on line-editing input (such as used by shells) + invalid UTF-8 bytes are not substituted with the selected + substitution character. + For example, this means that entering 'l', 's', ' ', 0xff, [Enter] + at shell prompt will list file named 0xff (single char name + with char value 255), not file named '?'. + config FEATURE_NON_POSIX_CP bool "Non-POSIX, but safer, copying to special nodes" default y @@ -177,6 +302,19 @@ config FEATURE_VERBOSE_CP_MESSAGE cp: cannot stat '/vmlinuz/file': Not a directory This will cost you ~60 bytes. +config FEATURE_USE_SENDFILE + bool "Use sendfile system call" + default y + select PLATFORM_LINUX + help + When enabled, busybox will use the kernel sendfile() function + instead of read/write loops to copy data between file descriptors + (for example, cp command does this a lot). + If sendfile() doesn't work, copying code falls back to read/write + loop. sendfile() was originally implemented for faster I/O + from files to sockets, but since Linux 2.6.33 it was extended + to work for many more file types. + config FEATURE_COPYBUF_KB int "Copy buffer size, in kilobytes" range 1 1024 -- cgit v1.2.3-55-g6feb From 24860fa09cf954704232406055d7ca291c636eab Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 24 Nov 2016 22:30:52 +0100 Subject: Move FEATURE_BUFFERS_USE_foo options to library tuning Signed-off-by: Denys Vlasenko --- Config.in | 24 ------------------------ libbb/Config.src | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 24 deletions(-) (limited to 'libbb') diff --git a/Config.in b/Config.in index 3d1759e21..924a197da 100644 --- a/Config.in +++ b/Config.in @@ -61,30 +61,6 @@ config PLATFORM_LINUX Answering 'N' here will disable such applets and hide the corresponding configuration options. -choice - prompt "Buffer allocation policy" - default FEATURE_BUFFERS_USE_MALLOC - help - There are 3 ways BusyBox can handle buffer allocations: - - Use malloc. This costs code size for the call to xmalloc. - - Put them on stack. For some very small machines with limited stack - space, this can be deadly. For most folks, this works just fine. - - Put them in BSS. This works beautifully for computers with a real - MMU (and OS support), but wastes runtime RAM for uCLinux. This - behavior was the only one available for BusyBox versions 0.48 and - earlier. - -config FEATURE_BUFFERS_USE_MALLOC - bool "Allocate with Malloc" - -config FEATURE_BUFFERS_GO_ON_STACK - bool "Allocate on the Stack" - -config FEATURE_BUFFERS_GO_IN_BSS - bool "Allocate in the .bss section" - -endchoice - config SHOW_USAGE bool "Show applet usage messages" default y diff --git a/libbb/Config.src b/libbb/Config.src index 18a40f2ac..00804e31e 100644 --- a/libbb/Config.src +++ b/libbb/Config.src @@ -7,6 +7,30 @@ menu "Busybox Library Tuning" INSERT +choice + prompt "Buffer allocation policy" + default FEATURE_BUFFERS_USE_MALLOC + help + There are 3 ways BusyBox can handle buffer allocations: + - Use malloc. This costs code size for the call to xmalloc. + - Put them on stack. For some very small machines with limited stack + space, this can be deadly. For most folks, this works just fine. + - Put them in BSS. This works beautifully for computers with a real + MMU (and OS support), but wastes runtime RAM for uCLinux. This + behavior was the only one available for BusyBox versions 0.48 and + earlier. + +config FEATURE_BUFFERS_USE_MALLOC + bool "Allocate with Malloc" + +config FEATURE_BUFFERS_GO_ON_STACK + bool "Allocate on the Stack" + +config FEATURE_BUFFERS_GO_IN_BSS + bool "Allocate in the .bss section" + +endchoice + config PASSWORD_MINLEN int "Minimum password length" default 6 -- cgit v1.2.3-55-g6feb From 4b89d512b1215e7b9d619af03496540d30cbbd1a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 25 Nov 2016 03:41:03 +0100 Subject: ash,hush: make ^C in interactive mode visually much closer to bash behavior Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 2 +- shell/ash.c | 4 +++- shell/hush.c | 17 +++++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) (limited to 'libbb') diff --git a/libbb/lineedit.c b/libbb/lineedit.c index ac049f57d..4d7828cfa 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -2251,6 +2251,7 @@ static int32_t reverse_i_search(void) * Returns: * -1 on read errors or EOF, or on bare Ctrl-D, * 0 on ctrl-C (the line entered is still returned in 'command'), + * (in both cases the cursor remains on the input line, '\n' is not printed) * >0 length of input string, including terminating '\n' */ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize, int timeout) @@ -2686,7 +2687,6 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman && ic_raw == initial_settings.c_cc[VINTR] ) { /* Ctrl-C (usually) - stop gathering input */ - goto_new_line(); command_len = 0; break_out = -1; /* "do not append '\n'" */ break; diff --git a/shell/ash.c b/shell/ash.c index 3e5a3b3e9..2bdb4aad7 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -9869,7 +9869,8 @@ preadfd(void) reinit_unicode_for_ash(); nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ, timeout); if (nr == 0) { - /* Ctrl+C pressed */ + /* ^C pressed, "convert" to SIGINT */ + write(STDOUT_FILENO, "^C", 2); if (trap[SIGINT]) { buf[0] = '\n'; buf[1] = '\0'; @@ -9877,6 +9878,7 @@ preadfd(void) return 1; } exitstatus = 128 + SIGINT; + bb_putchar('\n'); goto retry; } if (nr < 0) { diff --git a/shell/hush.c b/shell/hush.c index 5b720ce98..bcd4dffee 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -1756,8 +1756,6 @@ static int check_and_run_traps(void) switch (sig) { case SIGINT: debug_printf_exec("%s: sig:%d default SIGINT handler\n", __func__, sig); - /* Builtin was ^C'ed, make it look prettier: */ - bb_putchar('\n'); G.flag_SIGINT = 1; last_sig = sig; break; @@ -2195,16 +2193,22 @@ static int get_user_input(struct in_str *i) # if ENABLE_FEATURE_EDITING for (;;) { reinit_unicode_for_hush(); - G.flag_SIGINT = 0; + if (G.flag_SIGINT) { + /* There was ^C'ed, make it look prettier: */ + bb_putchar('\n'); + G.flag_SIGINT = 0; + } /* buglet: SIGINT will not make new prompt to appear _at once_, - * only after . (^C will work) */ + * only after . (^C works immediately) */ r = read_line_input(G.line_input_state, prompt_str, G.user_input_buf, CONFIG_FEATURE_EDITING_MAX_LEN-1, /*timeout*/ -1 ); - /* read_line_input intercepts ^C, "convert" it into SIGINT */ - if (r == 0) + /* read_line_input intercepts ^C, "convert" it to SIGINT */ + if (r == 0) { + write(STDOUT_FILENO, "^C", 2); raise(SIGINT); + } check_and_run_traps(); if (r != 0 && !G.flag_SIGINT) break; @@ -2232,6 +2236,7 @@ static int get_user_input(struct in_str *i) fputs(prompt_str, stdout); } fflush_all(); +//FIXME: here ^C or SIGINT will have effect only after r = fgetc(i->file); /* In !ENABLE_FEATURE_EDITING we don't use read_line_input, * no ^C masking happens during fgetc, no special code for ^C: -- cgit v1.2.3-55-g6feb From bff71d3b9d4244abc5182c38d0a98f4913188391 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 27 Nov 2016 22:25:07 +0100 Subject: lineedit: fix two bugs in SIGWINCH signal handling (1) restore entire sigaction, not only signal handler function (2) do not use stdio when not sure WINCH did not interrupt a printf() or such. function old new delta cmdedit_setwidth - 81 +81 read_line_input 3682 3722 +40 lineedit_read_key 138 155 +17 put_prompt 55 51 -4 win_changed 93 47 -46 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/2 up/down: 138/-50) Total: 88 bytes Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 70 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 29 deletions(-) (limited to 'libbb') diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 4d7828cfa..7a1b5433d 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -129,8 +129,7 @@ static const char null_str[] ALIGN1 = ""; struct lineedit_statics { line_input_t *state; - volatile unsigned cmdedit_termw; /* = 80; */ /* actual terminal width */ - sighandler_t previous_SIGWINCH_handler; + unsigned cmdedit_termw; /* = 80; */ /* actual terminal width */ unsigned cmdedit_x; /* real x (col) terminal position */ unsigned cmdedit_y; /* pseudoreal y (row) terminal position */ @@ -155,15 +154,22 @@ struct lineedit_statics { unsigned num_matches; #endif + unsigned SIGWINCH_saved; + volatile unsigned SIGWINCH_count; + volatile smallint ok_to_redraw; + #if ENABLE_FEATURE_EDITING_VI # define DELBUFSIZ 128 - CHAR_T *delptr; smallint newdelflag; /* whether delbuf should be reused yet */ + CHAR_T *delptr; CHAR_T delbuf[DELBUFSIZ]; /* a place to store deleted characters */ #endif #if ENABLE_FEATURE_EDITING_ASK_TERMINAL smallint sent_ESC_br6n; #endif + + /* Largish struct, keeping it last results in smaller code */ + struct sigaction SIGWINCH_handler; }; /* See lineedit_ptr_hack.c */ @@ -172,7 +178,6 @@ extern struct lineedit_statics *const lineedit_ptr_to_statics; #define S (*lineedit_ptr_to_statics) #define state (S.state ) #define cmdedit_termw (S.cmdedit_termw ) -#define previous_SIGWINCH_handler (S.previous_SIGWINCH_handler) #define cmdedit_x (S.cmdedit_x ) #define cmdedit_y (S.cmdedit_y ) #define cmdedit_prmt_len (S.cmdedit_prmt_len) @@ -434,14 +439,11 @@ static void beep(void) static void put_prompt(void) { - unsigned w; - fputs(cmdedit_prompt, stdout); fflush_all(); cursor = 0; - w = cmdedit_termw; /* read volatile var once */ - cmdedit_y = cmdedit_prmt_len / w; /* new quasireal y */ - cmdedit_x = cmdedit_prmt_len % w; + cmdedit_y = cmdedit_prmt_len / cmdedit_termw; /* new quasireal y */ + cmdedit_x = cmdedit_prmt_len % cmdedit_termw; } /* Move back one character */ @@ -513,13 +515,11 @@ static void input_backward(unsigned num) put_cur_glyph_and_inc_cursor(); } else { int lines_up; - unsigned width; /* num = chars to go back from the beginning of current line: */ num -= cmdedit_x; - width = cmdedit_termw; /* read volatile var once */ /* num=1...w: one line up, w+1...2w: two, etc: */ - lines_up = 1 + (num - 1) / width; - cmdedit_x = (width * cmdedit_y - num) % width; + lines_up = 1 + (num - 1) / cmdedit_termw; + cmdedit_x = (cmdedit_termw * cmdedit_y - num) % cmdedit_termw; cmdedit_y -= lines_up; /* go to 1st column; go up */ printf("\r" ESC"[%uA", lines_up); @@ -1978,28 +1978,29 @@ static void parse_and_put_prompt(const char *prmt_ptr) } #endif -static void cmdedit_setwidth(unsigned w, int redraw_flg) +static void cmdedit_setwidth(int redraw_flg) { - cmdedit_termw = w; + get_terminal_width_height(STDIN_FILENO, &cmdedit_termw, NULL); if (redraw_flg) { /* new y for current cursor */ - int new_y = (cursor + cmdedit_prmt_len) / w; + int new_y = (cursor + cmdedit_prmt_len) / cmdedit_termw; /* redraw */ redraw((new_y >= cmdedit_y ? new_y : cmdedit_y), command_len - cursor); fflush_all(); } } -static void win_changed(int nsig) +static void win_changed(int nsig UNUSED_PARAM) { - int sv_errno = errno; - unsigned width; - - get_terminal_width_height(0, &width, NULL); -//FIXME: cmdedit_setwidth() -> redraw() -> printf() -> KABOOM! (we are in signal handler!) - cmdedit_setwidth(width, /*redraw_flg:*/ nsig); - - errno = sv_errno; + if (S.ok_to_redraw) { + /* We are in read_key(), safe to redraw immediately */ + int sv_errno = errno; + cmdedit_setwidth(/*redraw_flg:*/ 1); + errno = sv_errno; + } else { + /* Signal main loop that redraw is necessary */ + S.SIGWINCH_count++; + } } static int lineedit_read_key(char *read_key_buffer, int timeout) @@ -2018,7 +2019,9 @@ static int lineedit_read_key(char *read_key_buffer, int timeout) * * Note: read_key sets errno to 0 on success. */ + S.ok_to_redraw = 1; ic = read_key(STDIN_FILENO, read_key_buffer, timeout); + S.ok_to_redraw = 0; if (errno) { #if ENABLE_UNICODE_SUPPORT if (errno == EAGAIN && unicode_idx != 0) @@ -2355,9 +2358,11 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman ask_terminal(); /* Install window resize handler (NB: after *all* init is complete) */ -//FIXME: save entire sigaction! - previous_SIGWINCH_handler = signal(SIGWINCH, win_changed); - win_changed(0); /* get initial window size */ + S.SIGWINCH_handler.sa_handler = win_changed; + S.SIGWINCH_handler.sa_flags = SA_RESTART; + sigaction(SIGWINCH, &S.SIGWINCH_handler, &S.SIGWINCH_handler); + + cmdedit_setwidth(/*redraw_flg:*/ 0); /* get initial window size */ read_key_buffer[0] = 0; while (1) { @@ -2370,6 +2375,13 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman * in one place. */ int32_t ic, ic_raw; + unsigned count; + + count = S.SIGWINCH_count; + if (S.SIGWINCH_saved != count) { + S.SIGWINCH_saved = count; + cmdedit_setwidth(/*redraw_flg:*/ 1); + } fflush_all(); ic = ic_raw = lineedit_read_key(read_key_buffer, timeout); @@ -2808,7 +2820,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman /* restore initial_settings */ tcsetattr_stdin_TCSANOW(&initial_settings); /* restore SIGWINCH handler */ - signal(SIGWINCH, previous_SIGWINCH_handler); + sigaction_set(SIGWINCH, &S.SIGWINCH_handler); fflush_all(); len = command_len; -- cgit v1.2.3-55-g6feb From 038a977d47c99c3e59d7a2393799b2afa838604c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 28 Nov 2016 01:10:16 +0100 Subject: lineedit: simplify code a bit function old new delta lineedit_read_key 155 162 +7 put_prompt 51 46 -5 read_line_input 3722 3715 -7 cmdedit_setwidth 81 50 -31 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 7/-43) Total: -36 bytes Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'libbb') diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 7a1b5433d..31e392147 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -440,7 +440,6 @@ static void beep(void) static void put_prompt(void) { fputs(cmdedit_prompt, stdout); - fflush_all(); cursor = 0; cmdedit_y = cmdedit_prmt_len / cmdedit_termw; /* new quasireal y */ cmdedit_x = cmdedit_prmt_len % cmdedit_termw; @@ -1978,16 +1977,15 @@ static void parse_and_put_prompt(const char *prmt_ptr) } #endif -static void cmdedit_setwidth(int redraw_flg) +static void cmdedit_setwidth(void) { - get_terminal_width_height(STDIN_FILENO, &cmdedit_termw, NULL); - if (redraw_flg) { - /* new y for current cursor */ - int new_y = (cursor + cmdedit_prmt_len) / cmdedit_termw; - /* redraw */ - redraw((new_y >= cmdedit_y ? new_y : cmdedit_y), command_len - cursor); - fflush_all(); - } + int new_y; + + cmdedit_termw = get_terminal_width(STDIN_FILENO); + /* new y for current cursor */ + new_y = (cursor + cmdedit_prmt_len) / cmdedit_termw; + /* redraw */ + redraw((new_y >= cmdedit_y ? new_y : cmdedit_y), command_len - cursor); } static void win_changed(int nsig UNUSED_PARAM) @@ -1995,7 +1993,8 @@ static void win_changed(int nsig UNUSED_PARAM) if (S.ok_to_redraw) { /* We are in read_key(), safe to redraw immediately */ int sv_errno = errno; - cmdedit_setwidth(/*redraw_flg:*/ 1); + cmdedit_setwidth(); + fflush_all(); errno = sv_errno; } else { /* Signal main loop that redraw is necessary */ @@ -2011,6 +2010,7 @@ static int lineedit_read_key(char *read_key_buffer, int timeout) int unicode_idx = 0; #endif + fflush_all(); while (1) { /* Wait for input. TIMEOUT = -1 makes read_key wait even * on nonblocking stdin, TIMEOUT = 50 makes sure we won't @@ -2152,7 +2152,6 @@ static int32_t reverse_i_search(void) int h; unsigned match_buf_len = strlen(match_buf); - fflush_all(); //FIXME: correct timeout? ic = lineedit_read_key(read_key_buffer, -1); @@ -2282,7 +2281,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman * tty is still in "raw mode"). */ parse_and_put_prompt(prompt); - /* fflush_all(); - done by parse_and_put_prompt */ + fflush_all(); if (fgets(command, maxsize, stdin) == NULL) len = -1; /* EOF or error */ else @@ -2362,7 +2361,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman S.SIGWINCH_handler.sa_flags = SA_RESTART; sigaction(SIGWINCH, &S.SIGWINCH_handler, &S.SIGWINCH_handler); - cmdedit_setwidth(/*redraw_flg:*/ 0); /* get initial window size */ + cmdedit_termw = get_terminal_width(STDIN_FILENO); read_key_buffer[0] = 0; while (1) { @@ -2380,10 +2379,9 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman count = S.SIGWINCH_count; if (S.SIGWINCH_saved != count) { S.SIGWINCH_saved = count; - cmdedit_setwidth(/*redraw_flg:*/ 1); + cmdedit_setwidth(); } - fflush_all(); ic = ic_raw = lineedit_read_key(read_key_buffer, timeout); #if ENABLE_FEATURE_REVERSE_SEARCH -- cgit v1.2.3-55-g6feb From 7d877fc9312a742b06125927bb1d34bd35398c6c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 28 Nov 2016 01:29:28 +0100 Subject: Do not print useless empty line after list of applets Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libbb') diff --git a/libbb/appletlib.c b/libbb/appletlib.c index bb7e905db..9425c7bd4 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -777,7 +777,7 @@ static int busybox_main(char **argv) col += len2; a += len2 - 1; } - full_write2_str("\n\n"); + full_write2_str("\n"); return 0; } -- cgit v1.2.3-55-g6feb