ash acts like init

casty at centolos.com casty at centolos.com
Sun Mar 29 14:26:18 UTC 2009


My answers were not sent to the list because, for some reason, the list
address is not in the reply-to field.

We had this conversation privately. I'm sorry for the inconvenience.

> On Sunday 29 March 2009 01:42, casty at centolos.com wrote:
>> >> I'm trying to run ash as the init process in the kernel parameters
(init=/bin/ash). But when I run it, it reads the /etc/inittab. I
>> tried
>> >> rebuilding busybox with init disabled, but the only thing I got was
>> an
>> >> "init: applet not found" error.
> ...
>> > Let's verify that you are getting correct argv[0].
>> > busybox's main() is in libbb/appletlib.c.
>> > Go there, and add debug write's like this:
>> >
>> > #if ENABLE_BUILD_LIBBUSYBOX
>> > int lbb_main(char **argv)
>> > #else
>> > int main(int argc UNUSED_PARAM, char **argv)
>> > #endif
>> > {
>> > write(1, "argv[0]:'", 9);            <=================
>> > write(1, argv[0], strlen(argv[0]));  <=================
>> > write(1, "'\n", 2);                  <=================
>>
>> You're right, I'm receiving "init" as argv[0]. So probably a "real" sh
doesn't care about argv[0]...
>
> It means that init=/bin/ash didn't take effect somehow.

/usr/src/linux/init/main.c

static char* argv_init[MAX_INT_ARGS+2] = {"init",NULL, };

...so argv[0] = "init"....

static void __init parse_options(char *line){
... for each string without spaces ...{
  if (!strncmp(line,"init=",5)){
    line += 5;
    execute_command = line;  // execute_command = "/bin/ash"
    args = 0;
    continue;
    }
...
  if (*line)
    argv_init[++args] = line;  // argv[0] is never touched (++args)
  }
}

later, execve(execute_command, argv_init,...) is called. So it calls "sh"
but argv[0] is "init" :(

I wonder if there is any way to execute busybox with the applet in argv[1]
ingnoring what's on argv[0], in the way that "init sh" would act as "sh".

Here is my .config

Regards!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config
Type: application/octet-stream
Size: 24313 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20090329/75158308/attachment-0001.obj>


More information about the busybox mailing list