Ticket #2110 (closed defect: fixed)
unexpected subshell execution
Reported by: | adminX | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 4.8.26 |
Component: | mc-core | Version: | master |
Keywords: | Cc: | mc-trac@…, zaytsev, ossi@…, onlyjob@… | |
Blocked By: | Blocking: | ||
Branch state: | no branch | Votes for changeset: |
Description
run mc
have somedir in the current panel and your home in the other panel.
Press <Ctrl-O> to get a subshell
Enter a command with trailing space
Press <Ctrl-O> to get back to mc and switch to the other panel.
This will execute the entered command with additonals parameters cd and your home.
This also works by changing directory in current panel.
I think this is a bug as accidentally executing long running commands, never ending commands like cat or evil commands like rm -rf should not happen.
This bug was introduced in #213.
Change History
comment:2 Changed 15 years ago by zaytsev
- Cc zaytsev added
Unfortunately, I have also stumbled upon this issue quite a few times. My vote here.
comment:3 Changed 14 years ago by andrew_b
- Version changed from version not selected to master
See also #2269.
comment:5 Changed 14 years ago by jmak
'The shell is already running a command' was annoying, but this "solution" only calls for shooting oneself in the foot. I just managed to make a svn commit with a bogus message only because I wanted to review something before smashing enter.
I added -u to mc's parameters. Executing commands without user's content, and with bogus arguments is just too dangerous.
comment:6 Changed 13 years ago by andrew_b
- Branch state set to no branch
- Milestone changed from 4.7 to Future Releases
comment:9 Changed 11 years ago by ossi
an attempt to fix the problem properly was made at https://mail.gnome.org/archives/mc-devel/2004-November/msg00199.html
another related thread is https://mail.gnome.org/archives/mc-devel/2006-July/msg00013.html
comment:10 Changed 11 years ago by ossi
fwiw, there is also https://mail.gnome.org/archives/mc-devel/2006-May/msg00030.html which contains a somewhat related patch that should be looked at.
comment:11 Changed 10 years ago by onlyjob
In the https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=703741#16
Dmitry Borisyuk proposed the following patch:
A simple solution for this problem is to send C-k C-u to the shell
before sending 'cd' command, which will erase previous unfinished text
(C-k is needed for bash if the cursor is in the middle of the line).
I've tried the following patch with bash, zsh and tcsh and it works fine.
--- a/src/subshell.c +++ b/src/subshell.c @@ -1190,7 +1190,7 @@ /* The initial space keeps this out of the command history (in bash because we set "HISTCONTROL=ignorespace") */ - write_all (mc_global.tty.subshell_pty, " cd ", 4); + write_all (mc_global.tty.subshell_pty, "\013\025 cd ", 6); directory = vfs_path_to_str (vpath); if (directory != '\0')
Please review.
comment:12 Changed 10 years ago by ossi
as a band-aid, the idea isn't bad.
note that the order c-k c-u is important, as a plain tty (as used by ash, for example) will not interpret c-k (but it will interpret c-u).
however, i don't consider this a real solution - it's destructive, after all.
imo, the original patch should be reverted, and a more robust way of detecting shell idleness devised. that could be probably done by looking closer at the shell's tty output, so we can actually know when nothing is on the prompt.
comment:13 Changed 9 years ago by and
summary subshell
mc open one (sub)shell for read/write (subshell_pty)
mc open one fifo for reading by mc and writing by (sub)shell (subshell_pipe)
mc init (sub)shell interpeter with custom precmd shell code
precmd is triggered at each (sub)shell prompt (doing by shell interpreter)
precmd writes CWD info to given fifo (subshell_pipe)
mc subshell is always running
mc subshell can be visible/invisible (aka Crtl-o aka subshell_state?)
subshell_ready state?
after (sub)shell init, mc can send command to (sub)shell itself
for example string " cd " will send when panel toggles
This can be bad because mc cannot see if (sub)shell is ready to accept next shell cmds
for example shells can have page-completions which except certain input response (#2269)
now toggle panel, mc write "cd" to issue precmd but no new fifo data arrived, BOOM.
It must be prevented that mc write shell commands itself in unclear situations.
What is a unclear situation?
- user input sended to (sub)shell, no fifo/CWD data arrived yet
What is a clear situation?
- (sub)shell init done and fifo/CWD data just arrived, no user input sended to (sub)shell yet
- fifo/CWD data arrived and no user input sended to (sub)shell yet
proposal:
- subshell_init_done flag TRUE/FALSE
- TRUE: init process complete (with optional "cd" test successful)
- FALSE: init process not done yet (will block all mc subshell user functions)
- subshell_visible flag TRUE/FALSE
- TRUE: (sub)shell visible
- FALSE mc panels visible
- subshell_busy flag TRUE/FALSE
- TRUE: user input sended
- FALSE: fifo/CWD received
- toggle panel
- subshell_busy=TRUE:
- no mc data aka "cd" send to (sub)shell
- when user enter data for (sub)shell inform user with a msgbox
- subshell_busy=FALSE:
- mc issue "cd" command
- send user data to (sub)shell if available (and set subshell_busy=TRUE)
- subshell_busy=TRUE:
- reading fifo/CWD
- after reading fifo/CWD set subshell_busy=FALSE
- after fresh (sub)shell init do a test "cd" cmd to detect if fifo/CWD working properly if not, give up (sub)shell handling earlier than later
What I miss?
comment:15 Changed 4 years ago by andrew_b
- Blocked By 4114 removed
(In #4114) Merged to master: [c22387d433bbca5470610f500f8fe01eb77e5f57].
comment:16 Changed 4 years ago by andrew_b
- Status changed from new to closed
- Resolution set to fixed
- Milestone changed from Future Releases to 4.8.26
comment:17 Changed 4 years ago by andrew_b
Fixed in #4114.