[BusyBox] problem with standalone shell + pivot_root

Denis Vlasenko vda at port.imtp.ilyichevsk.odessa.ua
Fri Jul 25 06:16:20 UTC 2003


I am making my first initrd.
My initscript on the initrd ends as follows:

...
mount /dev/something /new_root
mount -t devfs none /new_root/dev
cd /new_root
pivot_root . etc_root
exec chroot . /bin/sh

last line is supposed to be exec'ed on new fs as root fs,
there is no busybox on it, but if I compile ash with
'standalone shell' option it does not realize that and try
to exec '/bin/busybox chroot', which fails.

Relevant source exerpt is below. You may see how it finally
execve'cs itself. Maybe it's possible
to fork()+call applet sub+exit instead? This would work
even if busybox binary isn't visible (=exec'able) anymore.
--
vda

static void tryexec(char *cmd, char **argv, char **envp)
{
        int repeated = 0;

#ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL
        int flg_bb = 0;
        char *name = cmd;

#ifdef CONFIG_FEATURE_SH_APPLETS_ALWAYS_WIN
        name = bb_get_last_path_component(name);
        if(find_applet_by_name(name) != NULL)
                flg_bb = 1;
#else
        if(strchr(name, '/') == NULL && find_applet_by_name(name) != NULL) {
                flg_bb = 1;
        }
#endif
        if(flg_bb) {
                char **ap;
                char **new;

                *argv = name;
                if(strcmp(name, "busybox")) {
                        for (ap = argv; *ap; ap++);
                        ap = new = xmalloc((ap - argv + 2) * sizeof(char *));
                        *ap++ = cmd = "/bin/busybox";
                        while ((*ap++ = *argv++));
                        argv = new;
                        repeated++;
                } else {
                        cmd = "/bin/busybox";
                }
        }
#endif
  repeat:
        execve(cmd, argv, envp);



More information about the busybox mailing list