summaryrefslogtreecommitdiff
path: root/win32/process.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* time: WIN32 portRon Yorston2020-04-061-7/+34
| | | | | | | | Port the time applet to WIN32. This requires the implemntation of a replacement for wait3(2). Only elapsed, user and system times are supported, not the memory and i/o statistics reported by GNU time.
* win32: new functions: getpeername(2), mingw_spawn_detach()Ron Yorston2020-04-051-3/+15
| | | | | | | Implement getpeername(2). Add mingw_spawn_detach() to allow the spawned process to detach from the console.
* win32: more improvements to 'c:file' pathsRon Yorston2020-03-291-2/+3
| | | | | | | | Tab-completion of 'c:file' paths was leaking memory and incorrectly included BusyBox applets and shell built-ins. Fix handling of 'c:file' paths used as arguments to spawn functions. Otherwise things like 'timeout 5 c:busybox sleep 99' don't work.
* win32: trim leading and trailing spaces from shebang optionsRon Yorston2019-05-031-0/+4
| | | | | | | | | | | | Commit 97e2c4a05 (win32: changes to treatment of scripts) attempted to use strtok(3) to simplify the parsing of shebang lines. Unfortunately it resulted in leading and trailing whitespace being left in the option string. Fix this by trimming the options before they're returned. Reported-by: Niklas DAHLQUIST <niklas.dahlquist@st.com> Signed-off-by: Ron Yorston <rmy@pobox.com>
* win32: add function to convert slashes to backslashesRon Yorston2019-03-151-5/+2
| | | | | | | | | There are now two places where slashes are converted to backslashes throughout a string so it makes sense to create a function to do this. To avoid confusion rename convert_slashes() to bs_to_slash() and call the new function slash_to_bs().
* win32: drop argument from err_win_to_posix()Ron Yorston2019-03-061-2/+2
|
* win32: make more use of common lazy loading codeRon Yorston2019-02-271-17/+5
|
* win32: don't try to run non-existent scriptRon Yorston2019-02-071-1/+1
| | | | | | In parse_interpreter return an error when the file doesn't exist. The current code tries to run non-existent scripts with a .sh suffix, thus breaking the test ash-misc/exec.tests.
* ps: fix long output when desktop compatibility is disabledRon Yorston2019-01-081-0/+3
| | | | | | | | In desktop mode the state column is disabled and doesn't affect output. When desktop mode is disabled the state column is displayed in long output. Put some fake data in the column to improve the display.
* ps: display interpreted script name in comm columnRon Yorston2019-01-081-1/+2
| | | | | | | | | | | When an interpreted script is being run the comm column in ps should display the name of the script not the name of the interpreter. Use a fake applet pathname to indicate which argument contains the script. This also allows pidof to obtain the pid of a script.
* ps: add support for the args columnRon Yorston2019-01-081-11/+29
| | | | | | | | | Implement read_cmdline() for WIN32 by storing the command line in the same way as the applet name. The applet name is actually used for the comm column which is truncated to COMM_LEN. Using this as the size of the bb_comm array avoids the need to calculate MAX_APPLET_NAME_LEN.
* ps: add user and group columnsRon Yorston2019-01-081-1/+10
|
* win32: special treatment for PATHRon Yorston2018-12-141-20/+0
| | | | | | | | | | | | | | | | | The PATH shell variable is a special case. It can be exported to the environment where it might be interpreted by native applications which assume the separator is ';'. Hence: - require that the separator used in PATH is ';' - enforce this by intercepting calls to setvareq() that set PATH and adjusting its value if necessary. As a result of this the code to parse PATH can be simplified by replacing the hardcoded Unix ':' path separator by the platform- dependent macro PATH_SEP. The MANPATH variable is also required to use ';' as its separator but since it's less likely to be used this isn't enforced.
* win32: special treatment for files with the '.sh' extensionRon Yorston2018-12-091-27/+36
| | | | | | | | | | | | Files with the extension '.sh' are considered to be executable. Those that start with a '#!' line will be run using the specified interpreter. If no '#!' is present the script will be run by the shell. When searching for an executable the '.sh' extension will be tested in the same way as the standard extensions understood by spawnve(). '.sh' takes precedence over the standard extensions.
* win32: use open_read_close() where possibleRon Yorston2018-12-091-6/+2
|
* win32: allow execution of empty batch file to succeedRon Yorston2018-12-081-0/+8
| | | | | | | Microsoft Windows' spawnve returns ERROR_BAD_EXE_FORMAT when passed an empty batch file. Work around this by skipping spawnve and returning success.
* win32: improve execution of batch filesRon Yorston2018-12-071-26/+8
| | | | | | | | | It appears that when a batch file is executed the first argument must contain backslashes if it's a relative path. Absolute paths work either way. In both cases the extension is optional. This allows for a considerable simplification of the special case in spawnveq.
* win32: rework adding of extensions to filenamesRon Yorston2018-12-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | | Previously there was one function to handle adding extensions to executable filenames, add_win32_extension(). Refactor this into three functions: add_win32_extension() appends the suffix to the argument string in-place. The argument must be long enough to cope with this, as is the case in ash where path_advance() adds 4 bytes to each filename for just this reason. alloc_win32_extension() is equivalent to the old add_win32_extension(). It allocates a string to hold the new filename then calls the new add_win32_extension() function. The caller is responsible for managing the returned string. auto_win32_extension() calls alloc_win32_extension() and saves the resulting string using auto_string(). It's used where the new filename is consumed immediately or the actual value isn't needed. Rewrite code to use the most appropriate function. Also reorder some code in find_executable() and find_command().
* ash: fix a couple of test casesRon Yorston2018-12-041-3/+1
| | | | | | | | | | | | | | The ash tests exitcode_EACCES and exitcode_ENOENT both failed. In commit 92dbd3c09 a test was added to tryexec to check that the file being run existed and was executable. The error codes returned by this test were incorrect. The slightly later commit f5783ef14 added a similar test in spawnveq which got the error codes right. Remove the test from tryexec and some superfluous error messages from spawnveq.
* win32: save a few bytes in process scanningRon Yorston2018-11-271-14/+7
| | | | | | Recalculate the system boot time on every pass through the process scanning loop. It's less efficient than storing the value in a static variable but not noticeably so and it saves a few bytes.
* win32: use string_array_len to obtain size of argv arrayRon Yorston2018-10-261-8/+4
| | | | Saves 16 bytes.
* win32: better error message in kill(2)Ron Yorston2018-07-121-0/+2
| | | | | | When the process architecture of busybox-w32 didn't match that of the target process the error reported was 'Function not implemented'. Change this to 'Permission denied'.
* win32: remove some code from procps_scanRon Yorston2018-04-101-3/+0
| | | | | Now that we're calling memset to clear data for each process it's no longer necessary to zero the process times by hand.
* ps: indicate forkshell processes in listingRon Yorston2018-04-051-1/+1
|
* ps: obtain applet names from other BusyBox processesRon Yorston2018-04-041-18/+89
| | | | | | | | | | | | | | | Remove the code which passed applet names to child processes using environment variables. This only allowed ps to display names for its ancestors. Instead attempt to read applet names from the memory of unrelated processes. The Microsoft documentation alone wasn't enough to figure out how to do this. Additional hints from: https://stackoverflow.com/questions/4298331/exe-or-dll-image-base-address https://stackoverflow.com/questions/14467229/get-base-address-of-process
* win32: return correct exit status from waitpidRon Yorston2018-03-291-1/+5
| | | | | | | | | | | The exit status from _cwait wasn't being correctly returned. This resulted, for example, in the exit status of xargs being incorrect. Running this: $ ls | xargs ls in a directory containing filenames with spaces should cause 'ls' to fail and 'xargs' to return an exit status of 123.
* win32: save a few bytesRon Yorston2018-03-291-4/+3
| | | | | | | | In the recently-added code to pass applet names to child processes use local arrays to build the environment variables rather that allocating them every time. mingw_spawn can call mingw_spawn_proc instead of mingw_spawn_1.
* ps: display applet names in process listingRon Yorston2018-03-281-1/+16
| | | | | | | | | | | | | | | | In standalone shell mode all busybox-w32 applets are displayed as 'busybox.exe' in a process listing. I haven't found a satisfactory way to query a running instance of busybox-w32 to determine which applet it's running. Handle a couple of cases: - the process running the process scan knows its own PID and knows which applet it is; - just before invoking applet_main set an environment variable whose name contains the PID and whose value is the current applet name. Children running a process scan will inherit their parent's environment and can therefore match the parent's PID to its applet name.
* ps: clear status for each processRon Yorston2018-03-281-0/+2
| | | | | | | | | The original procps_scan function takes care to clear the status information before handling each process. Do the same for the WIN32 version. This requires moving the snapshot handle to the part of the structure that isn't cleared on each iteration.
* win32: changes to kill(2)Ron Yorston2018-03-271-14/+20
| | | | | | | | | The names of the callbacks to kill processes with a given signal were confusing because they referred to the implementation rather than the intent. Create the new function kill_SIGTERM_by_handle which is more efficient when a handle to the process to be killed is already available.
* win32: small changes to reduce size of binaryRon Yorston2018-03-221-2/+2
| | | | | | | | Reduce the size of the binary by about 32 bytes: - use xzalloc to allocate static buffers so we don't have to initialise them; - avoid duplicated code in spawnveq.
* win32: reduce amount of static dataRon Yorston2018-03-041-28/+34
| | | | | | | It appears that uninitialised static variables are placed in the data section rather than bss, increasing the size of the binary. Rewrite some code to reduce the amount of static data.
* win32: additional improvements to handling of executablesRon Yorston2018-02-281-10/+24
| | | | | | | | | | | | | Consistent processing of file extensions, as described in the previous commit, has been applied to the 'which' applet and the functions find_executable and mingw_spawn_interpreter. In spawnveq check that the file to be executed exists and is executable, and ensure that it won't have any extensions added by spawnve. It's intended that all files passed to spawnve should have their names fully specified. If this isn't the case the tests here will cause errors which will need to be fixed.
* win32: move detection of file formats to stat(2)Ron Yorston2018-02-261-3/+17
| | | | | | | | | | | | | | | | | | | | | Move the code to detect shell scripts and binary executables from mingw_access to a separate function, has_exec_format. Call this function in do_lstat to decide whether to set the executable bits in the file mode. This will slow down stat but has a couple of advantages: - shell scripts are highlighted in ls output - the test applet can use stat(2) to detect executable files The new function is used to handle another corner case in spawnveq: binary executables without the usual .exe extension are only run by spawnve if the file name ends with '.'. Two minor changes: - file_is_win32_executable has been renamed add_win32_extension to clarify what it does - a call to file_is_executable has been removed from find_command in ash as it resulted in unhelpful error messages.
* win32: add support for batch filesRon Yorston2018-02-261-0/+28
| | | | | | | | Support batch files with .bat and .cmd extensions, similar to what's done for .exe and .com. Check extensions in the same order as Windows' spawn function: .com, .exe, .bat, .cmd.
* mingw: clarify that waitpid(-1, ...) is not supportedJohannes Schindelin2017-10-011-1/+1
| | | | | | | | | | | | | | | | | When passing -1 as pid to the waitpid() function, it is supposed to wait for *any* child to exit. That is a bit tough to emulate on Windows given that waitpid() returns only one pid, and if multiple children have exited, subsequent calls to waitpid() should produce all of their pids subsequently. Oh, and we would have to figure out which processes were spawned and remember that list. And then, it would still be possible for the children to exit in the meantime and for *another* process using the pid, as Windows reuses pids very, very quickly. So let's punt and simply state that we do not support that functionality. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Ron Yorston <rmy@pobox.com>
* win32: allow kill to send signal number 0Ron Yorston2017-09-271-0/+15
| | | | | | | According to the man page: If sig is 0, then no signal is sent, but existence and permission checks are still performed
* win32: improvements to implementation of kill(2)Ron Yorston2017-09-271-87/+94
| | | | | | | | | | | | | | | | | Extend the implementation of kill(2) so that: - Sending the TERM signal asks the target process to exit. As on Unix it may not comply. - Sending the KILL signal forcibly terminates the target process. - Using a negative pid treats the target process as a process group leader and signals it and all of its descendants. - Using a pid of zero treats the current process as a process group leader and signals it and all of its descendants. Signed-off-by: Ron Yorston <rmy@pobox.com>
* kill: use gentler method than TerminateProcess()Johannes Schindelin2017-09-271-1/+161
| | | | | | | | | | | | | | | As Git for Windows' source code recently learned, let's also avoid using TerminateProcess() in BusyBox-w32: it does not allow the killed processes' atexit() handlers to run. Instead, jump through a couple of hoops by injecting a remote thread that executes the ExitProcess() function. This allows the atexit() handlers to run, at which point the exit code of the process can already be queried via GetExitCodeProcess(), and appropriate action can be taken, such as killing child processes. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
* ps: add support for CPU and elapsed time columnsRon Yorston2017-09-011-1/+46
| | | | | | | | It may be necessary to run ps as administrator to get information about processes belonging to other users. The code to detect GetTickCount64 at run-time was imported from Git for Windows.
* ps: add parent process id as a supported columnRon Yorston2017-08-311-0/+1
|
* win32: further minor code shrinkRon Yorston2017-08-301-17/+11
| | | | | Remove the check for argv being NULL in spawnveq. It shouldn't ever succeed.
* win32: add a function to find executable on PATHRon Yorston2017-08-301-34/+30
| | | | | | The function find_executable is more generic than needed here: it can search for all matches on PATH whereas we only want the first. Implement find_first_executable to do that.
* win32: changes to treatment of scriptsRon Yorston2017-08-301-58/+36
| | | | | | | | | | | | | | | Simplify how scripts are detected by parse_interpreter. It now: - uses strtok to parse the line buffer; - returns any options as a single string, not an array of separate options; - returns both the full path of the interpreter and its name. When a script is detected the sequence is now: - if the path to the interpreter refers to an executable run that; - else look up the interpreter name as a applet (if so configured) and run the applet found; - else search for the interpreter name on PATH.
* win32: shrink code to detect .exe filesRon Yorston2017-08-301-4/+1
| | | | | | | | Add a function (has_exe_suffix) to replace explicit code to check if a filename ends with '.exe. or '.com'. Also shrink code that checks for '.exe' or '.com' on PATH in shell's find_command function.
* win32/mingw: fix signatures of the *execv*() family of functionsJohannes Schindelin2017-08-231-20/+18
| | | | | | | | | | The function signatures were inherited from Git's source code, but are inconsistent with the declarations in the POSIX standard. This requires quite a few changes in quite a few callers, unfortunately. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Ron Yorston <rmy@pobox.com>
* win32: check for relative path when spawning processRon Yorston2017-07-311-1/+1
| | | | | | When spawning a process the file should be executed directly if its filename contains any path separator, not just if it's an absolute path.
* Allow PREFER_APPLETS and SH_STANDALONE to be set separatelyRon Yorston2017-07-271-6/+12
| | | | | Upstream BusyBox allows PREFER_APPLETS and SH_STANDALONE to be set independently. Allow such configurations to work in busybox-w32.
* win32: simplify spawning appletsRon Yorston2017-07-211-24/+4
| | | | | | | The original WIN32 code used the BUSYBOX_APPLET_NAME environment variable to pass the applet name to the spawned process. This was based on the (apparently) mistaken idea that WIN32 would replace argv[0] with the path to the executable.
* ash: fix use of pid/handle in waitpid_childRon Yorston2016-05-181-1/+13
| | | | | | | | | | Previously spawn was returning a process handle which was treated as a pid in certain circumstances. This resulted in the following failing: find . -type f | sed xargs -n 1 sed -n '1 p' It should output the first line of each file but stopped after the first.