"init" is 4 chars long, "/bin/init" is 9 chars long, so when I "remove" the while (*++argv) ... loop, there are 5 extra bytes between "init" and the content of argv[1]. In ps, the symptom is extra spaces inserted in the output, but the argv[1]+ args are shown "correctly" In hexdump -C /proc/1/cmdline, 6 zeros instead of 1, are present between the last char of "init" and the first of argv[1].
I think it's normal since the strncpy line doesn't bother with the rest of the command-line which was to be wiped, in the end. So my question was, do I #ifdef the whole cmdline modifications, including that of argv[0] like you did, or do I let init modify argv[0], in which case I'll have to memmove the rest of the command-line to get rid of the unused extra bytes. Personally, I prefer the first solution. I still don't get the point of modifying a program's argument, be it init or not... 2016-02-01 9:00 GMT+01:00 Mike Frysinger <[email protected]>: > On 01 Feb 2016 08:09, Nicolas CARRIER wrote: > > I wrote a little patch which adds the option not to wipe the arguments, > but > > the result is a little bit odd, some 0 are inserted between "init" and > the > > rest of the arguments. I must be because "/bin/init" is replaced with > > "init". > > So the proper patch should either : > > * inhibit this argv[0] modification too > > * perform a memmove to wipe those extra zeros > > > > Which one do you think is best ? > > what do you mean "some 0" ? can you copy & paste the exact terminal > output you're seeing ? > > argv settings has always been ugly in Linux ... the location of argv > is static as is the size. there's no way to tell the kernel to use > a different location so you're force to screw with the existing mem. > > that said, i would just start with the simple answer: don't mess with > anything at all. > -mike > > --- a/init/init.c > +++ b/init/init.c > @@ -1139,11 +1139,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 (FEATURE_INIT_ARGV_REWRITE) { > + /* 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); > + } > > /* Set up signal handlers */ > if (!DEBUG_INIT) { >
_______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
