aboutsummaryrefslogtreecommitdiff
path: root/libbb/executable.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* win32: more efficient tests for executablesRon Yorston2021-07-261-2/+8
| | | | | | | | | | | | | | | | file_is_executable() calls access(2) and stat(2); in this case our WIN32 implementation also calls stat(2). Avoid this unnecessary duplication by copying the required test from the WIN32 access(2). In find_executable() it's possible to avoid calling file_is_executable() if add_win32_extension() returns TRUE as the latter will already have verified that the file is executable. Replace a call to file_is_executable() in the tab completion code with the equivalent tests, avoiding (up to) two calls to stat(2). These changes don't affect the size of the binary and should be faster.
* libbb: reduce changes to find_executable()Ron Yorston2021-01-231-8/+7
| | | | | | | | | Reduce the divergence from upstream in find_executable(): - Reset the path separator after the call to file_is_executable(). Doing it before isn't wrong, but it's different. - Move the declaration 'char *w;' into a platform-specific block.
* Merge branch 'busybox' into mergeRon Yorston2021-01-141-9/+0
|\
| * libbb: rename run_shell() to exec_shell()Denys Vlasenko2020-12-021-9/+0
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | win32: code shrink Unix-style path handlingRon Yorston2020-08-231-8/+4
| | | | | | | | | | | | | | | | Replace auto_add_system_drive() with alloc_system_drive() which leaves space for a possible filename extension. This makes it possible to drop alloc_win32_extension() and auto_win32_extension(). Saves 144 bytes.
* | win32: handle Unix-style absolute paths for executablesRon Yorston2020-08-131-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As noted in commit 548ec7045 (win32: interpret absolute paths as relative to %SYSTEMDRIVE%) a path starting with a '/' in the Unix world is treated as relative to the current drive by Windows. To avoid ambiguity that commit considered certain such paths to be relative to %SYSTEMDRIVE%. Extend this to paths representing executables. Add the functions need_system_drive() and auto_add_system_drive() to detect the need for a system drive prefix and to add it if necessary. Use these functions in: - the 'which' applet - the find_executable() function - tab-completion code - PATH look-up, shellexec(), describe_command() and find_command() in ash - parse_interpreter() and mingw_spawn_1() With these changes executable paths starting with a slash are handled consistently, whatever the current drive.
* | win32: special treatment for PATHRon Yorston2018-12-141-11/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: rework adding of extensions to filenamesRon Yorston2018-12-061-21/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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().
* | win32: additional improvements to handling of executablesRon Yorston2018-02-281-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Merge branch 'busybox' into mergeRon Yorston2018-02-131-8/+23
|\|
| * which: fix TODO with NOFORK+malloc_failure misbehavingDenys Vlasenko2018-01-121-8/+10
| | | | | | | | | | | | | | | | | | | | | | function old new delta find_executable 86 104 +18 which_main 202 194 -8 executable_exists 66 51 -15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 18/-23) Total: -5 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2017-11-031-1/+0
|\|
| * whitespace and comment format fixes, no code changesDenys Vlasenko2017-10-051-1/+0
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2016-11-101-1/+1
|\|
| * su: expand help; simplify passing of -c CMD to run_shell()Denys Vlasenko2016-11-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Also, added a comment about bug 9401 (TIOCSTI input injection). function old new delta packed_usage 30909 30932 +23 su_main 470 487 +17 sulogin_main 260 258 -2 run_applet_and_exit 681 678 -3 run_shell 166 126 -40 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2016-04-041-1/+10
|\|
| * nsenter,unshare: share common code; fix a bug of not closing all fdsDenys Vlasenko2016-04-021-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | function old new delta xvfork_parent_waits_and_exits - 64 +64 exec_prog_or_SHELL - 39 +39 unshare_main 873 810 -63 nsenter_main 663 596 -67 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 0/2 up/down: 106/-130) Total: -27 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | MinGW: rename execable -> executableRon Yorston2014-05-061-1/+1
| |
* | Merge branch 'busybox' into mergeRon Yorston2014-05-061-1/+15
|/ | | | | | | Conflicts: debianutils/which.c editors/vi.c libbb/executable.c
* libbb: rename execable -> executable. No code changesDenys Vlasenko2014-05-021-0/+92
English speakers complained that it sounded awfully broken. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>