diff options
author | Nicolas Carrier <nicolas.carrier@parrot.com> | 2016-02-04 12:18:01 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-02-11 14:23:33 +0100 |
commit | 29eae728e959a382841bd0a32cc1a8d1bcdc9150 (patch) | |
tree | 7ccda1c300308023aa99b0b358db1f0571a0b561 | |
parent | 383201e7258c3c1646f6d5cab4e813b5c3b3ecd0 (diff) | |
download | busybox-w32-29eae728e959a382841bd0a32cc1a8d1bcdc9150.tar.gz busybox-w32-29eae728e959a382841bd0a32cc1a8d1bcdc9150.tar.bz2 busybox-w32-29eae728e959a382841bd0a32cc1a8d1bcdc9150.zip |
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.
Signed-off-by: Nicolas Carrier <nicolas.carrier@parrot.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | init/init.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/init/init.c b/init/init.c index 2040a59e8..25bfaec8c 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -102,6 +102,21 @@ | |||
102 | //config: | 102 | //config: |
103 | //config: Note that on Linux, init attempts to detect serial terminal and | 103 | //config: Note that on Linux, init attempts to detect serial terminal and |
104 | //config: sets TERM to "vt102" if one is found. | 104 | //config: sets TERM to "vt102" if one is found. |
105 | //config: | ||
106 | //config:config FEATURE_INIT_MODIFY_CMDLINE | ||
107 | //config: bool "Modify the command-line to \"init\"" | ||
108 | //config: default y | ||
109 | //config: depends on INIT | ||
110 | //config: help | ||
111 | //config: When launched as PID 1 and after parsing its arguments, init | ||
112 | //config: wipes all the arguments but argv[0] and rewrites argv[0] to | ||
113 | //config: contain only "init", so that its command-line appears solely as | ||
114 | //config: "init" in tools such as ps. | ||
115 | //config: If this option is set to Y, init will keep its original behavior, | ||
116 | //config: otherwise, all the arguments including argv[0] will be preserved, | ||
117 | //config: be they parsed or ignored by init. | ||
118 | //config: The original command-line used to launch init can then be | ||
119 | //config: retrieved in /proc/1/cmdline on Linux, for example. | ||
105 | 120 | ||
106 | //applet:IF_INIT(APPLET(init, BB_DIR_SBIN, BB_SUID_DROP)) | 121 | //applet:IF_INIT(APPLET(init, BB_DIR_SBIN, BB_SUID_DROP)) |
107 | //applet:IF_FEATURE_INITRD(APPLET_ODDNAME(linuxrc, init, BB_DIR_ROOT, BB_SUID_DROP, linuxrc)) | 122 | //applet:IF_FEATURE_INITRD(APPLET_ODDNAME(linuxrc, init, BB_DIR_ROOT, BB_SUID_DROP, linuxrc)) |
@@ -1138,11 +1153,13 @@ int init_main(int argc UNUSED_PARAM, char **argv) | |||
1138 | } | 1153 | } |
1139 | #endif | 1154 | #endif |
1140 | 1155 | ||
1141 | /* Make the command line just say "init" - thats all, nothing else */ | 1156 | if (ENABLE_FEATURE_INIT_MODIFY_CMDLINE) { |
1142 | strncpy(argv[0], "init", strlen(argv[0])); | 1157 | /* Make the command line just say "init" - that's all, nothing else */ |
1143 | /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */ | 1158 | strncpy(argv[0], "init", strlen(argv[0])); |
1144 | while (*++argv) | 1159 | /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */ |
1145 | nuke_str(*argv); | 1160 | while (*++argv) |
1161 | nuke_str(*argv); | ||
1162 | } | ||
1146 | 1163 | ||
1147 | /* Set up signal handlers */ | 1164 | /* Set up signal handlers */ |
1148 | if (!DEBUG_INIT) { | 1165 | if (!DEBUG_INIT) { |