aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
| * shell/read: do not allow empty variable nameDenys Vlasenko2023-06-171-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: eliminate some redundant stores on return code pathDenys Vlasenko2023-06-171-20/+23
| | | | | | | | | | | | | | function old new delta evaluate_string 1432 1412 -20 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: change ?: nesting code to not have 63 level nesting limitationDenys Vlasenko2023-06-172-14/+21
| | | | | | | | | | | | | | | | | | | | | | function old new delta evaluate_string 1406 1432 +26 arith 36 29 -7 arith_apply 998 990 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 26/-15) Total: 11 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math.h: update comments, rearrange struct members for smaller codeDenys Vlasenko2023-06-172-23/+5
| | | | | | | | | | | | | | | | | | | | function old new delta arith_apply 1000 998 -2 evaluate_string 1414 1406 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-10) Total: -10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: code shrinkDenys Vlasenko2023-06-171-3/+3
| | | | | | | | | | | | | | function old new delta evaluate_string 1432 1414 -18 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: tweka commentsDenys Vlasenko2023-06-161-16/+8
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: fix ?: to not evaluate not-taken branchesDenys Vlasenko2023-06-1626-24/+131
| | | | | | | | | | | | | | | | | | | | | | | | | | This fixes ash-arith-arith-ternary1/2.tests function old new delta evaluate_string 1271 1432 +161 arith_apply 968 1000 +32 arith 22 36 +14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 207/0) Total: 207 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: simplify handling of unary plusDenys Vlasenko2023-06-151-3/+5
| | | | | | | | | | | | | | | | | | | | function old new delta evaluate_string 1257 1271 +14 arith_apply 977 968 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-9) Total: 5 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: explain the logic, small tweak to make code smallerDenys Vlasenko2023-06-151-10/+25
| | | | | | | | | | | | | | function old new delta evaluate_string 1258 1257 -1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: fix order of expansion of variables to numbersDenys Vlasenko2023-06-153-34/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | This fixes arith-assign-in-varexp1.tests function old new delta evaluate_string 1132 1258 +126 arith_lookup_val 143 - -143 arith_apply 1132 977 -155 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/1 up/down: 126/-298) Total: -172 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: document another arithmetic discrepancy with bashDenys Vlasenko2023-06-152-0/+11
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: code shrink: introduce and use [_]exit_FAILURE()Denys Vlasenko2023-06-1521-27/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta exit_FAILURE - 7 +7 _exit_FAILURE - 7 +7 run 198 199 +1 restore_state_and_exit 114 115 +1 xbsd_write_bootstrap 399 397 -2 vfork_compressor 209 207 -2 sig_handler 12 10 -2 serial_ctl 154 152 -2 parse_args 1169 1167 -2 onintr 21 19 -2 make_new_session 493 491 -2 login_main 988 986 -2 gotsig 35 33 -2 do_iplink 1315 1313 -2 addgroup_main 397 395 -2 inetd_main 1911 1908 -3 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 2/12 up/down: 16/-25) Total: -9 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: remove special code to handle a?b?c:d:e, it works without it nowDenys Vlasenko2023-06-155-9/+9
| | | | | | | | | | | | | | | | | | | | | | The "hack" to virtually parenthesize ? EXPR : made this unnecessary. The expression is effectively a?(b?(c):d):e and thus b?c:d is evaluated before continuing with the second : function old new delta evaluate_string 1148 1132 -16 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: fix parsing of ?: and explain why it's parsed that wayDenys Vlasenko2023-06-1511-26/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes arith-precedence1.tests. This breaks arith-ternary2.tests again (we now evaluate variables on not-taken branches). We need a better logic here anyway: not only bare variables should not evaluate when not-taken: 1 ? eval_me : do_not_eval but any (arbitrarily complex) expressions shouldn't evaluate as well! 1 ? var_is_set=1 : ((var_is_not_set=2,var2*=4)) function old new delta evaluate_string 1097 1148 +51 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: simpler insertion of "fake" last RPARENDenys Vlasenko2023-06-151-7/+6
| | | | | | | | | | | | | | | | | | Skip one pass through token table, since we know the result. function old new delta evaluate_string 1095 1097 +2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: sync ash/hush test scriptsDenys Vlasenko2023-06-142-8/+25
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: trivial code shrinkDenys Vlasenko2023-06-141-4/+3
| | | | | | | | | | | | | | function old new delta arith_apply 1143 1132 -11 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: fix the order of variable resolution in binopsDenys Vlasenko2023-06-149-12/+48
| | | | | | | | | | | | | | function old new delta arith_apply 1134 1143 +9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: remove now-unused second_valDenys Vlasenko2023-06-141-20/+3
| | | | | | | | | | | | | | | | | | | | | | function old new delta arith_apply 1137 1134 -3 evaluate_string 1101 1095 -6 arith_lookup_val 150 143 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-16) Total: -16 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: fix nested ?: and do not parse variables in not-taken branchDenys Vlasenko2023-06-147-43/+61
| | | | | | | | | | | | | | | | | | | | | | | | Fixes arith-ternary1.tests and arith-ternary_nested.tests function old new delta evaluate_string 1043 1101 +58 arith_apply 1087 1137 +50 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 108/0) Total: 108 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: remove a redundant checkDenys Vlasenko2023-06-141-6/+6
| | | | | | | | | | | | | | function old new delta arith_apply 1134 1087 -47 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: document ternary ?: op's weirdness, add code commentsDenys Vlasenko2023-06-143-28/+65
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * syslogd: daemonize _after_ init (so that init errors are visible, if they occur)Denys Vlasenko2023-06-131-8/+8
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * syslogd: decrease stack usage, ~50 bytesDenys Vlasenko2023-06-131-75/+81
| | | | | | | | | | | | | | | | | | | | function old new delta syslogd_init - 1007 +1007 syslogd_main 1619 636 -983 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 1007/-983) Total: 24 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: fix one name check, other minor cleanupsDenys Vlasenko2023-06-131-8/+12
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: add a few yet-failing arithmentic testsDenys Vlasenko2023-06-1310-0/+43
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: reduce stack usageDenys Vlasenko2023-06-131-30/+36
| | | | | | | | | | | | | | | | | | | | | | function old new delta arith_apply 1123 1134 +11 arith_lookup_val 140 145 +5 evaluate_string 1053 1047 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 16/-6) Total: 10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: avoid segfault on ${0::0/0~09J}. Closes 15216Denys Vlasenko2023-06-121-4/+35
| | | | | | | | | | | | | | function old new delta evaluate_string 1011 1053 +42 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: fix expansion of space in "a=${a:+$a }c" constructDenys Vlasenko2023-06-125-1/+17
| | | | | | | | | | | | | | function old new delta encode_then_append_var_plusminus 554 552 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * udhcpd: optional BOOTP supportDenys Vlasenko2023-06-126-15/+76
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | from Adam Goldman <adamg@pobox.com> This patch makes udhcpd respond correctly to queries from BOOTP clients. It contains the following changes: The end field, or DHCP_END option, is required in DHCP requests but optional in BOOTP requests. However, we still send an end field in all replies, because some BOOTP clients expect one in replies even if they didn't send one in the request. Requests without a DHCP_MESSAGE_TYPE are recognized as BOOTP requests and handled appropriately, instead of being discarded. We still require an RFC 1048 options field, but we allow it to be empty. Since a BOOTP client will keep using the assigned IP forever, we only send a BOOTP reply if a static lease exists for that client. BOOTP replies shouldn't contain DHCP_* options, so we omit them if there was no DHCP_MESSAGE_TYPE in the request. Options other than DHCP_* options are still sent. The options field of a BOOTP reply must be exactly 64 bytes. If we construct a reply with more than 64 bytes of options, we give up and log an error instead of sending it. udhcp_send_raw_packet already pads the options field to 64 bytes if it is too short. This implementation has been tested against an HP PA-RISC client. function old new delta .rodata 105247 105321 +74 udhcpd_main 1520 1591 +71 send_offer 419 470 +51 init_packet 81 97 +16 udhcp_init_header 75 88 +13 udhcp_scan_options 192 203 +11 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 6/0 up/down: 236/0) Total: 236 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: pass "" rather than NULL as format string in _nomsg functionsDenys Vlasenko2023-06-123-26/+4
| | | | | | | | | | | | | | | | | | | | | | function old new delta bb_perror_nomsg_and_die 9 10 +1 bb_perror_nomsg 9 10 +1 bb_verror_msg 480 469 -11 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 2/-11) Total: -9 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: fix 'read' shell built-in (2)Ron Yorston2023-07-121-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Enabling polling in the previous commit resulted in the following incorrect behaviour: { echo -n te; sleep 3; echo st; } | (read -t 1 x; echo "$x") An empty "$x" is echoed immediately, not after 1 second. { echo -n te; sleep 1; echo st; } | (read -t 3 x; echo "$x") An empty "$x" is echoed immediately. "test" should be echoed after 1 second. This arises because poll(2) from gnulib is unable to handle anonymous pipes properly due do deficiencies in Microsoft Windows. These have been acknowledged and fixed in relation to select(2): https://lists.gnu.org/archive/html/bug-gnulib/2014-06/msg00051.html Apply a similar fix to poll(2). Costs 104-156 bytes.
* | ash: fix 'read' shell built-in (1)Ron Yorston2023-07-121-16/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider this test case: { echo -n te; sleep 3; echo st; } | (read -t 1 x; echo "$x") - bash echoes "te" after 1 second. - Upstream BusyBox echoes an empty "$x" after 1 second. - busybox-w32 echoes an empty "$x" after 3 seconds. The delayed echo in busybox-w32 arises because the 'read' shell built-in omits the code to poll for input. Rearrange the code so that polling takes place. This doesn't address the difference between BusyBox and bash. Costs 48-64 bytes.
* | ash: properly echo console input to 'read' built-inRon Yorston2023-07-124-4/+16
| | | | | | | | | | | | | | The 'read' shell built-in echoed console input to stdout. Echo directly to the console instead. Costs 124-136 bytes.
* | win32: more console input character conversionsRon Yorston2023-07-072-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | Add wrappers for the following input functions with conversions for console input. Applications suitable for testing these changes are appended in brackets. - getchar (xargs) - fgetc (tac) - getline (shuf) - fgets (rev) Costs 112-120 bytes.
* | win32: character conversion for fread(3)Ron Yorston2023-07-062-0/+17
| | | | | | | | | | | | | | Some applets use fread(3): dd and od, for example. Perform the necessary conversion when input is coming from the console. Costs 96-112 bytes.
* | win32: don't crash the console *and* handle CJK inputRon Yorston2023-07-022-20/+21
| | | | | | | | | | | | | | | | | | | | | | | | The previous commit prevented the console from crashing with a UTF8 input code page on Windows 10/11 in the default configuration. But it broke input in CJK code pages. Again. Handle both cases. Costs 36-72 bytes. (GitHub issue #335)
* | win32: revert to previous console input method by defaultRon Yorston2023-07-013-12/+19
| | | | | | | | | | | | | | | | Although the input method used for euro support is no longer required for that reason it does provide a more lightweight workaround for the problem with ReadConsoleInputA and UTF8. Repurpose FEATURE_EURO_INPUT as FEATURE_UTF8_INPUT.
* | win32: code shrink readConsoleInput_utf8Ron Yorston2023-07-012-4/+5
| | | | | | | | | | | | | | Move decision about how to read console input from windows_read_key() to readConsoleInput_utf8(). Saves 48-64 bytes.
* | win32: remove superfluous euro codeRon Yorston2023-07-011-18/+0
| | | | | | | | | | | | | | | | | | Commit ebe80f3e5 (win32: don't assume console CP equals OEM CP) fixed the incorrect character conversions which required special treatment for the euro symbol. The unnecessary code has been removed. Saves 64-80 bytes.
* | Merge pull request #338 from avih/concpRon Yorston2023-07-011-3/+5
|\ \ | | | | | | win32: UTF8 console input: don't spin the CPU
| * | win32: UTF8 console input: don't spin the CPUAvi Halachmi (:avih)2023-06-301-3/+5
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a regression from ec99f03ae which changed Read into Peek in order to keep the record at the console queue. However, it failed to take into account that as a result, if no input is pending, that readConsoleInput_utf8 now returns immediately without waiting for input - unlike ReadConsoleInput. Other than incorrectly returning a FALSE value in such case, it also caused a busy-wait loop of windows_read_key and high CPU usage. Fix that by waiting till there's input before the peek. This should make it just like ReadConsoleInput - which idles till there's input.
* | Merge pull request #337 from avih/concpRon Yorston2023-06-303-2/+174
|\ \ | | | | | | Improve console codepage awareness
| * | win32: UTF8 input: avoid timeout when delivering UTF8 bytesAvi Halachmi (:avih)2023-06-281-6/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When windows_read_key - which is the sole consumer of readConsoleInput_utf8 - is called with a timeout value, it uses WaitForSingleObject to test whether the console has pending input. Previously, readConsoleInput_utf8 consumed the input record before it delivered the UTF8 bytes which are generated from it. It's not an issue with ASCII-7 input - because indeed there are no buffered bytes once it's delivered, and, except for console bugs (when only key-up record exists) also not an issue with 2 or 3 bytes UTF8 codepoints - because these are generated from a single wchar_t input record on key-down, and the key-up event is not yet dequeued while delivering the key-down UTF8 bytes. But with a surrogate pair, which consumes two wchar_t records to realize the UTF8 sequence, we previously consumed the records up to and including the key-up event of the 2nd surrogate half. This could result in a timeout if there are no further records at the queue - eventhough some UTF8 bytes are still buffered/pending. Such timeout can result in the shell aborting - windows_read_key returns -1, which is later interpreted as EOF of the shell input, and quits the shell. Now readConsoleInput_utf8 dequeues an input record only once the last byte which was generated from this record is delivered, which we do using PeekConsoleInputW instead of ReadConsoleInputW. This avoid a timeout as long as there are input bytes to deliver.
| * | win32: the great UTF8 ReadConsoleInput hackAvi Halachmi (:avih)2023-06-283-2/+166
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since commit 597d31ee (EURO_INPUT), ReadConsoleInputA is the default. The main problem with that is that if the console codepage is UTF8, e.g. after "chcp 65001", then typing or pasting can result in a crash of the console itself (the Windows Terminal or cmd.exe window closes). Additionally and regardless of this crash, ReadConsoleInputA is apparently buggy with UTF8 CP also otherwise. For instance, on Windows 7 only ASCII values work - others become '?'. Or sometimes in Windows 10 (cmd.exe console but not Windows terminal) only key-up events arrive for some non-ASCII codepoints (without a prior key-down), and more. So this commit implements readConsoleInput_utf8 which delivers UTF8 Regardless of CP, including of surrogate pairs, and works on win 7/10. Other than fixing the crash and working much better with UTF8 console CP, it also allows a build with the UTF8 manifest to capture correctly arbitrary unicode inputs which are typed or pasted into the console regardless of the console CP. However, it doesn't look OK unless the console CP is set to UTF8 (which we don't do automatically, but the user can chcp 65001), and editing is still lacking due to missing screen-length awareness. To reproduce the crash: start a new console window, 'chcp 65001', run this program (or busybox sh), and paste "ಀ" or "😀" (U+0C80, U+1F600) #include <windows.h> int main() { HANDLE h = GetStdHandle(STD_INPUT_HANDLE); INPUT_RECORD r; DWORD n; while (ReadConsoleInputA(h, &r, 1, &n)) /* NOP */; return 0; }
* | win32: don't assume console CP equals OEM CPAvi Halachmi (:avih)2023-06-285-62/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, console input was converted to the ANSI codepage using OemToChar[Buff], and ANSI to console conversion used CharToOem[Buff]. However, while typically true by default, it's not guaranteed that the console CP is the same as the OEM CP. Now the code uses the console input/output CP as appropriate instead of the OEM CP. It uses full wide-char conversion code, which was previously limited to FEATURE_EURO, and now may be used also otherwise. While at it, the code now bypasses the conversion altogether if the src/dst CPs happen to be identical - which can definitely happen. Other than saving some CPU cycles, this also happens to fix an issue with the UTF8 manifest (in both input and output), because apparently the Oem/Char conversion APIs fail to convert one char at a time (which is not a complete UTF8 codepoint sequence) even if both the OEM and the ANSI CPs are UTF8 (as is the case when using UTF8 manifest). Conversion is also skipped: - if the converted output would be longer than the input; - if the input length is 1 and the input is multi-byte.
* | win32: reduce impact of euro support (2)Ron Yorston2023-06-231-1/+3
| | | | | | | | | | | | | | winansi_OemToCharBuff() needs to call the real OemToCharBuff(), not itself! (GitHub issue #335)
* | win32: reduce impact of euro supportRon Yorston2023-06-231-10/+12
| | | | | | | | | | | | | | | | | | | | The workaround for euro support in busybox-w32 is only intended to work in the 858 code page. Skip the workaround if any other code page is in use. Costs 8-36 bytes. (GitHub issue #335)
* | win32: make support for euro input a separate optionRon Yorston2023-06-224-12/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 93a63809f (win32: add support for the euro currency symbol) made various changes to enable support for the euro symbol. One of these changes allows the euro to be entered from the console even if the current code page doesn't support it. This is probably of limited use: the symbol can be entered but won't be displayed correctly. Move this capability into a separate configuration option, FEATURE_EURO_INPUT, which is disabled by default. Saves 48-64 bytes in the new default case. (GitHub issue #335)
* | pgrep,pkill: remove non-functional optionsRon Yorston2023-06-221-0/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Due to limitations of the process scanning code on Windows some features of pgrep and pkill don't work properly: - display/matching of the full command line (-a/-f) - killing the oldest or newest process (-o/-n) - matching session id (-s) To avoid disappointment or error support for these features has been removed. Saves 408-464 bytes.