2003-05-08 04:39:30

by Glenn McGrath

[permalink] [raw]
Subject: [patch] set argv[0] of init process to filename


In init/main.c the kernel always sets argv[0] = "init" when calling the
init process.

The file being executed as init is commonly /sbin/init, but could be
anything, as set from init= boot paramater.

Always setting argv[0] = "init" is inconsistent with standard behaviour
of setting it to the filename that was run.

This current behaviour is inconvenient for busybox (http://www.busybox.net) as
it uses argv[0] to determine functionality.

The attached patch against 2.4.20 sets argv[0] to the filename being run
as the init process, it results in marginally smaller binary (12 bytes).

Is there a reason why argv[0] should always be set to "init" ?



Glenn


Attachments:
init_argv.diff.gz (906.00 B)
(No filename) (189.00 B)
Download all attachments

2003-05-08 08:25:36

by DervishD

[permalink] [raw]
Subject: Re: [patch] set argv[0] of init process to filename

Hi Glenn :)

* Glenn McGrath <[email protected]> dixit:
> This current behaviour is inconvenient for busybox
> (http://www.busybox.net) as it uses argv[0] to determine functionality.

I had a similar problem with my init clone (a virtual console
init+getty+login for embedded systems) with the same issue. I wanted
to change the argv[0] for spawned processes for chaging the name that
the ps command will show. At the end I assumed that the shortest name
possible was 'init' and that I had four characters at least... If the
space is shorter, less characters are used.

> The attached patch against 2.4.20 sets argv[0] to the filename
> being run as the init process, it results in marginally smaller
> binary (12 bytes).

IMHO this is a good thing, I hope it gets included, since in the
general case it won't do any harm (IMHO, again). Let's see what says
Marcelo.

> Is there a reason why argv[0] should always be set to "init" ?

Don't know :??

Ra?l N??ez de Arenas Coronado

--
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/