[git commit] busybox: optional --version support

Denys Vlasenko vda.linux at googlemail.com
Mon Oct 13 19:56:47 UTC 2025


commit: https://git.busybox.net/busybox/commit/?id=b99a529177b4adbe3b3f5a86f46b9cf386d4cbe4
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
busybox_main                                         695     734     +39

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 Config.in         |  7 +++++++
 libbb/appletlib.c | 16 ++++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/Config.in b/Config.in
index ad0cd1e26..6b925b517 100644
--- a/Config.in
+++ b/Config.in
@@ -204,6 +204,13 @@ config FEATURE_INSTALLER
 	busybox at runtime to create hard links or symlinks for all the
 	applets that are compiled into busybox.
 
+config FEATURE_VERSION
+	bool "Support --version"
+	default y
+	depends on BUSYBOX
+	help
+	Enable 'busybox --version' support.
+
 config INSTALL_NO_USR
 	bool "Don't use /usr"
 	default n
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index d2e5900b5..17216baab 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -892,14 +892,14 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
 	}
 
 	if (strcmp(argv[1], "--help") == 0) {
-		/* "busybox --help [<applet>]" */
+		/* "busybox --help [APPLET]" */
 		if (!argv[2]
 #  if ENABLE_FEATURE_SH_STANDALONE && ENABLE_FEATURE_TAB_COMPLETION
 		 || strcmp(argv[2], "busybox") == 0 /* prevent getting "No help available" */
 #  endif
 		)
 			goto help;
-		/* convert to "<applet> --help" */
+		/* convert to "APPLET --help" */
 		applet_name = argv[0] = argv[2];
 		argv[2] = NULL;
 		if (find_applet_by_name(applet_name) >= 0) {
@@ -907,8 +907,16 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
 			xfunc_error_retval = 0;
 			bb_show_usage();
 		} /* else: unknown applet, fall through (causes "applet not found" later) */
-	} else {
-		/* "busybox <applet> arg1 arg2 ..." */
+	}
+#  if ENABLE_FEATURE_VERSION
+	else if (!argv[2] && strcmp(argv[1], "--version") == 0) {
+		full_write1_str(bb_banner); /* reuse const string */
+		full_write1_str("\n");
+		return 0;
+	}
+#  endif
+	else {
+		/* "busybox APPLET arg1 arg2 ..." */
 		argv++;
 		/* We support "busybox /a/path/to/applet args..." too. Allows for
 		 * "#!/bin/busybox"-style wrappers


More information about the busybox-cvs mailing list