Ticket #3063 (new defect)

Opened 6 years ago

Last modified 4 years ago

subshell history is poisoned with cwd's in csh

Reported by: drookie Owned by:
Priority: major Milestone: Future Releases
Component: mc-core Version: 4.8.8
Keywords: Cc: iav@…
Blocked By: Blocking:
Branch state: no branch Votes for changeset:


% uname -a
FreeBSD bsdrookie.norma.com. 10.0-CURRENT FreeBSD 10.0-CURRENT #2 r251990M: Mon Jul 15 15:57:40 YEKT 2013 emz@….:/usr/obj/usr/src/sys/GENERIC amd64

% mc -V
GNU Midnight Commander 4.8.8
Built with GLib 2.34.3
Using the S-Lang library with terminfo database
With builtin Editor
With subshell support as default
With support for background operations
With mouse support on xterm
With support for X11 events
With internationalization support
With multiple codepages support
Virtual File Systems: cpiofs, tarfs, sfs, extfs, ftpfs, fish
Data types: char: 8; int: 32; long: 64; void *: 64; size_t: 64; off_t: 64;

% history

1 20:24 mc
2 20:24 cd "printf "%b" '\0057usr\0057home\0057drookie'"
3 20:24 set echo_style=both ; alias precmd 'echo $cwd:q >>/tmp/mc-drookie/mc.pipe.60740;kill -STOP $$'
4 20:24 cd "printf "%b" '\0057sbin'"
5 20:25 cd "printf "%b" '\0057usr\0057home\0057drookie\0057\0056config'"
6 20:25 cd "printf "%b" '\0057usr\0057home\0057drookie'"
7 20:25 cd "printf "%b" '\0057usr\0057home\0057drookie\0057\0056config\0057mc'"
8 20:25 cd "printf "%b" '\0057usr\0057home\0057drookie\0057\0056config'"
9 20:25 cd "printf "%b" '\0057usr\0057home\0057drookie'"

10 20:27 cd "printf "%b" '\0057usr\0057home\0057drookie'"
11 20:27 set echo_style=both ; alias precmd 'echo $cwd:q >>/tmp/mc-drookie/mc.pipe.74065;kill -STOP $$'
12 20:27 mc
13 20:27 cd "printf "%b" '\0057bin'"
14 20:27 ./chmod
15 21:52 cd "printf "%b" '\0057usr\0057home\0057drookie'"
16 21:52 set echo_style=both ; alias precmd 'echo $cwd:q >>/tmp/mc-drookie/mc.pipe.87093;kill -STOP $$'
17 21:52 mc
18 21:52 cd "printf "%b" '\0057usr\0057home\0057drookie'"
19 21:52 cd "printf "%b" '\0057usr\0057home\0057drookie'"
20 21:52 cd "printf "%b" '\0057usr\0057home\0057drookie'"
21 21:52 cd "printf "%b" '\0057usr\0057home\0057drookie'"
22 21:52 cd "printf "%b" '\0057usr\0057home\0057drookie'"
23 21:52 set echo_style=both ; alias precmd 'echo $cwd:q >>/tmp/mc-drookie/mc.pipe.87112;kill -STOP $$'
24 21:52 cd "printf "%b" '\0057usr\0057home\0057drookie'"
25 21:52 cd "printf "%b" '\0057usr\0057home\0057drookie'"
26 21:52 cd "printf "%b" '\0057usr\0057home\0057drookie'"
27 21:53 cd "printf "%b" '\0057usr\0057home\0057drookie\0057\0056cache'"
28 21:53 cd "printf "%b" '\0057usr\0057home\0057drookie'"
29 21:53 cd "printf "%b" '\0057usr\0057home\0057drookie'"
30 21:56 uname -a
31 21:56 mc -V
32 21:56 unset LANG
33 21:56 mc -V
34 21:56 set
35 21:57 unsetenv LANG
36 21:57 mc -V
37 21:57 history


So, when I press up/down arrows this stuff appears in my CLI. This works fine under Linux/Solaris?, but obviously, not FreeBSD.

I tried different shell with same result.

Change History

comment:1 Changed 6 years ago by drookie

  • Summary changed from subshell records all kinds of weird stuff to subshell records all kinds of weird stuff in csh

Update: this acually works fine under bash, but when user's shell is csh, setting HISTCONTROL in any form doesn't help.

comment:2 Changed 6 years ago by drookie

  • Summary changed from subshell records all kinds of weird stuff in csh to subshell history is poisoned with cwd's in csh

comment:3 in reply to: ↑ description Changed 6 years ago by Klimontov

I have a similar situation.
OS: RHEL 6.4, OpenSuse? 12.3

There is a bit information in #2104

Last edited 6 years ago by Klimontov (previous) (diff)

comment:4 Changed 6 years ago by Klimontov

Although we have a slightly different problem. Subshell cmd is not cleaned ​​when switching panels in mc.
And works next case:

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.

Therefore, we propose next. Send ctrl+u for cleaning bash cmd.

diff --git a/subshell1.c b/subshell.c
index b36fbbc..5886b87 100644
--- a/subshell1.c
+++ b/subshell.c
@@ -1168,6 +1168,9 @@ do_subshell_chdir (const vfs_path_t * vpath, gboolean update_prompt)
         g_free (pcwd);
+       if(subshell_type == BASH)
+               write_all (mc_global.tty.subshell_pty, &shell_mode.c_cc[VKILL], sizeof(shell_mode.c_cc[VKILL]));

     /* The initial space keeps this out of the command history (in bash
        because we set "HISTCONTROL=ignorespace") */

comment:5 Changed 5 years ago by andrew_b

When mc starts, it creates the child process (the subshell) using fork(2). From this moment, we have two independent processes: mc itself and mc's subshell. In order to synchronize current working directory in both processes, mc sends "cd path" command to subshell. There is no way other than sending command from first process to second one to change some internal state of second process.

Subshell receives the "cd path" command. Since it is a command, it is stored in subshell's history. Bash and zsh provide some ways to exclude some commands being stored in history: HISTCONTROL=ignorespace in bash, HIST_IGNORE_SPACE in zsh (see #3124 for some details). Unfortunately, csh doesn't.

I'm not quite sure that there is some simple way to fix this bug.

Last edited 5 years ago by andrew_b (previous) (diff)

comment:6 Changed 5 years ago by iav

  • Cc iav@… added

comment:7 Changed 5 years ago by drookie

Okay, thanks for an explanation. It took some time to accept this. Now I'm migrating to zsh after 14 years of csh'ing. :P I think this may be closed as "won't fix" or something similar.

comment:8 Changed 4 years ago by zaytsev

Moved discussion re. subshell clearing to Ticket #3486.

Note: See TracTickets for help on using tickets.