[PATCH] ash: add built-in $ASH_VERSION variable
Ariadne Conill
ariadne at dereferenced.org
Thu Mar 11 06:54:54 UTC 2021
This is helpful for detecting if the shell is busybox ash or not,
which is necessary for enabling ash-specific features in /etc/profile
and Alpine's default $ENV.
https://gitlab.alpinelinux.org/alpine/aports/-/issues/12398 outlines
the rationale for detecting what shell is running in /etc/profile and
similar.
function old new delta
varinit_data 360 384 +24
.rodata 77899 77922 +23
bbconfig_config_bz2 6127 6120 -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 47/-7) Total: 40 bytes
Signed-off-by: Ariadne Conill <ariadne at dereferenced.org>
---
shell/ash.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/shell/ash.c b/shell/ash.c
index 6a16833b1..6f1d2b2a8 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -153,6 +153,14 @@
//config: you to run the specified command or builtin,
//config: even when there is a function with the same name.
//config:
+//config:config ASH_VERSION_VAR
+//config: bool "declare $ASH_VERSION variable"
+//config: default y
+//config: depends on SHELL_ASH
+//config: help
+//config: Enable support for declaring the $ASH_VERSION variable,
+//config: which is set as the busybox version.
+//config:
//config:endif # ash options
//applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP))
@@ -2109,6 +2117,9 @@ static const struct {
{ VSTRFIXED|VTEXTFIXED , "PS1=$ " , NULL },
{ VSTRFIXED|VTEXTFIXED , "PS2=> " , NULL },
{ VSTRFIXED|VTEXTFIXED , "PS4=+ " , NULL },
+#if ENABLE_ASH_VERSION_VAR
+ { VSTRFIXED|VTEXTFIXED , "ASH_VERSION=" BB_VER, NULL },
+#endif
#if ENABLE_ASH_GETOPTS
{ VSTRFIXED|VTEXTFIXED , defoptindvar, getoptsreset },
#endif
@@ -2159,18 +2170,19 @@ extern struct globals_var *BB_GLOBAL_CONST ash_ptr_to_globals_var;
#define vps1 varinit[VAR_OFFSET1 + 2]
#define vps2 varinit[VAR_OFFSET1 + 3]
#define vps4 varinit[VAR_OFFSET1 + 4]
+#define VAR_OFFSET2 (VAR_OFFSET1 + ENABLE_ASH_VERSION_VAR)
#if ENABLE_ASH_GETOPTS
-# define voptind varinit[VAR_OFFSET1 + 5]
+# define voptind varinit[VAR_OFFSET2 + 5]
#endif
-#define VAR_OFFSET2 (VAR_OFFSET1 + ENABLE_ASH_GETOPTS)
-#define vlineno varinit[VAR_OFFSET2 + 5]
+#define VAR_OFFSET3 (VAR_OFFSET2 + ENABLE_ASH_GETOPTS)
+#define vlineno varinit[VAR_OFFSET3 + 5]
#if ENABLE_ASH_RANDOM_SUPPORT
-# define vrandom varinit[VAR_OFFSET2 + 6]
+# define vrandom varinit[VAR_OFFSET3 + 6]
#endif
-#define VAR_OFFSET3 (VAR_OFFSET2 + ENABLE_ASH_RANDOM_SUPPORT)
+#define VAR_OFFSET4 (VAR_OFFSET2 + ENABLE_ASH_RANDOM_SUPPORT)
#if BASH_EPOCH_VARS
-# define vepochs varinit[VAR_OFFSET3 + 6]
-# define vepochr varinit[VAR_OFFSET3 + 7]
+# define vepochs varinit[VAR_OFFSET4 + 6]
+# define vepochr varinit[VAR_OFFSET4 + 7]
#endif
#define INIT_G_var() do { \
unsigned i; \
--
2.30.2
More information about the busybox
mailing list