Optware / Optware-ng

279 stars 52 forks source link

mc subshell not working #164

Closed PiotrC1 closed 7 years ago

PiotrC1 commented 7 years ago

I'm not sure if it is a bug or a feature, but after pressing ctrl+o there is no subshell opened.

alllexx88 commented 7 years ago

OK, I marked this as invalid, since this is normal behaviour by mc to not launch a subshell when it doesn't recognize SHELL as supported shell. If you run export SHELL=/opt/bin/bash before launching mc (after installing bash package), it works fine. However, I see that starting from version 4.8.16 (more specifically, this commit) mc supports ash subshell. I'll upgrade mc to the latest (v 4.8.17) -- and it should fix this issue

alllexx88 commented 7 years ago

Hmm, I upgraded it, but it still doesn't support Busybox ash: it works with Debian ash, but not Busybox. Closing, since I don't know how to fix this. If you have an idea for a fix, feel free to reopen It does work fine with Optware provided bash though

PiotrC1 commented 7 years ago

Hi @alllexx88! Thanks for your excellent explanation. In my case (TomatoUSB) I have /bin/sh interpreter, so it was not recognised by mc. Adding /opt/etc/profile with export SHELL=/opt/bin/bash (after installing bashof course) has solved all my problems. Side effect is resolving one more recent bug of mc - when SHELL is not recognised, it takes approximatelly 3 seconds for mc to start.

alllexx88 commented 7 years ago

Hi @PiotrC1! I finally realized what's actually going on when you try to use mc with TomatoUSB busybox ash (/bin/sh points to busybox binary, and it's actually busybox ash shell). I took a look at mc sources (more specifically, src/subshell/common.c), and now it's all clear. mc needs a way to know subshell current working dir in order to change its dir accordingly, so it creates a named pipe for this (subshell_pipe[WRITE]) -- to have subshell echo its CWD there after each prompt. In case of bash, it appends pwd>&subshell_pipe[WRITE];kill -STOP $$ to PROMPT_COMMAND, which gets executed before every prompt, but busybox ash doesn't use PROMPT_COMMAND, so the only way to get it done is emulating similar behaviour with PS1, and it launches this command during subshell initialization for this: precmd() { if [ ! "${PWD##$HOME}" ]; then MC_PWD=\"~\"; else [ "${PWD##$HOME/}" = "$PWD" ] && MC_PWD="$PWD" || MC_PWD="~/${PWD##$HOME/}"; fi; echo "$USER@$(hostname -s):$MC_PWD"; pwd>&subshell_pipe[WRITE]; kill -STOP $$; }; PRECMD=precmd; PS1='$($PRECMD)$ '. This can only work if PS1 is being expanded, so it needs CONFIG_ASH_EXPAND_PRMT=y busybox config, otherwise you get plain $($PRECMD)$ string as a result, and nothing executed/piped (like in case of TomatoUSB shell). What happens in the latter case, is that mc waits 10 seconds after subshell initialization for CWD to get forwarded, and when these 10 seconds expire, it silently disables the subshell.

With latest Optware busybox, it works fine. If you have older version of busybox package installed, you'll have to upgrade it in a bit tricky way, since opkg is a bit stupid when it comes to dealing with dependencies on fixed versions (just like ipkg was):

ipkg update
ipkg upgrade busybox busybox-base busybox-links --force-depends

Then try launching mc with optware busybox ash subshell, and see that it works:

SHELL=/opt/bin/sh mc

If you want this to work with tomatousb shell, you'll have to ask Shibby to enable CONFIG_ASH_EXPAND_PRMT busybox config.

PiotrC1 commented 7 years ago

Hi @alllexx88! Thank you once again! In TomatoUSB by Shibby is the same version of busybox, as in optware-ng. The only difference is mentioned CONFIG_ASH_EXPAND_PRMT. I have asked Shibby to include it in newest version as well as /etc/shadow issue.

alllexx88 commented 7 years ago

@PiotrC1

Thank you once again!

No problem: it's been bugging me, so I made an effort to figure it out :smile:

In TomatoUSB by Shibby is the same version of busybox, as in optware-ng

The version in the latest Shibby build (138) is indeed the same (1.25.0), but configs (and hence the available applets) are quite different. However, the only things about busybox that matter here are:

  1. ash is used as the shell
  2. CONFIG_ASH_EXPAND_PRMT=y is set
  3. busybox isn't ancient: at least 1.20 -- to have printf 4-digit octal codes bug fixed, see here

So if Shibby fixes CONFIG_ASH_EXPAND_PRMT it'll be good

PiotrC1 commented 7 years ago

Hallo @alllexx88, the problem seems to be a little bit more complicated. If I set export SHELL=/foo then mc starts promptly but without subshell. If I set it to export SHELL=/bin/sh then I've got 10 seconds of delay. Colleagues from openlinksys.info have added CONFIG_ASH_EXPAND_PRMT=y to busybox configuration and compiled ARM image but still there is a 10 seconds delay.

alllexx88 commented 7 years ago

@PiotrC1

If I set export SHELL=/foo then mc starts promptly but without subshell.

SHELL=/foo is an unsupported shell, so it's not trying to do any subshell initialization.

Colleagues from openlinksys.info have added CONFIG_ASH_EXPAND_PRMT=y to busybox configuration and compiled ARM image but still there is a 10 seconds delay.

Optware-ng busybox package made mc behaved the same way, and it started to work as expected after setting CONFIG_ASH_EXPAND_PRMT=y. Give me the actual busybox config, and I can try it myself, otherwise this info is useless to me.

alllexx88 commented 7 years ago

@PiotrC1 You mean this config? I can try it with CONFIG_ASH_EXPAND_PRMT=y set

alllexx88 commented 7 years ago

@PiotrC1 OK, I tried, and it works as expected. I think there's something wrong with your colleagues build. A simple way to test if CONFIG_ASH_EXPAND_PRMT=y is really set is to run this command PS1='$(echo "# ")'. If the prompt looks like this after the command:

$(echo "# ")

Then it's off. It should look like this:

# 

In the config I used I only disabled deprecated 2.4 modutils stuff and emptied CONFIG_CROSS_COMPILER_PREFIX, everything else was unchanged.

(Removing config from here, since it's too long of a read)

PiotrC1 commented 7 years ago

I have passed all this information to TomatoUSB crew. Thanks for your investigations.

PiotrC1 commented 7 years ago

So, the guys have correctly configured compilation and now everything works perfectly - mc starts without delay (without extra bash or busybox installation). /etc/shadow will be corrected soon. Thanks again.