Please find attached the new version implementing
FEATURE_INIT_MODIFY_CMDLINE, defaulting to "y".

2016-02-04 8:12 GMT+01:00 Nicolas CARRIER <[email protected]>:
> OK, I will send the new patch ASAP
>
> Le 3 févr. 2016 18:39, "Mike Frysinger" <[email protected]> a écrit :
>>
>> On 03 Feb 2016 12:45, Daniel Thompson wrote:
>> > On 03/02/16 12:29, Nicolas CARRIER wrote:
>> > > Honestly, I hesitated to propose the inverse feature.
>> > > I think the key point is : what we consider "normal" behavior ?
>> > > I tend to consider it's "keep your arguments as they were passed to
>> > > you", but I felt there was more people favoring the "do as you've
>> > > always done".
>> >
>> > Defaults are enough to handle "normal" behavior; inverting the
>> > definition of a feature isn't helpful.
>> >
>> > It is far better (and more intuitive) if: feature off -> smaller code
>>
>> naming wise, FEATURE_INIT_MODIFY_CMDLINE is fine.  the "default" value
>> can be easily used to set the state regardless of naming and inverted.
>>
>> i have no strong opinion either way as to the default.  disabling the
>> munging by default does yield smaller code.
>> -mike
From 5cfe08e030635890d3a194e6a4969d602302d28f Mon Sep 17 00:00:00 2001
From: Nicolas Carrier <[email protected]>
Date: Thu, 4 Feb 2016 12:18:01 +0100
Subject: init: make the command-line rewrite optional

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

This patch adds the FEATURE_INIT_MODIFY_CMDLINE which, if set to n, will
make init preserve all its 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 | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/init/init.c b/init/init.c
index 2040a59..bd77cfc 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_INIT_MODIFY_CMDLINE
+//config:	bool "Modify the command-line to \"init\""
+//config:	default y
+//config:	depends on INIT
+//config:	help
+//config:	  When launched as PID 1 and after parsing its arguments, init
+//config:	  wipes all the arguments but argv[0] and rewrites argv[0] to
+//config:	  contain only "init", so that its command-line appears solely as
+//config:	  "init" in tools such as ps.
+//config:	  If this option isset to Y, init will keep its original behavior,
+//config:	  otherwise, all the arguments including argv[0] will be preserved,
+//config:	  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
 
-	/* 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);
+	if (ENABLE_FEATURE_INIT_MODIFY_CMDLINE) {
+		/* Make the command line just say "init"  - that's 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);
+	}
 
 	/* Set up signal handlers */
 	if (!DEBUG_INIT) {
-- 
2.7.0

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to