Fwd: why are init's arguments wiped ?

Mike Frysinger vapier at gentoo.org
Mon Feb 1 17:10:57 UTC 2016


On 01 Feb 2016 09:17, Nicolas CARRIER wrote:
> "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].

OK, so you're talking about embedded NULs.  that's entirely to be expected
and there's not really anything you can do about it unless you repack the
args yourself (as you noticed).

> Personally, I prefer the first solution. I still don't get the point of
> modifying a program's argument, be it init or not...

it makes a lot of sense when you fork children that have specific purposes.
rather than just seeing the program's name 4 times, it's more helpful for
them to be broken up.  for example, postgres does:
805 ? S  0:28 /usr/lib/postgresql-9.4/bin/postgres -D /etc/postgresql-9.4 --data-directory=/var/lib/postgresql/9.4/data
807 ? Ss 2:49 postgres: checkpointer process   
808 ? Ss 1:05 postgres: writer process   
809 ? Ss 0:56 postgres: wal writer process   
810 ? Ss 0:22 postgres: autovacuum launcher process   
811 ? Ss 1:24 postgres: stats collector process   

surely you'd agree this is way better than if you saw:
805 ? S  0:28 /usr/lib/postgresql-9.4/bin/postgres -D /etc/postgresql-9.4 --data-directory=/var/lib/postgresql/9.4/data
807 ? Ss 2:49 /usr/lib/postgresql-9.4/bin/postgres -D /etc/postgresql-9.4 --data-directory=/var/lib/postgresql/9.4/data
808 ? Ss 1:05 /usr/lib/postgresql-9.4/bin/postgres -D /etc/postgresql-9.4 --data-directory=/var/lib/postgresql/9.4/data
809 ? Ss 0:56 /usr/lib/postgresql-9.4/bin/postgres -D /etc/postgresql-9.4 --data-directory=/var/lib/postgresql/9.4/data
810 ? Ss 0:22 /usr/lib/postgresql-9.4/bin/postgres -D /etc/postgresql-9.4 --data-directory=/var/lib/postgresql/9.4/data
811 ? Ss 1:24 /usr/lib/postgresql-9.4/bin/postgres -D /etc/postgresql-9.4 --data-directory=/var/lib/postgresql/9.4/data

especially if you're trying to debug why one of those processes is taking
up a ton of CPU or memory.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20160201/8d33d137/attachment.asc>


More information about the busybox mailing list