Ticket #2104 (closed defect: invalid)

Opened 4 years ago

Last modified 10 months ago

using subshell makes bash clobber its history with some PS1-related (?) junk

Reported by: doktornotor Owned by:
Priority: major Milestone: 4.7
Component: mc-core Version: 4.7.1
Keywords: Cc: mc-trac@…
Blocked By: Blocking:
Branch state: no branch Votes for changeset:

Description

E.g., if I type cd /usr/portage/distfiles into a subshell in , the folloging will get logged:

cd "printf "%b" '\0057'"
cd "printf "%b" '\0057usr'"
cd "printf "%b" '\0057usr\0057portage'"
cd "printf "%b" '\0057usr\0057portage\0057distfiles'"
cd "printf "%b" '\0057'"

The above is on Gentoo.

On FreeBSD, junk gets logged as well, e.g. cd /var/log produces:

#+1267704528
cd "printf "%b" '\0057var'"
#+1267704528
cd "printf "%b" '\0057var\0057log'"

Have had this problem for ages, valid with any app-misc/mc version incl. the latest masked 4.7.1. Happens semi-randomly and usually doesn't happen if I press Enter before typing into the subshell.

Reproduced on Gentoo and FreeBSD, have had this issue for ages. Currently using bash-4.1_p2 but as said above, it doesn't matter, been so for a long time.

Related downstream bug: http://bugs.gentoo.org/show_bug.cgi?id=309261

In case it matters:

$ echo $PS1
\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]

If you need something else, let me know :)

Attachments

subshell.diff (717 bytes) - added by Klimontov 10 months ago.
subshell.2.diff (717 bytes) - added by Klimontov 10 months ago.

Change History

comment:1 follow-up: ↓ 2 Changed 4 years ago by angel_il

IMHO this bug is by-effect of #213

comment:2 in reply to: ↑ 1 ; follow-up: ↓ 3 Changed 4 years ago by adminX

Replying to angel_il:

IMHO this bug is by-effect of #213

It is not only a side-effect of #213 but enables you to all sorts of bad things.

example:

run mc
have somedir in the current panel and your home in the other panel.
Press <Ctrl-O> to get a subshell
Enter rm -rf with trailing space
Press <Ctrl-O> to get back to mc and press <Tab> or <Ctrl-I> to get into the other panel.
This will remove everything in somedir/cd and / or whatever directory was current to the other panel.

comment:3 in reply to: ↑ 2 Changed 4 years ago by doktornotor

Replying to adminX:

run mc
have somedir in the current panel and your home in the other panel.
Press <Ctrl-O> to get a subshell
Enter rm -rf with trailing space
Press <Ctrl-O> to get back to mc and press <Tab> or <Ctrl-I> to get into the other panel.
This will remove everything in somedir/cd and / or whatever directory was current to the other panel.

Yikes, indeed... :/ Well, this one really sucks.

comment:4 Changed 4 years ago by adminX

  • Cc mc-trac@… added

After getting some sleep and another look at the patch the bug report itself is not a side-effect of #213. #213 only enables you to accidentally execute unexpected commands. The execution of the commands mentioned in the bug report are needed to change the subshell to the correct directory.

I think it is impossible to remove them and keep the subshell and current panel directories in sync without feeding some sort of command to the subshell.
Without subshell it works fine as there is no need to change the current working directory of a running shell.

comment:5 Changed 4 years ago by doktornotor

Hello... I probably was not clear enough. This is NOT about cd only... E.g. pwd does the same thing. Worse yet, it is NOT needed to type cd or any other command manually, simply switching to another dir on the second pane, using (or merely switching to) a subshell there, going back tu first pane and using subshell there spams bash history with tons of junk. E.g., have /usr in first panel, /tmp in second and do the above, you'll get:

cd "printf "%b" '\0057'"
cd "printf "%b" '\0057tmp'"

echo

cd "printf "%b" '\0057usr'"

I don't know whether you realize the severity of the problem, because it currently makes my bash history practically unusable.

$ grep printf ~/.bash_history | wc -l
6709

And there's another thing:

$ grep PROMPT_COMMAND .bash_history | wc -l
174

but that's probably #2027 more than this.

comment:6 Changed 4 years ago by adminX

Logging of Midnight Commander's cd and PROMPT_COMMAND lines happens if $HISTCONTROL is unset or otherwise not set to ignorespace or ignoreboth.
HISTCONTROL=ignorespace is set by default in MC but may be overriden in ~/.mc/bashrc or ~/.bashrc or any file included from there.

#2027 has the problem in the other direction as MC overwrites the variable after starting bash.

comment:7 follow-up: ↓ 8 Changed 4 years ago by doktornotor

Hmmm... I don't think this is the case.

$ echo $HISTCONTROL
ignorespace ignoredups

on all boxes where I experience this issue. So, HISTCONTROL won't help here. Meanwhile, export HISTIGNORE='cd "\`printf*' will work around logging most of the noise but that's obviously not a real solution.

comment:8 in reply to: ↑ 7 Changed 4 years ago by ossi

Replying to doktornotor:

$ echo $HISTCONTROL
ignorespace ignoredups

this is wrong. the separator is a colon.

comment:9 Changed 4 years ago by doktornotor

Oh well, a lot if misunderstanding here apparently. So - the above is what bash spits out as ENV variable, so wrt separators you need to talk to bash upstream.

$ grep HISTCONTROL $HOME/.bashrc
export HISTCONTROL="ignoreboth"

comment:10 Changed 4 years ago by adminX

$HISTCONTROL is evaluated every time a command is executed.

Your export HISTCONTROL="ignoreboth" in ~/.bashrc seems to be overridden by a sourced script.

comment:11 Changed 4 years ago by doktornotor

Well... indeed, figured out. This all junk was caused by sourcing a stale mc.sh wrapper in .bashrc which in turn sourced another stale mc-wrapper.sh which attempted to append stuff to $HISTCONTROL in a broken way. From where did those stale files come - no idea *g*

So, thanks for help and close this, and sorry for wasting your time.

comment:12 Changed 4 years ago by slavazanko

  • Status changed from new to closed
  • Resolution set to invalid

Added answer into FAQ:

http://www.midnight-commander.org/wiki/doc/faq#a6.8Iseelotofstrangecdprintflinesintomy.historyfile

If answer in FAQ not clean - keep comments here.

comment:13 Changed 4 years ago by doktornotor

Pretty clean and clear to me... Hopefully this saves other people some trouble. Thanks again. ;)

comment:14 Changed 11 months ago by Klimontov

  • Branch state set to no branch

Hello guys!
Take in account, there is issue. Condition is reproduced and this is very very bad.

Replying to adminX:

run mc
have somedir in the current panel and your home in the other panel.
Press <Ctrl-O> to get a subshell
Enter rm -rf with trailing space
Press <Ctrl-O> to get back to mc and press <Tab> or <Ctrl-I> to get into the other panel.

Changed 10 months ago by Klimontov

Changed 10 months ago by Klimontov

comment:15 Changed 10 months ago by Klimontov

Hello again.
I am can propose next fix. This is not very good solve, but you can modify him better.

See Attached: subshell.diff​

comment:16 Changed 10 months ago by andrew_b

Well, patches in the closed ticket is not good idea. :)

About patch.

if (strstr (mc_global.tty.shell, "/bash") || getenv ("BASH"))

This is overkill. I (and most bush users) don't have this problem. But this bug is reproducible with (t)csh: #3063. But I personally not so familiar with various shell internals to 1) know what and why this happens exactly and 2) fix this correctly.

Note: See TracTickets for help on using tickets.