aboutsummaryrefslogtreecommitdiff
path: root/win32 (follow)
Commit message (Collapse)AuthorAgeFilesLines
* win32: retry when command needs elevated privilegesRon Yorston2025-02-032-0/+64
| | | | | | | | | | | | | | Some installer programs have an entry in their manifest to indicate that they need elevated privileges. The shell in busybox-w32 was unable to run such programs. When a program fails to run with ERROR_ELEVATION_REQUIRED, try again using ShellExecuteEx() with the 'runas' verb to give it elevated privileges. Adds 272-288 bytes. (GitHub issue #481)
* win32: fix compilation with FEATURE_SH_NOFORK disabledRon Yorston2024-12-311-0/+2
| | | | | Compiling with FEATURE_SH_NOFORK disabled resulted in an error and a warning. Fixing these doesn't change the default build.
* win32: code shrink quote_arg()Ron Yorston2024-12-301-24/+20
| | | | | | | | Alter quote_arg() to perform a single pass over the string in the case where no change is required. Based on a proposal by @avih in GitHub PR #317. Saves 16 bytes.
* ash: strip trailing slash from directory if necessaryRon Yorston2024-12-291-0/+5
| | | | | | | | | | | The previous commit removed trailing dots and spaces from the last component of a pathname when changing directory. If the result has a trailing slash remove that too. But not if it's a drive root, to avoid 'cd C:/' showing a current directory of 'C:'. Adds 48 bytes. (GitHub issue #478)
* ash: match behaviour of cmd.exe in cd builtinRon Yorston2024-11-191-0/+13
| | | | | | | | | | | | | | The Windows API strips trailing dots and spaces from the last component of a path. cmd.exe handles this quirk when changing directory by adjusting its idea of the current directory to match reality. The shell in busybox-w32 didn't do this, leading to some confusion. Fix the shell's cd builtin so it works more like cmd.exe. Adds 64-80 bytes. (GitHub issue #478)
* win32: update poll(2) to match latest gnulib versionRon Yorston2024-10-251-5/+6
|
* win32: workaround for pipe writability in poll(2)Ron Yorston2024-10-251-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | A CGI script was found to hang when a large amount of data was posted: #!/bin/sh echo "Content-type: text/plain;" echo if [ "$REQUEST_METHOD" = "POST" ]; then dd of=my.dat bs=1 count=${CONTENT_LENGTH} echo -n "success." else echo -n "error!" fi This appears to be due to problems determining whether a pipe is writable on Windows. The Git for Windows project has a workaround in their copy of GNUlib's poll(2) implementation. The details are in the commit message: https://github.com/git-for-windows/git/commit/94f4d01932279c419844aa708bec31a26056bc6b Apply the same workaround here. Saves 220-272 bytes. (GitHub issue #468)
* win32: close exec'ing process if possibleRon Yorston2024-10-131-0/+3
| | | | | | | | | If a process performing an exec is an orphan there's no reason for it to wait for its child's exit code. Let it exit immediately. Adds 16 bytes. (GitHub issue #461)
* kill: fix regression in 'kill -9'Ron Yorston2024-10-121-6/+7
| | | | | | | | | | | | | | 'kill -9' was found to fail with an 'Invalid argument' error. This is a regression introduced by commit 569de936a (kill: killing a zombie process should fail). Use the correct argument to OpenProcess() for SIGKILL so it can query the exit code of the target process. Adds 16 bytes. (GitHub issue #465)
* win32: fix problem interrupting shell loopRon Yorston2024-10-111-11/+13
| | | | | | | | | | | | | | | | | It proved to be almost impossible to interrupt a loop like: while true; do sleep 1; done where 'sleep' was an external program, not an applet. The issue was introduced by commit 0475b7a64 (win32: convert exit codes). This passed a POSIX error code to the exit() in wait_for_child() so a parent was unable to detect when its child was interrupted. Pass the Windows exit code to exit() instead. Work around the changes introduced by commit 790e377273 (win32: revert 'don't set error mode'). Adds 16-32 bytes.
* win32: fix regression in chdir(2)Ron Yorston2024-10-101-7/+9
| | | | | | | | | | | | | When mingw_chdir() was introduced it canonicalised its argument (585d17d26). This had the side effect of making its case match that of the directory as stored on disk. Subsequent changes retained that behaviour for symlinks but not otherwise (69d328022, b99032390). This was noted to affect the appearance of the directory specified by the (undocumented) 'sh -d' option. Fix the case of non-symlink directories too. Adds 16-32 bytes.
* id: code shrinkRon Yorston2024-10-091-0/+2
| | | | | | | | The bogus user/group ids we use on Windows are very limited. Make these limitations explicit in the 'id' applet. Saves 464 bytes.
* Merge branch 'busybox' into mergeRon Yorston2024-10-081-1/+1
|
* win32: drop workaround for Wine console bufferRon Yorston2024-09-271-7/+0
| | | | | | | | | | | | | | Commit 1ade2225d2 (winansi: allow alternative screen buffer to be disabled) added a workaround for the broken alternative screen buffer in the Wine console. The problem has been fixed in Wine for well over a year: https://bugs.winehq.org/show_bug.cgi?id=54287 Remove the workaround. Saves 80-96 bytes.
* ash: optimise running of scriptsRon Yorston2024-08-191-8/+1
| | | | | | | | | | | | | | | | | | | | | | The BusyBox shell detects certain cases where forking a command is unnecessary (last command in a script or subshell, for example) and calls execve(2) instead. This doesn't help in the Windows port because execve(2) is implemented by creating a process. There is one case where it is possible to apply this optimisation: if the command is a script and the script interpreter is an applet. - Have evalcommand() pass a flag to indicate this situation to shellexec(). Also, allocate two spare elements before the start of the argv array. - If the flag is TRUE shellexec() passes the shell's PATH variable down to tryexec() so it can perform a test for applet override. - If tryexec() finds that all the necessary conditions apply it can run a script by directly invoking the interpreter's main(). Adds 192-224 bytes.
* win32: code shrinkRon Yorston2024-08-163-16/+16
| | | | | Add the FAST_FUNC qualifier to several Windows-specific functions. This has no effect in 64-bit builds but saves 336 bytes for 32-bit.
* win32: fix strftime(3) '%s' formatRon Yorston2024-08-141-1/+1
| | | | | | | | | | | | The '%s' format of our strftime(3) wrapper (display number of seconds since the Unix epoch) returned incorrect results on 64-bit systems for times more than 2^31 seconds after the epoch. Use the correct format. Adds 16 bytes. (GitHub issue #446)
* win32: fix another problem with stat(2)Ron Yorston2024-08-091-2/+3
| | | | | | | | | | | If we can't open a file to preserve its access time (perhaps because it doesn't belong to us) just try again without bothering about the access time. I thought I'd already done that, but that must have been in an alternative reality. Adds 16 bytes. (GitHub issue #443)
* su: detect inability to raise privilegeRon Yorston2024-08-031-22/+22
| | | | | | | | | | | | When privilege has been dropped by the 'drop' applet, the 'su' applet is unable to raise it again because ShellExecuteEx() thinks it unnecessary. Detect this situation, report an error and return exit code 2. Costs 72-112 bytes. (GitHub issue #437)
* win32: consolidate executable handling in popen.cRon Yorston2024-07-201-31/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | Commit f444dc586 (win32: only search PATH for compressor) made mingw_fork_compressor() perform a PATH lookup for the xz and lzma compression programs. This avoided relying on CreateProcess() to perform the search. Other callers of the pipe creation code should also avoid reliance on CreateProcess's executable search: - Move the applet test and PATH lookup into mingw_popen_internal(). The first argument to CreateProcess() will always be a path to an executable. - mingw_fork_compressor() uses the new "w+" mode to indicate that xz and lzma compressors should be found on PATH. - mingw_popen() no longer needs to check for an applet itself, as that's now handled in mingw_popen_internal(). - spawn_ssl_client() in 'wget' can rely on the popen code to look up the 'ssl_client' applet. - Remove unnecessary argument checks in mingw_popen_internal(). Adds 0-24 bytes.
* win32: code shrink popen(3)Ron Yorston2024-07-191-40/+13
| | | | | | | | | | | - Replace the half-baked code to quote the command passed to popen(3) with a call to quote_arg(). - Where the command to be run is a non-overridden applet in the current binary pass the path to the binary to CreateProcess() instead of adding '--busybox' to the command. Saves 128-136 bytes.
* win32: code shrink mingw_spawn_interpreter()Ron Yorston2024-07-141-11/+8
| | | | | | | Rewrite mingw_spawn_interpreter() to remove a duplicated recursive call. Saves 32-48 bytes.
* ash: read profile script relative to binaryRon Yorston2024-07-081-0/+8
| | | | | | | As well as trying to read '/etc/profile' also look for the script 'etc/profile' relative to the location of the running binary. Adds 64-96 bytes.
* win32: code shrink system drive handling (2)Ron Yorston2024-07-071-1/+1
| | | | | | Now that get_system_drive() no longer returns a NULL pointer on error chdir_system_drive() needs to check for an empty string instead.
* win32: code shrink system drive handlingRon Yorston2024-07-071-27/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | A previous commit (e3bfe3695) revised the use of getsysdir() to obtain the system directory, and hence the system drive. See the commit message for the history to that point. Further improvements are possible: - Remove getsysdir() and push the calls to GetSystemDirectory() down into get_system_drive() and get_proc_addr(). - Check the return value of GetSystemDirectory(). It's unlikely to fail, but better safe than sorry. - Instead of making all callers of get_system_drive() check for a NULL return value always return a non-NULL pointer. If the drive can't be found an empty string is returned instead (which is what the callers were using anyway). - The function need_system_drive() was only used in one place (in httpd). Move the code there and remove the function. - Use concat_path_file() where possible. Saves 76-144 bytes.
* win32: don't allow BB_TERMINAL_MODE=6Ron Yorston2024-06-281-1/+1
| | | | | | | | The BB_TERMINAL_MODE variable is only documented to work for values between 0 and 5. Due to an oversight it also accepted the value 6. Like other unsupported values 6 is now replaced with the default value configured at build time.
* win32: add definition for old mingw-w64FRP-5398-g89ae34445Ron Yorston2024-06-251-0/+4
|
* win32: code shrink exit_code_to_wait_status_cmd()Ron Yorston2024-06-241-4/+4
| | | | Saves 16 bytes.
* win32: code shrink BB_CRITICAL_ERROR_DIALOGSRon Yorston2024-06-231-1/+2
| | | | | | Rewrite the test for the value of BB_CRITICAL_ERROR_DIALOGS. Saves 16-48 bytes.
* win32: only access mode argument of open(2) if requiredRon Yorston2024-06-221-3/+5
| | | | | | | | | The wrapper function 'mingw_open()' should only read the optional third argument if the 'O_CREAT' flag bit is set. Adds 16 bytes. (GitHub issue #425)
* win32: add env var to control error dialogsRon Yorston2024-06-221-0/+6
| | | | | | | | | | | | | | | If the environment variable BB_CRITICAL_ERROR_DIALOGS is set to 1 critical error dialogs are enabled. If unset or set to any other value they aren't. In either case the error messages introduced by commit 790e37727 (win32: revert 'don't set error mode') are issued. The shell exports BB_CRITICAL_ERROR_DIALOGS to the environment immediately on any change so the setting takes effect at once. Adds 104-160 bytes. (GitHub issue #423)
* win32: revert 'don't set error mode'Ron Yorston2024-06-221-29/+64
| | | | | | | | | | | | | | | | | | | | | | | | Commit eb376b5d1 (win32: don't set error mode) removed a call to SetErrorMode(SEM_FAILCRITICALERRORS). But the documentation says: Best practice is that all applications call the process-wide SetErrorMode function with a parameter of SEM_FAILCRITICALERRORS at startup. This is to prevent error mode dialogs from hanging the application. Doing this prevents the system from displaying useful information, though. The application should attempt to tell the user what went wrong. Reinstate the call to SetErrorMode() and try to provide an error message, at least for the situation mentioned in issue #423 and other similar cases. Adds 360-368 bytes. (GitHub issue #423)
* ash: allow HISTFILE=/dev/null to work as intendedRon Yorston2024-06-191-3/+8
| | | | | | | | | | | | | | | It was noted that setting HISTFILE=/dev/null in upstream BusyBox prevented shell history from being saved to a history file. This failed in busybox-w32 with an error from lseek(2). The lseek(2) wrapper was rather conservative in the file types it accepted. Allowing FILE_TYPE_CHAR makes it possible to seek on /dev/null, thus avoiding the issue with HISTFILE. In addition, the wrapper for open(2) now converts the Unix-style mode argument to Windows-style. (GitHub issue #425)
* win32: code shrink APE detection; avoid UBRon Yorston2024-06-191-3/+7
| | | | | | | | | | | | | Detecting Actually Portable Executable binaries used a longer signature than seems necessary. Six characters should be enough for anyone. When right shifting a byte by 24 bits, cast it to unsigned to avoid undefined behaviour. Saves 24-32 bytes. (GitHub issue #424)
* win32: detect Actually Portable Executable binariesRon Yorston2024-06-161-15/+23
| | | | | | | | | Check for the signature of Actually Portable Executable binaries and treat them as executable. Adds 40-64 bytes. (GitHub issue #424)
* win32: allow for trailing separator in PATHRon Yorston2024-06-141-0/+26
| | | | | | | | | | | | | | | | | | | In recent versions of Windows the PATH environment variable has a trailing semicolon. This is insignificant to Windows because it's ignored. busybox-w32 conforms to the POSIX interpretation of PATH which treats an empty path element as denoting the current directory. As result, on these versions of Windows executables may by default be run from the current directory, contrary to usual Unix practice. Attempt to detect and remove the trailing semicolon on applet start up. If the user insists, they can add a trailing semicolon to the shell variable PATH and it will be respected in the conventional manner. Adds 88-112 bytes. (GitHub issue #422)
* win32: some changes to kill(2)Ron Yorston2024-05-181-26/+27
| | | | | | | | Merge the kill() and kill_pids() functions. Allocate an array for the PIDs rather than use a hardcoded one. Adds 32 bytes to the 32-bit build, none to 64-bit.
* win32: implement getppid(2)Ron Yorston2024-05-161-9/+24
| | | | | | | | | | | | | | busybox-w32 had a dummy implementation of getppid(2) which always returned 1. Provide a more realistic version. The effect is limited: - The PPID shell variable should report a sensible value. - The special value to omit the parent PID 'pidof -o %PPID' should work. Costs 48 bytes.
* win32: ensure PIDs are read early in procps_scan()Ron Yorston2024-05-161-10/+15
| | | | | | | | | | | Recent changes to allow orphaned processes to report a parent PID of 1 rely on the assumption that Process32First/Process32Next return parents before children. This isn't guaranteed by the API. Obtain all known PIDs on the first call to procps_scan() so that dead parents can be detected reliably. Costs 48 bytes.
* win32: code shrinkRon Yorston2024-05-151-2/+0
| | | | Saves 16-32 bytes
* ps: report unknown parent PID as 1Ron Yorston2024-05-141-2/+20
| | | | | | | | | | If the parent PID doesn't appear in the process table, report it as 1. This more closely matches how orphaned children are handled on UNIX. Adds 96-128 bytes. (GitHub issue #416)
* kill: killing a zombie process should failRon Yorston2024-05-141-106/+90
| | | | | | | | | | | | | | | | | | | | | | | A process which has exited may still have its process handle held open by its children. Such a process doesn't appear in the process table. It is thus similar to a zombie process in UNIX. Using kill(1) to interact with such a process was seen to succeed, contrary to expectation. The code for "ordinary" signals in kill(2) did check if the process was still active but didn't treat an attempt to kill an inactive process as an error. Furthermore, sending SIGKILL or the fake signal 0 to a process didn't even check if the process was still active. Rearrange the implementation of kill(2) so that an attempt to signal an inactive process is treated as an error. This also consolidates handling of SIGKILL and signal 0 with "ordinary" signals. Saves 96 bytes. (GitHub issue #416)
* win32: try to avoid downloading offline filesRon Yorston2024-04-301-2/+5
| | | | | | | | It's possible that files in remote storage may not be available locally. Avoid downloading such files just to obtain file attributes. (GitHub issue #414)
* win32: adjust handling of executable extensionsRon Yorston2024-04-221-8/+12
| | | | | | | | | | | | | | | Mixing Windows and Unix-style filename extensions was causing problems. Tweak how extensions are handled to try and improve matters: - Consistently check whether the unaltered filename is an executable before trying adding extensions. - Check .exe and .com before .sh. Saves up to 16 bytes. (GitHub issue #405)
* win32: make stat(2) fail for /dev/zero, /dev/urandomRon Yorston2024-04-201-1/+2
| | | | | | | | | | /dev/zero and /dev/urandom are only available internally and as arguments to 'dd'. Since users can't otherwise access them they shouldn't be treated as existing by stat(2). With this change stat(1) and test(1) will deny their existence. (GitHub issue #282)
* ash: add title built-inRon Yorston2024-04-091-2/+6
| | | | | | | | | | | | | | Implement a 'title' built-in for ash. It's very simple-minded, performs almost no error checking and is completely non-portable. - With no arguments it prints the current console title. - If arguments are provided the *first only* is set as the console title. Costs 88-116 bytes. (GitHub issue #401)
* win32: ascii-optimize winansi_fputc, winansi_putcharAvi Halachmi (:avih)2024-04-061-8/+2
| | | | | | | | | | | | | | | | | | | | | | Other winansi IO wrappers, like winansi_fputs, optimize by calling the libc API directly if no special handling is needed, e.g. if the input is fully ASCII and without escape sequences - without converting the output codepage or interpreting escapes. Now the fputc and putchar wrappers do that as well. And as a simplification, putchar is now also a wrapper of fputc. Other than possibly minor speedup, this can also help buffered streams remain buffered, because the codepage conversion using writeCon_utf8 is unbuffered and first flushes the stream, so by avoiding the conversion and calling the libc API directly, we also avoid premature flush of a buffered stream. This did happen, as "time" is buffered since commit 54dbf0fa5, so previously it was flushed early when using putchar, while now it remains buffered by default (but can still be flushed early if the -f format string contains non-ASCII chars).
* win32: UTF8_OUTPUT: flush stream before conversionAvi Halachmi (:avih)2024-04-061-1/+3
| | | | | | | | | | | | | | | | | | | | writeCon_utf8 is unbuffered - it writes directly using WriteConsoleW, but some winansi libc IO wrappers, like fputs, use the libc API directly if the content doesn't need any special handling (e.g. all ASCII and no escape sequences), and so if the stream is buffered, and if only some parts of it go through writeCon_utf8, then we can get wrong output order due to some parts being buffered and some not. Case in point, the recent commit 54dbf0fa5 made the output of "time" buffered, and so if only parts of it go through writeCon_utf8, then we get bad output order. This did actually happen, because not all the winasi wrappers have this ASCII-only optimization (e.g. winansi_putchar), and "time" did end up with wrong output order. Even if all the winansi wrappers were ASCII-optimized, "time" could still have unicode output, e.g. with -f. Fix it by flushing the stream before converting using writeCon_utf8.
* win32: improvements to realpath(3)Ron Yorston2024-03-091-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | The previous commit unnecessarily duplicated the path returned from resolve_symlinks(), resulting in a memory leak. Thanks to avih for spotting this. Even if we can't canonicalise the path in resolve_symlinks() we can at least return the result of resolving the trailing symlink. Moreover, this can be done both when the necessary API is missing and when the filesystem doesn't support it. Not perfect, but better than nothing, and there's no cost. This change gets rid of a handful of realpath-related test failures on ReactOS and Windows XP. Some background: Commit 8ebe81483 returned the raw path when the required API was missing. This was reverted in commit f902184fa because it caused an infinite loop (GitHub issue #204). Commit 31467ddfc fixed the cause of the loop, which is why it's now safe to reintroduce a fallback return. (GitHub commit #389)
* win32: let realpath(3) work on flaky filesystemsRon Yorston2024-03-081-0/+3
| | | | | | | | | | | | Some filesystems don't support the feature required to resolve symlinks for realpath(3). In such cases just carry on without resolving symlinks. This is a trade-off between correctness and convenience. Adds 16 bytes. (GitHub issue #389)