When launched as PID 1 and after parsing it's arguments, init wipes all
all of them except argv[0] and rewrites argv[0] to contain only "init",
so that it's command-line appears solely as "init" in tools such as ps.

This patch adds the FEATURE_PRESERVE_CMDLINE which, if set to Y, will make
init preserve all it's arguments including argv[0], be they parsed or
ignored.
The original command-line used to launch init can then be retrieved in
/proc/1/cmdline on Linux, for example.
From 4a798bf8e080d88a17a35feaf83f2c76151a9fae Mon Sep 17 00:00:00 2001
From: Nicolas Carrier <nicolas.carr...@parrot.com>
Date: Mon, 1 Feb 2016 17:59:56 +0100
Subject: init: allow to preserve init's command-line

When launched as PID 1 and after parsing it's arguments, init wipes all
all of them except argv[0] and rewrites argv[0] to contain only "init",
so that it's command-line appears solely as "init" in tools such as ps.

This patch adds the FEATURE_PRESERVE_CMDLINE which, if set to Y, will make
init preserve all it's arguments including argv[0], be they parsed or
ignored.
The original command-line used to launch init can then be retrieved in
/proc/1/cmdline on Linux, for example.
---
 init/init.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/init/init.c b/init/init.c
index 2040a59..74c9486 100644
--- a/init/init.c
+++ b/init/init.c
@@ -102,6 +102,22 @@
 //config:
 //config:	  Note that on Linux, init attempts to detect serial terminal and
 //config:	  sets TERM to "vt102" if one is found.
+//config:
+//config:config FEATURE_PRESERVE_CMDLINE
+//config:	bool "Prevent init from altering it's command-line after parsing"
+//config:	default n
+//config:	depends on INIT
+//config:	help
+//config:	  When launched as PID 1 and after parsing it's arguments, init
+//config:	  wipes all the arguments but argv[0] and rewrites argv[0] to
+//config:	  contain only "init", so that it's command-line appears solely as
+//config:	  "init" in tools such as ps.
+//config:
+//config:	  If you set this option to Y, all the arguments including argv[0]
+//config:	  will be preserved, be they parsed or ignored by init.
+//config:	  The original command-line used to launch init can then be
+//config:	  retrieved in /proc/1/cmdline on Linux, for example.
+
 
 //applet:IF_INIT(APPLET(init, BB_DIR_SBIN, BB_SUID_DROP))
 //applet:IF_FEATURE_INITRD(APPLET_ODDNAME(linuxrc, init, BB_DIR_ROOT, BB_SUID_DROP, linuxrc))
@@ -1138,11 +1154,13 @@ int init_main(int argc UNUSED_PARAM, char **argv)
 	}
 #endif
 
+#if !ENABLE_FEATURE_PRESERVE_CMDLINE
 	/* Make the command line just say "init"  - thats all, nothing else */
 	strncpy(argv[0], "init", strlen(argv[0]));
 	/* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
 	while (*++argv)
 		nuke_str(*argv);
+#endif
 
 	/* Set up signal handlers */
 	if (!DEBUG_INIT) {
-- 
2.7.0

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to