aboutsummaryrefslogtreecommitdiff
path: root/modutils/modutils.c (unfollow)
Commit message (Collapse)AuthorFilesLines
2023-07-16date: allow system date to be setRon Yorston3-25/+24
Implement clock_settime(2) and enable the '-s' option to allow the system time to be set. This requires elevated privileges. The code in date.c is now identical to upstream BusyBox. Costs 256-272 bytes.
2023-07-16Update default configurationsRon Yorston4-10/+18
2023-07-12hwclock: add get/set parameters optionAndrej Picej2-5/+100
In kernel 5.16 special ioctls were introduced to get/set RTC parameters. Add option to get/set parameters into busybox version of hwclock. Implementation is similar to the one already used in linux-utils hwclock tool. Example of parameter get use: $ hwclock -g 2 The RTC parameter 0x2 is set to 0x2. $ hwclock --param-get bsm The RTC parameter 0x2 is set to 0x2. Example of parameter set use: $ hwclock -p 2=1 The RTC parameter 0x2 will be set to 0x1. $ hwclock -p bsm=2 The RTC parameter 0x2 will be set to 0x2. function old new delta hwclock_main 298 576 +278 .rodata 105231 105400 +169 packed_usage 34541 34576 +35 static.hwclock_longopts 60 84 +24 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 506/0) Total: 506 bytes Signed-off-by: Andrej Picej <andrej.picej@norik.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-12ash: fix 'read' shell built-in (2)Ron Yorston1-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.
2023-07-12ash: fix 'read' shell built-in (1)Ron Yorston1-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.
2023-07-12ash: properly echo console input to 'read' built-inRon Yorston4-4/+16
The 'read' shell built-in echoed console input to stdout. Echo directly to the console instead. Costs 124-136 bytes.
2023-07-10ntpd: fix a warning on 32-bit arch buildDenys Vlasenko1-2/+2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10i2ctransfer: fix build warningDenys Vlasenko1-1/+1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10Update applet size estimatesDenys Vlasenko265-320/+320
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10ash: tweak comments, no code changesDenys Vlasenko1-6/+7
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10ash: remove "volatile" specifier from suppress_intDenys Vlasenko1-4/+11
function old new delta aliascmd 274 278 +4 signal_handler 81 80 -1 static.redirectsafe 144 141 -3 unwindlocalvars 219 215 -4 trapcmd 333 329 -4 setvar 164 160 -4 setpwd 167 163 -4 setinputfile 216 212 -4 setcmd 76 72 -4 readcmd 221 217 -4 raise_exception 26 22 -4 out2str 37 33 -4 out1str 32 28 -4 freejob 89 85 -4 forkchild 616 612 -4 fg_bgcmd 298 294 -4 expandarg 949 945 -4 evaltree 753 749 -4 evalsubshell 173 169 -4 evalpipe 346 342 -4 evalfun 408 404 -4 cdcmd 699 695 -4 ash_main 1240 1236 -4 __pgetc 589 585 -4 unaliascmd 152 147 -5 unalias 51 46 -5 umaskcmd 253 248 -5 stalloc 97 92 -5 shiftcmd 144 139 -5 setinputstring 73 68 -5 redirect 1068 1063 -5 recordregion 81 76 -5 pushstring 160 155 -5 popstring 120 115 -5 popstackmark 69 64 -5 popredir 123 118 -5 popfile 110 105 -5 out1fmt 45 40 -5 newline_and_flush 39 34 -5 ifsfree 66 61 -5 growstackblock 146 141 -5 freestrings 95 90 -5 fmtstr 59 54 -5 flush_stdout_stderr 23 18 -5 dowait 577 572 -5 delete_cmd_entry 52 47 -5 clearcmdentry 98 93 -5 ash_arith 79 74 -5 argstr 1404 1399 -5 evalcommand 1523 1515 -8 removerecordregions 219 209 -10 mklocal 284 274 -10 find_command 893 883 -10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/52 up/down: 4/-251) Total: -247 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10ash: disable sleep as builtin, closes 15619Denys Vlasenko2-5/+19
Has a few annoying problems: * sleepcmd() -> sleep_main(), the parsing of bad arguments exits the shell. * sleep_for_duration() in sleep_main() has to be interruptible for ^C traps to work, which may be a problem for other users of sleep_for_duration(). * BUT, if sleep_for_duration() is interruptible, then SIGCHLD interrupts it as well (try "/bin/sleep 1 & sleep 10"). * sleep_main() must not allocate anything as ^C in ash longjmp's. (currently, allocations are only on error paths, in message printing). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-09libiproute: fix filtering ip6 route by table idYousong Zhou1-9/+1
Otherwise - "ip -6 route show" shows routes from all tables - "ip -6 route show table 200" shows nothing function old new delta print_route 1962 1941 -21 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-21) Total: -21 bytes Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-08hush: fix a compile failureDenys Vlasenko1-1/+1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-07win32: more console input character conversionsRon Yorston2-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.
2023-07-06win32: character conversion for fread(3)Ron Yorston2-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.
2023-07-04ash: disable check for "good" function name, bash does not check thisDenys Vlasenko3-11/+17
function old new delta .rodata 105304 105261 -43 parse_command 1696 1633 -63 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-106) Total: -106 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-03hush: quote values in "readonly" outputDenys Vlasenko1-4/+11
function old new delta builtin_readonly 61 107 +46 builtin_export 140 145 +5 .rodata 105321 105304 -17 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 51/-17) Total: 34 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-02shell/math: avoid $((3**999999999999999999)) to take yearsDenys Vlasenko1-3/+14
function old new delta arith_apply 991 1030 +39 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-02shell/math: do not accept $((36#@))Denys Vlasenko1-16/+22
function old new delta parse_with_base 170 174 +4 arith_apply 996 991 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-5) Total: -1 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-02win32: don't crash the console *and* handle CJK inputRon Yorston2-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)
2023-07-01win32: revert to previous console input method by defaultRon Yorston3-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.
2023-07-01win32: code shrink readConsoleInput_utf8Ron Yorston2-4/+5
Move decision about how to read console input from windows_read_key() to readConsoleInput_utf8(). Saves 48-64 bytes.
2023-07-01win32: remove superfluous euro codeRon Yorston1-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.
2023-06-30shell/math: code shrinkDenys Vlasenko1-4/+7
function old new delta arith_apply 999 996 -3 evaluate_string 1295 1291 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-7) Total: -7 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-30win32: UTF8 console input: don't spin the CPUAvi Halachmi (:avih)1-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.
2023-06-29shell/math: code shrinkDenys Vlasenko1-11/+13
function old new delta arith_apply 1023 996 -27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-28win32: UTF8 input: avoid timeout when delivering UTF8 bytesAvi Halachmi (:avih)1-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.
2023-06-28win32: the great UTF8 ReadConsoleInput hackAvi Halachmi (:avih)3-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; }
2023-06-28win32: don't assume console CP equals OEM CPAvi Halachmi (:avih)5-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.
2023-06-28shell/math: code shrinkDenys Vlasenko1-8/+10
function old new delta arith_apply 1015 1023 +8 evaluate_string 1309 1295 -14 .rodata 105344 105321 -23 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 8/-37) Total: -29 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-26shell/math: improve commentsDenys Vlasenko1-2/+4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-26shell/math: rename TOK_NUM to TOK_VALUE, improve commentsDenys Vlasenko1-24/+25
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-25shell/math: bash-compatible handling of too large numbersDenys Vlasenko9-44/+118
function old new delta parse_with_base - 170 +170 evaluate_string 1477 1309 -168 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 170/-168) Total: 2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-23win32: reduce impact of euro support (2)Ron Yorston1-1/+3
winansi_OemToCharBuff() needs to call the real OemToCharBuff(), not itself! (GitHub issue #335)
2023-06-23win32: reduce impact of euro supportRon Yorston1-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)
2023-06-22win32: make support for euro input a separate optionRon Yorston4-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)
2023-06-22pgrep,pkill: remove non-functional optionsRon Yorston1-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.
2023-06-21ash: standardise treatment of winxp optionRon Yorston1-13/+41
Although 'winxp' is a shell option it could only be set with '-X' on the command line. Fully implement 'winxp' so it can also be set within the shell by 'set -o winxp' and 'set +o winxp'. '-X' no longer needs to be the first option on the command line. Track which shell variables have been imported from a native Windows environment so only those are affected when 'winxp' is changed. The tracking persists in a subshell but is lost when shell variables are exported to the environment so 'set -/+o winxp' is ineffective in a child shell. Costs 48-52 bytes. (GitHub issue #322)
2023-06-21ash: code shrinkRon Yorston1-28/+20
- There's no need to set USER, LOGNAME, HOME and SHELL as environment variables: making them shell variables is enough. - Use endofname() to detect invalid characters in variable names and take the copy of the invalid variable before it's modified. Saves 48-64 bytes.
2023-06-20win32: include UTF-8 manifestRon Yorston5-1/+21
Include a manifest in the binary to set the process code page to UTF-8. This only has an effect from Windows 10 version 1903. Controlled by the FEATURE_UTF8_MANIFEST config setting, disabled by default.
2023-06-19win32: more applet look-up tweaksRon Yorston1-4/+21
When an applet is overridden by BB_OVERRIDE_APPLETS it should still function in certain cases: busybox applet applet.exe busybox --help applet Arrange for this by adding really_find_applet_by_name() as a static function in libbb/appletlib.c. find_applet_by_name() is implemented using this for external use while really_find_applet_by_name() is used internally in some instances. Adds 32 bytes. (GitHub issue #329)
2023-06-19shell/math: disable debug againDenys Vlasenko1-1/+1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-19shell/math: $((1?)) has one-too-small opstack, fix thisDenys Vlasenko1-1/+2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-19shell/math: fix comments about jammed-together num+num corner casesDenys Vlasenko1-8/+16
function old new delta evaluate_string 1478 1470 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18shell/math: add note on ERANGEDenys Vlasenko1-4/+11
function old new delta evaluate_string 1488 1478 -10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18shell/math: explain why we use separate &endDenys Vlasenko1-1/+1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18shell/math: code shrinkDenys Vlasenko1-2/+5
function old new delta evaluate_string 1498 1491 -7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18shell/math: eliminate redundant endofname()Denys Vlasenko1-8/+8
function old new delta evaluate_string 1486 1498 +12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18shell: typo fix in testsDenys Vlasenko2-2/+2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>