aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* win32: more changes to console/terminal modesRon Yorston2023-03-072-32/+31
| | | | | | | | | | | | | | | | | | Allowing virtual terminal input mode to be set if available proved to be unhelpful: cmd.exe doesn't understand such newfangled stuff (though PowerShell does). The allowed values of BB_TERMINAL_MODE are changed to: 0 Force console mode. 1 Force virtual terminal mode for output. 2 Force virtual terminal mode for input. 3 Force virtual terminal mode for input and output. 4 Support virtual terminal input if enabled. Don't alter mode. 5 Support virtual terminal input if enabled. Set virtual terminal mode for output, if possible. The default is 5.
* win32: virtual terminal input fixesRon Yorston2023-03-065-11/+10
| | | | | | | | | | | - Disable ENABLE_PROCESSED_INPUT in raw mode. Otherwise ^C isn't immediately detected during shell command line editing with virtual terminal input enabled. - Switch read_key()/unix_readkey() to windows_read_key()/read_key(). This allows the shell `read` builtin to use windows_read_key(). Without this change `read` fails when virtual terminal input is enabled.
* win32: add support for virtual terminal inputRon Yorston2023-03-054-32/+34
| | | | | | | | | | | | | | | | Alter certain applets to support virtual terminal input, if enabled. In many places this is achieved by building previously excluded upstream terminal-handling code. The busybox-w32 implementation of termios(3) functions does nothing if virtual terminal input is disabled, so it can be invoked regardless. Some applet-specific terminal-handling code is also required. This affects less, more, vi and command line editing in the shell. (The `more` applet isn't enabled in the default configuration.) This series of patches adds about 1.7KB to the binaries.
* win32: enable Unix read_key() for virtual terminalRon Yorston2023-03-054-5/+11
| | | | | | | Until now busybox-w32 has used a native Windows implementation of read_key(). Build the upstream Unix implementation and use it instead of the native version when virtual terminal input mode is enabled.
* win32: add virtual terminal support to termios(3)Ron Yorston2023-03-053-114/+50
| | | | | | | | | | | | Modify `struct termios` to support Windows virtual terminals. Native console mode flags replace the Unix `c_?flag` structure members. Remove unsupported flags from termios.h. Add implementations of tcgetattr(3)/tcsetattr(3) to get/set console flags when virtual terminal input mode is enabled. Add support for emulating raw mode to get_termios_and_make_raw(). This (and related functions) are exposed but not yet used.
* win32: changes to console mode handlingRon Yorston2023-03-0511-43/+93
| | | | | | | | | | | | | | | | | | | Add the environment variable BB_TERMINAL_MODE as a more general way of controlling console/terminal mode setting. The default remains unchanged: use virtual terminal mode for output if possible but fall back to the console API with emulated ANSI escape sequences. Currently valid settings are: 0 Force use of console mode 1 Force use of virtual terminal mode for output 5 Prefer virtual terminal mode for output, fall back to console Other values won't do anything useful until code elsewhere has been updated. BB_SKIP_ANSI_EMULATION remains available for backwards compatibility. If both variables are set BB_TERMINAL_MODE takes precedence.
* ash: drop workaround for 'read -t 0'Ron Yorston2023-03-051-12/+0
| | | | | | | | | Commit 0eda390d6 (ash: improve handling of 'read -t 0') added code to work around the limitations of our poll(2) implementation. Now that poll(2) has been improved the workaround is unnecessary. Saves 64 bytes.
* nc: switch to using poll(2)Ron Yorston2023-03-031-49/+2
| | | | | | | | | | | | Upstream started using poll(2) rather than select(2) in `nc` some time ago, in commit 5b3b468ec (nc: use poll() instead of select()). Now that poll(2) in busybox-w32 has been updated to work with `nc` switch to using the same code as upstream. As a result of this change nothing in busybox-w32 now uses the select(2) implementation. This reduces the size of the binaries by about 3.4KB.
* win32: revise poll(2) for use in ncRon Yorston2023-03-031-7/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit 5b3b468ec (nc: use poll() instead of select()) changed `nc` to use poll(2) instead of select(2), obviously. In busybox-w32 select(2) had already been hacked to support `nc`. To avoid hacking poll(2) too the upstream change was reverted (c2002eae3). Later `nc` was altered to include the code for both poll and select (3c85cc0c4). Make the changes necessary for poll(2) to work with `nc` on Windows. These are all in the function windows_compute_revents(). Treat a character file that isn't a console as a normal file. Without this `nc 127.0.0.1 1234 </dev/null` doesn't work. Return 0 instead of POLLHUP if GetNumberOfConsoleInputEvents() indicates no events are available. Without this communication between two instances of `nc` which are both using keyboard input isn't as asynchronous as one would like. Only process key press events: key releases are ignored. Without this `nc 127.0.0.1 1234` won't receive anything from the server until the local user presses a key. In the default case, which now includes disk files and character files, detect polling for reads as well as writes. Without this `nc 127.0.0.1 1234 <local_file` doesn't work.
* win32: update poll(2) to match latest gnulib versionRon Yorston2023-03-031-12/+37
|
* win32: try to recover from strange console modeRon Yorston2023-02-211-4/+14
| | | | | | | | | | | | | | | | | | | | | | Execute a remote command on a Windows server using ssh: ~$ ssh localhost 'echo hello' rmy@localhost's password: hello If such a command is run from a busybox-w32 shell the console enters a strange mode when the command completes. Attempt to recover by setting the console back to a default mode. - This doesn't work in a legacy console. - The new mode may not be _exactly_ correct, but it's better than how ssh leaves it. Costs 80-96 bytes. (GitHub issue #288)
* ash: revised CRLF handling for scriptsRon Yorston2023-02-211-1/+64
| | | | | | | | | | | | | | As noted in commit 2d848eba5 (ash: fix CRLF handling), removing CRs from CRLF pairs in preadbuffer() is complicated by the possibility that a CRLF pair might be split across the boundary between buffers. Add a wrapper around calls to nonblock_immune_read() to allow for this. Adds 104-128 bytes. (GitHub issue #280)
* ash: revert changes to handle CRLF in scriptsRon Yorston2023-02-211-34/+4
| | | | | | | Commit 4b894b60a doesn't seem to have worked out. Revert it and the fix in 6e0a6b7e5. We're now back to removing CRs unconditionally from shell scripts.
* ash: really reset ANSI emulation in interactive modeRon Yorston2023-02-201-2/+2
| | | | | | | | | Commit 329f907b2 (ash: only reset ANSI emulation in interactive loop) claimed to move resetting of ANSI emulation up into the main interactive loop. Unfortunately it *just* missed the if-block for interactive mode. Put the call to skip_ansi_emulation() in the right place.
* win32: shuffle skip_ansi_emulation() codeRon Yorston2023-02-191-6/+8
| | | | | Rearrange code to avoid unnecessary tests when the environment variable BB_SKIP_ANSI_EMULATION is set.
* win32: work around problem with ConEmuRon Yorston2023-02-191-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | When running the busybox-w32 shell in ConEmu, if: - ANSI emulation is disabled (which it will be, by default) - a non-builtin command is run there is a window of a few seconds after the command completes during which ConEmu is in XTerm mode. During this time any attempt to use the arrows keys will result in [A[B[C[D appearing. This appears to be a common problem: https://github.com/Maximus5/ConEmu/issues/2316 Try to detect if we're running under ConEmu and alter the default behaviour to prefer ANSI emulation. The user can override this preference by setting BB_SKIP_ANSI_EMULATION if desired. By a quirk of fate, old MSYS2 programs (from 2021) which required a workaround in busybox-w32 (commit 54d2ea4b4) are immune to the problem with ConEmu. (GitHib issue #287)
* win32: only change console mode if necessaryRon Yorston2023-02-191-7/+10
| | | | | In skip_ansi_emulation() only call SetConsoleMode() if the new mode differs from the current mode.
* ash: only reset ANSI emulation in interactive loopRon Yorston2023-02-191-3/+3
| | | | | | | | | | | Commit 54d2ea4b4 (ash: reset ANSI emulation at prompt) worked around a problem with MSYS2 applications. This seems to have been fixed in more recent versions of MSYS2 but there's still value in retaining the workaround for other such cases. However, the call to reset ANSI emulation is probably being made more often than necessary. Move it out of setprompt_if() and into the main shell interactive loop.
* ash: skip CR when detecting end of here documentFRP-4882-g6e0a6b7e5Ron Yorston2023-02-151-1/+1
| | | | | | The change introduced by commit 4b894b60a (ash: change CRLF handling) failed to detect the end of a here document with a CRLF line ending. Add the necessary check.
* win32: skip ACL check in stat(2) when running as rootFRP-4881-ga6c5fd4ebRon Yorston2023-02-131-1/+2
| | | | | | | | | | Commit 88965fe20 (win32: use ACL check to clarify write permission) added code to check if a file had write permission due to an ACL entry. When running with elevated privileges this check is unnecessary as "user" permissions will be sufficient. This also prevents write permission for "other" being set without respecting umask.
* Merge branch 'busybox' into mergeRon Yorston2023-02-136-41/+77
|\
| * hush: restore SIGHUP handling, this time explain why we do what we doDenys Vlasenko2023-01-301-20/+28
| | | | | | | | | | | | | | function old new delta check_and_run_traps 229 278 +49 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: restore tty pgrp on SIGHUPDenys Vlasenko2023-01-301-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | Found one case where SIGHUP does need some handling. ash does not restore tty pgrp when killed by SIGHUP, and this means process which started ash needs to restore it, or it would get backgrounded when trying to use tty. function old new delta check_and_run_traps 214 229 +15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: remove special handling of SIGHUPDenys Vlasenko2023-01-301-18/+20
| | | | | | | | | | | | | | | | | | | | Kernel should do the right thing. (ash and dash do not have special SIGHUP handling.) function old new delta check_and_run_traps 278 214 -64 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: fix SIGWINCH and SIGCHLD (in hush) interrupting line input, closes 15256Denys Vlasenko2023-01-263-10/+20
| | | | | | | | | | | | | | | | | | | | function old new delta record_pending_signo 32 63 +31 lineedit_read_key 231 224 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 31/-7) Total: 24 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * nmeter: increase maximum /proc file size (needed for large machines)Denys Vlasenko2023-01-241-3/+6
| | | | | | | | | | | | | | function old new delta get_file 185 201 +16 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ntpd: correct comment: 2^-20 is ~1 microsecond (confused with 10^-20)Denys Vlasenko2023-01-181-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ntpd: fold d_to_tv() into its only callerDenys Vlasenko2023-01-181-8/+10
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ntpd: correct fixed->float conversions of fractionsDenys Vlasenko2023-01-171-4/+4
| | | | | | | | | | | | | | | | | | | | Need to divide by (1<<32), not by (1<<32)-1. Fraction of 0xffffffff is not 1 whole second. function old new delta .rodata 105264 105268 +4 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ntpd: make NTP client and server Y2036/2038-readyMiroslav Lichvar2023-01-171-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The 32-bit integer part of the NTP timestamp overflows in year 2036, which starts the second NTP era. Modify the timestamp conversion to shift values between 1900-1970 (in the first era) to the second era to enable the client to measure its offset correctly until year 2106 (assuming 64-bit time_t). Also update the conversion from double used when stepping the clock to work with 64-bit time_t after reaching the maximum 32-bit value in 2038 and the server conversion to work correctly in the next NTP era. function old new delta lfp_to_d 51 64 +13 step_time 326 332 +6 .rodata 105260 105264 +4 d_to_lfp 100 86 -14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 23/-14) Total: 9 bytes Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ed: don't use memcpy with overlapping memory regionsSören Tempel2023-01-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The memcpy invocations in the subCommand function, modified by this commit, previously used memcpy with overlapping memory regions. This is undefined behavior. On Alpine Linux, it causes BusyBox ed to crash since we compile BusyBox with -D_FORTIFY_SOURCE=2 and our fortify-headers implementation catches this source of undefined behavior [0]. The issue can only be triggered if the replacement string is the same size or shorter than the old string. Looking at the code, it seems to me that a memmove(3) is what was actually intended here, this commit modifies the code accordingly. [0]: https://gitlab.alpinelinux.org/alpine/aports/-/issues/13504 Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: improve CRLF handling in readRon Yorston2023-02-122-0/+40
| | | | | | | | | | | | | | | | | | | | | | Commit deae0c7bf3 (Skip carriage return in read builtin command) caused all CRs to be removed from input to the read builtin. Only remove CRs that are part of a CRLF pair. Adds 64-80 bytes. (GitHub issue #285)
* | ash: remove CRs from CRLF during field splittingRon Yorston2023-02-103-5/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | Commit e371e46fa0 (shell: add \r to IFS) added '\r' to the IFS variable so field splitting would remove carriage returns. Rather than change IFS, remove CRs preceding LFs in regions being scanned for field splitting before IFS is applied. This prevents free-standing CRs from being removed. Costs 112-120 bytes. (GitHub issue #285)
* | ash: change CRLF handlingRon Yorston2023-02-073-7/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As noted in commit 2d848eba5 (ash: fix CRLF handling) all CRs are removed when scripts are read. Allow an alternative approach (configurable at build-time, enabled by default): - Do not strip CRs from input. - Treat CR as similar to space or tab in base syntax mode. - Adjust pgetc_eatbnl() to handle backslash-CRLF in the same way as backslash-LF. With these changes scripts containing CRLF line endings are more likely to work. Adds 48-56 bytes. (GitHub issue #285)
* | vi: introduce 'binary' option and '-b' flagRon Yorston2023-02-061-11/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | vim has the 'binary' option and corresponding '-b' command line flag. These allow files to be opened in binary mode, ignoring the 'fileformats' setting and treating all files as of type 'unix'. Add these to busybox-w32 vi so it's possible to edit files which have a mixture of different line endings. Costs 80-112 bytes. (GitHub issue #285)
* | vi: allow change of 'fileformat' optionRon Yorston2023-02-061-12/+23
| | | | | | | | | | | | | | | | | | For some reason the 'fileformat' option was made read-only when it was introduced in commit 420afde92e (vi: add fileformats option). I think I'd read some vim documentation that made it seem more complicated than it really is. Costs 48 bytes.
* | Fix POSIX buildRon Yorston2023-02-042-2/+2
| | | | | | | | | | A misplaced #endif in ash and the wrong sense of a test in parse_config.c broke the POSIX build.
* | make: strip leading whitespace in shell assignmentRon Yorston2023-02-011-11/+28
| | | | | | | | | | | | | | | | | | | | | | | | Assignment of shell output to a macro ('!=') was originally a non-POSIX extension. It later became a POSIX 202X feature. However, the implementation failed to include the additional POSIX requirement that leading whitespace is removed from the shell output. Neither GNU make nor bmake strip leading whitespace. Implement this behaviour as a non-POSIX extension.
* | ash: fix CRLF handlingRon Yorston2023-01-311-2/+7
| | | | | | | | | | | | | | | | Only remove CRs that are part of a CRLF pair in the output of command substitution. It would be nice to do the same in preadbuffer() but there's a small chance the CRLF might be split between buffers.
* | libbb: fix CRLF handlingRon Yorston2023-01-312-4/+14
| | | | | | | | | | | | | | | | | | | | Ensure a trailing CR is only removed if it precedes a LF. The two cases at issue are intended to read complete lines and remove the line terminator. In the normal case a trailing LF will be present so removing the CR unconditionally worked. However, if the last line of a file was missing its LF or if a NUL was detected (in the case of xmalloc_fgetline()) the CR might have been removed without justification.
* | ash,make: fix CRLF handlingRon Yorston2023-01-302-2/+9
| | | | | | | | | | | | | | Fix remove_cr() so it only removes CRs which are part of a CRLF pair, not every CR. Add a test case for the shell.
* | awk: CRLF handlingRon Yorston2023-01-302-19/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previous efforts at handling DOS-style line endings in awk have included commits ee7e00dc5 and 1a3717342. The use of remove_cr() is unwise: - It's overzealous, removing all CRs, not just those in CRLF pairs. - Even if that were fixed awk reads input in chunks. There's a remote chance a CRLF might appear at a chunk boundary and be missed. remove_cr() will be fixed separately. In awk treat all data input as being in text mode. Skipping CRs in skip_spaces() is also flawed. Instead read scripts in text mode. Add a couple of test cases. One of these (awk backslash+CRLF eaten with no trace) fails without this patch.
* | diff: improve --binary implementationRon Yorston2023-01-291-13/+7
| | | | | | | | | | | | | | | | | | | | | | Commit 82f0d19b1 (diff: implement --binary flag) was both over- complicated and incorrect. If stdin was seekable it was left in binary mode even if the --binary flag wasn't supplied. Always open files in binary mode. Only switch to text mode at the last moment, if necessary. Saves 48 bytes.
* | win32: provide a default value for HOMERon Yorston2023-01-292-9/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The busybox-w32 shell initialises HOME when it starts. However, if applets are run outside the environment provided by the shell they may find HOME is unset. This caused a problem for 'vi' as it was unable to locate its .exrc. If HOME isn't available in the environment make getenv(3) provide a sensible default value. The shell must use the *real* getenv(3) when determining if HOME is already set. Also, unrelated to the above, the shell shouldn't treat failure of getpwuid(3) as a fatal error. Costs 72-80 bytes.
* | diff: implement --binary flagRon Yorston2023-01-271-0/+25
| | | | | | | | | | | | | | | | | | | | | | On Windows GNU diff uses text mode for input and output. It also has the '--binary' flag to use binary mode instead. On Unix binary mode is the default and the flag does nothing. Alter diff to use text mode by default for input (though not output, let's not go overboard). Add the '--binary' flag to override this. Costs 96-160 bytes.
* | win32: another stat(2) + access time fixRon Yorston2023-01-261-1/+1
| | | | | | | | | | | | | | | | Use FILE_SHARE_READ when opening a file to check if it's an executable. Without that other processes running in parallel might be unable to access the file. (GitHub issue #284)
* | make: enable pdpmake alias in default configurationRon Yorston2023-01-242-2/+2
| | | | | | | | | | This allows additional flexibility when another 'make' program is present.
* | make: allow building as pdpmake onlyRon Yorston2023-01-242-0/+2
| | | | | | | | | | | | | | | | | | Commit f261d2d27 (make: make + sh configuration) added 'pdpmake' as an alias for 'make'. It should have been possible to include 'pdpmake' in a build without also including 'make'. Adjust the build configuration so this works as intended.
* | win32: only count subdirectories if necessaryRon Yorston2023-01-234-3/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 7fb95a2a5 (win32: try to get link count for directories) allowed stat(2) to report accurate values of st_nlink for directories. There are only a couple of places in busybox-w32 where these values are required. Disable counting of subdirectories by default and only enable it when necessary. Microsoft kindly provide directories to test edge cases like this: C:/Windows/WinSxS (contains many subdirectories) C:/Windows/WinSxS/Manifests (contains many files) Adds 84-112 bytes.
* | win32: limit setting of errno when lazy loading failsRon Yorston2023-01-221-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | The function get_proc_addr() facilitates dynamic loading of functions from DLLs. In the event of failure it set errno to ENOSYS. This is sometimes useful, such as in the implementations of link(2), symlink(2) and realpath(3). However, many other uses of lazy loading can recover from failure or simply don't care. In these cases setting errno is unnecessary and may be counterproductive. (GitHub issue #283)