Re: How to add subshell support for ash

Never mind, I am one step further:

>     case ASH:
>         /* ash does not support precmd, we need to read cwd from the prompt */
>         g_snprintf (precmd, sizeof (precmd),
>                     "PS1='$(pwd>&%d; kill -STOP $$)\\u@\\h:\\w\\$ '\n", subshell_pipe[WRITE]);
>         break;

This works for BusyBox ash (tested on mipsel platform). The command will
be contained in the shell editing history, but for me this is acceptable.

The next thing I want to do is set ENV so as to enable loading my shell
profile without having to use a login shell. This would be the
equivalent to Bash's "-rcfile" parameter. I did this:

>     case ASH:
>         /* Do we have a custom init file ~/.local/share/mc/ashrc? */
>         init_file = mc_config_get_full_path ("ashrc");
>         /* Otherwise use ~/.profile */
>         if (access (init_file, R_OK) == -1)
>         {
>             g_free (init_file);
>             init_file = g_strdup (".profile");
>         }
>         /* Put init file to ENV variable used by ash */
>         char *putenv_str = g_strconcat ("ENV=", init_file, NULL);
>         putenv (putenv_str);
>         g_free (putenv_str);
>         break;

And later this:

>     /* TODO for upstream patch: Execute correct ash/dash/busybox shell (not necessary for Freetz) */
>     case ASH:
>         execl (shell, "sh", (char *) NULL);
>         break;

The problem is that ENV seems to be unset in my subshell's environment,
i.e. that ~ /.profile (whiche exists) is not evaluated. Do I need to
somehow export the ENV variable to make it available to the subshell?
BTW, I am compiling against uClibc 0.9.29, if this is relevant.

Alexander Kriegisch, 03.03.2012 14:41:
> I am on an embedded environment. Bash is available as a separate 
> package, but huge in comparison with the built-in ash of BusyBox.
> Disclaimer before I continue: I am *not* a C programmer. I can read
> a bit of C, but not develop anything meaningful other than copy,
> paste and modify existing code. So bear with me anyway, if you
> please.
> I looked into src/subshell.c and tried to figure out what happens
> there. I have started to add ash support, but MC seems to depend on 
> PROMPT_COMMAND/precmd/fish_prompt, i.e. on a function or alias which
> is executed each time just before a prompt is printed. Ash does not
> have anything like that, AFAIK. If I understand correctly, using
> those pre-commands are MC's way of determining the cwd. I wonder why
> you do not just use something like pwd or $PWD, but OTOH I do not
> understand the difficulties of corresponding with the subshell.
> Anyway, in my case it would be absolutely fine to set a fixed value
> of PS1='\w\$ ' for the subshell and read the cwd from the prompt. In
> any case it would be better than not having the option of using ash
> as a subshell at all.
> Could anyone maybe provide me with a code snippet or a patch which
> shows me how to extract the cwd from the prompt assuming that PS1 has
> the value '\w\$ '? (BTW, '\$' will be evaluated to '$' or '#' in
> ash, depending on whether you are root or not.)
> Thank you so much. If I succeed in adding ash as a subshell, I will 
> provide a (raw) patch for you to inspect and maybe refine and
> include upstream.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]