aboutsummaryrefslogtreecommitdiff
path: root/libbb/appletlib.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'busybox' into mergeRon Yorston2024-10-081-3/+3
|\
* | Merge branch 'busybox' into mergeRon Yorston2024-09-281-34/+36
|\|
| * libbb: send usage messages to correct streamRon Yorston2024-09-271-13/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | POSIX generally requires normal output to go to stdout and diagnostic (i.e. error) output to go to stderr. When usage messages for BusyBox applets are specifically requested by the user (e.g. 'find --help') they should go to stdout; when they're emitted due to an error they should go to stderr. function old new delta bb_show_usage 148 146 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-2) Total: -2 bytes Signed-off-by: Avi Halachmi <avihpit@yahoo.com> Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: use full_write1_str() to shrink busybox_main()Ron Yorston2024-09-271-13/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are two calls to dup2() in busybox_main(). These were introduced to coerce full_write2_str() into writing to stdout. The relevant commits were: 21278dff7 (busybox: do not print help to fd 2, print it to fd 1) and 5a7c72015 (busybox --list option. +140 bytes. Rob wanted it.) Later, in commit 729ecb87b (bbconfig: make it independent from printf functions), the function full_write1_str() was added. Using this in busybox_main() allows us to drop the dup2() calls. function old new delta run_applet_and_exit 796 760 -36 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-36) Total: -36 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: optimise running of scripts (2)Ron Yorston2024-09-041-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 4b7b4a960 (ash: optimise running of scripts) avoided creation of a process when running a script. There's another case where we can do the same: if the script is being run from a FS_SHELLEXEC shell. - Check the necessary conditions for this to happen. - Allocate two extra slots in the argv array for FS_SHELLEXEC. - Set the index of the script file in the argv array. Without this the test 'pidof this' failed because the command name hadn't been correctly set. Adds 80-96 bytes.
* | win32: code shrink system drive handlingRon Yorston2024-07-071-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: code shrink BB_CRITICAL_ERROR_DIALOGSRon Yorston2024-06-231-1/+1
| | | | | | | | | | | | Rewrite the test for the value of BB_CRITICAL_ERROR_DIALOGS. Saves 16-48 bytes.
* | win32: add env var to control error dialogsRon Yorston2024-06-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* | win32: don't set error modeRon Yorston2024-06-161-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit a8c63f25b3 (win32: improve filesystem detection and display) added a call to SetErrorMode(SEM_FAILCRITICALERRORS). This was on the strength of the documentation for GetVolumeInformation() which suggests that otherwise a message box will appear to prompt the user to put media in an empty floppy or CD drive. This would disrupt the expected behaviour of applets like 'df'. In practice it seems the call to SetErrorMode() is unnecessary. It also results in other errors going unreported. Remove the call to SetErrorMode(). Saves 8-20 bytes. (GitHub issue #423)
* | win32: allow for trailing separator in PATHRon Yorston2024-06-141-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: rearrange applet override handlingRon Yorston2024-02-021-25/+28
| | | | | | | | | | | | | | | | | | | | - Rename some functions to be more meaningful. - Adjust conditional compilation to clarify which code is required for 'standalone shell' and 'exec prefers applets' settings. This shouldn't result in any change to the behaviour or size of default builds.
* | win32: avoid invalid freeRon Yorston2024-01-241-3/+5
| | | | | | | | | | | | In external_exists() in appletlib.c it's necessary to take a copy of the pointer to the allocated variable path1 so it can be freed: find_executable() will change its value.
* | Annual update of copyright messageRon Yorston2024-01-151-1/+1
| |
* | httpd: fix failure to run daemonisedRon Yorston2023-12-151-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Since commit 2af141a2c (ash: changes to login shell functionality) httpd has failed to run in the background (i.e. without the '-f' option). This was due the removal of support for applet names with a '-' prefix. Although this feature isn't used by the shell it was used by httpd to mark when the process had been daemonised. Adds 16 bytes. (GitHub issue #378)
* | win32: tidy up conditional compilation of applet overrideRon Yorston2023-12-121-7/+6
| | | | | | | | | | This doesn't affect the generated binary, at least in the default configuration.
* | win32: code shrink applet overridesRon Yorston2023-12-101-12/+22
| | | | | | | | | | | | | | | | Pass the PATH to be used to look up executables down from the shell to the applet override code. This replaces the use of a static variable and a function to fetch its value. Saves 16-32 bytes.
* | win32: allow hardcoded list of applets to overrideRon Yorston2023-12-091-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | The environment variable BB_OVERRIDE_APPLETS provides control over which applets are preferred in standalone shell mode. Allow a similar list to be hardcoded in the binary with the OVERRIDE_APPLETS configuration string. The environment variable is checked first. If it doesn't override the applet the hardcoded string is then checked too. The default for OVERRIDE_APPLETS is an empty string. In this case the size and behaviour of the binary is unchanged.
* | ash: changes to login shell functionalityRon Yorston2023-08-301-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream BusyBox supports the usual Unix functionality where the login process adds a '-' prefix to the shell's argv[0]. Since busybox-w32 doesn't have a login process this serves no purpose and can be removed. Instead it would be useful to have a way to invoke a login shell without requiring any arguments. Advantages would be: - easier to configure busybox-w32 'ash' as the SSH login shell; - double clicking on a shell binary could start a login shell. Add 'lash' as an alias for 'ash' which starts a login shell without requiring the '-l' option. Saves 16 bytes.
* | libbb: fix #!/bin/busyboxRon Yorston2023-08-281-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 3476fb9f4c (ps: display interpreted script name in comm column) required the applet start up code to detect the index of the script in a shebang command line. When a script starts with '#!/bin/busybox' the argument list is shifted in busybox_main() but the script index wasn't adjusted to match. This caused the command to fail. Make the proper adjustment. Add 16 bytes. (GitHub issue #357)
* | libbb: change message regarding UTF-8 manifestRon Yorston2023-08-171-1/+1
| | | | | | | | | | When the UTF-8 manifest is included in the binary but the ANSI code page isn't UTF-8 report "UTF8 manifest not supported".
* | win32: fail early if UTF8 isn't supportedRon Yorston2023-07-271-11/+20
| | | | | | | | | | | | | | | | | | When the UTF8 manifest is included in the binary and ACP isn't UTF8 fail at once. This avoids raising false hopes if the binary is run on Window 7/8. On Windows XP it won't even run. When the busybox applet is run without arguments always report the build-time configuration of globbing and the UTF8 manifest.
* | win32: version with UTF8 manifest: add '(Unicode on/off)'Avi Halachmi (:avih)2023-07-241-0/+4
| | | | | | | | | | | | When the UTF8 manifest is enabled at build time, then the version now includes a string indicating whether unicode is active (e.g. it's inactive on win 7/8, but should be active on Win10 1903+).
* | win32: more applet look-up tweaksRon Yorston2023-06-191-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)
* | win32: code shrink applet look-upRon Yorston2023-06-051-20/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - Remove find_preferred_applet_by_name(). Instead add a reference to is_applet_preferred() in find_applet_by_name(). - Remove the global variable ash_path. Use a static instead, accessed by calling get_ash_path(). - Mark ash_applet_by_name() as NOINLINE. Saves 64-96 bytes. (GitHub issue #329)
* | win32: another BB_OVERRIDE_APPLETS fixRon Yorston2023-06-041-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Support for conditionally replacing applets with external commands requires the ability to check whether a given command name is present on PATH. This was being done using the PATH environment variable, which works in commands run by the shell but not in the shell itself. - The shell uses the *shell* variable PATH to look for executables. This may not be the same as the *environment* variable. - 'command -p' uses an entirely different PATH. Applet look-up in the shell is now treated as a special case, with the actual PATH being used passed to the look-up code in a global variable. This doesn't affect tab completion in the shell: whether a completion is an applet or an external command is irrelevant. Costs 152-288 bytes. (GitHub issue #329)
* | win32: change interpretation of BB_OVERRIDE_APPLETSRon Yorston2023-06-021-6/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make the following changes to BB_OVERRIDE_APPLETS: - Applet names in the list can be separated by spaces, commas or semicolons. - Applets before the first semicolon are disabled unconditionally. - Applets after the first semicolon are overridden if a matching external command exists. - '-' alone disables all applets. - '+' alone overrides every applet for which a matching external command exists. This doesn't change the existing documented behaviour. It adds the ability to have applets overridden if an external command exists but to remain available if not. Adds 80-88 bytes. (GitHub issue #329)
* | Merge branch 'busybox' into mergeRon Yorston2023-04-171-1/+1
|\|
| * appletlib: fix "warning: unused variable applet_no"Tomas Paukrt2023-04-101-1/+1
| | | | | | | | | | Signed-off-by: Tomas Paukrt <tomaspaukrt@email.cz> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | win32: delay adjusting code pageRon Yorston2023-03-171-3/+1
| | | | | | | | | | | | | | | | | | | | | | Commit 93a63809f9 (win32: add support for the euro currency symbol) caused all invocations of busybox-w32 to change code page 850 to 858. This has been known to cause problems with fonts in PowerShell (GitHub issue #207). Delay changing the code page until an i/o operation is imminent. Instances of PowerShell started by the `drop` applet during ssh login thus no longer have their code page adjusted.
* | Annual update of copyright messageRon Yorston2023-01-051-1/+1
| |
* | Merge branch 'busybox' into mergeRon Yorston2022-10-121-3/+5
|\|
| * fix [ --help ] and [[ --help ]]Denys Vlasenko2022-08-301-0/+3
| | | | | | | | | | | | | | function old new delta show_usage_if_dash_dash_help 72 79 +7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: make '--help' handling more consistentRon Yorston2022-08-221-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Running an applet with '--help' as its only argument is treated as a special case. If additional arguments follow '--help' the behaviour is inconsistent: - applets which call single_argv() print help and do nothing else; - applets which call getopt() report "unrecognized option '--help'" and print help anyway; - expr says "expr: syntax error" and doesn't print help; - printenv silently ignores '--help', prints any other variables and doesn't print help; - realpath says "--help: No such file or directory", prints the path of any other files and doesn't print help. If the first argument is '--help' ignore any other arguments and print help. This is more consistent and most likely what the user wanted. See also commit 6bdfbc4cb (libbb: fix '--help' handling in FEATURE_SH_NOFORK=y). function old new delta show_usage_if_dash_dash_help 75 69 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-6) Total: -6 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2022-05-121-1/+1
|\|
| * style fixDenys Vlasenko2022-05-011-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: export certain variables to the environment immediatelyRon Yorston2022-05-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | The environment variables BB_OVERRIDE_APPLETS, BB_SKIP_ANSI_EMULATION and BB_SYSTEMROOT affect of the behaviour of the shell itself. Setting them as shell variables is insufficient for them to affect the current shell. When these three variables are exported from the shell they are now placed in the environment immediately. Conversely, when they're unset or unexported they're removed from the environment.
* | win32: allow preference for applets to be disabled at runtimeRon Yorston2022-05-061-0/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The default busybox-w32 configuration enables the PREFER_APPLETS and SH_STANDALONE features. Sometimes it may be desirable to override the default preference for applets, for example, if an applet needs to be replaced by an external program with additional features. Add support for the environment variable BB_OVERRIDE_APPLETS. Its value may be: - a single dash ('-'): all applets are overridden; - a space-separated list of names: only the specified applets are overridden.
* | win32: minor adjustments to file permissionsRon Yorston2022-04-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Mask the file permission bits in mingw_umask(), not when it's called from run_applet_no_and_exit(). Rather than hardcode write permissions for group and other in file_attr_to_st_mode() and mingw_fstat() make them respect the current umask setting. In mingw_fstat() there's no need to check the mode using S_ISDIR(): the hardcoded mode doesn't set S_IFDIR. The compiler had already figured this out so there's no reduction in bloat.
* | Fix POSIX build; new yearRon Yorston2022-02-091-1/+1
| |
* | Merge busybox into mergeRon Yorston2022-02-091-1/+1
|\| | | | | | | | | | | | | | | Fix conflicts in reset and ash. Redefine the new safe_read_key() as a reference to read_key(). Disable SHA256_HWACCEL.
| * *: slap on a few ALIGN* where appropriateDenys Vlasenko2022-02-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The result of looking at "grep -F -B2 '*fill*' busybox_unstripped.map" function old new delta .rodata 108586 108460 -126 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-126) Total: -126 bytes text data bss dec hex filename 970412 4219 1848 976479 ee65f busybox_old 970286 4219 1848 976353 ee5e1 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2021-10-131-9/+14
|\|
| * shell: fix script's comm field if ENABLE_FEATURE_PREFER_APPLETS=yDenys Vlasenko2021-10-111-2/+8
| | | | | | | | | | | | | | | | | | | | function old new delta re_execed_comm - 46 +46 main 72 86 +14 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 60/0) Total: 60 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * Make const ptr assign as function call in clangYU Jincheng2021-10-091-1/+1
| | | | | | | | | | | | | | | | - This can act as memory barrier in clang to avoid read before assign of a const ptr Signed-off-by: LoveSy <shana@zju.edu.cn> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * *: generalize "const trick"YU Jincheng2021-10-071-2/+1
| | | | | | | | | | | | | | | | While at it, change all "__asm__" to "asm" Co-authored-by: canyie <31466456+canyie@users.noreply.github.com> Signed-off-by: YU Jincheng <shana@zju.edu.cn> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: code shrink in main() and scripted_main()Denys Vlasenko2021-09-281-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | function old new delta main 68 65 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3) Total: -3 bytes text data bss dec hex filename 1472 560 16 2048 800 busybox_old 1398 552 16 1966 7ae busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * busybox: fix "busybox --help busybox" not showing correct textDenys Vlasenko2021-08-161-1/+5
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | busybox: bring help handling into line with upstreamRon Yorston2021-08-161-5/+5
| | | | | | | | | | Upstream has fixed a problem with 'busybox --help' so it's possible to remove another gratuitous divergence.
* | busybox: make 'busybox --help busybox' workRon Yorston2021-05-141-0/+4
| | | | | | | | | | Upstream changes broke the 'busybox --help busybox' command. Fix it.