Ticket #4253 (new defect)

Opened 3 years ago

Last modified 3 years ago

subshell/common.c/init_subshell interferes with read in .zshrc causing 10 second mc startup delay

Reported by: marlonrichert Owned by:
Priority: major Milestone: Future Releases
Component: mc-core Version: 4.8.26
Keywords: subshell common.c init_subshell zsh .zshrc Cc: baltazar.bz@…
Blocked By: Blocking:
Branch state: no branch Votes for changeset:

Description

Steps to reproduce

$ cd $(mktemp -d); exec env -i HOME=$PWD TERM=$TERM zsh -f 
% print -r "typeset -F SECONDS
print -nr \$'\e[6n'  # We query the terminal for info.
IFS=\$'\e[;' read -Asd R -- reply  # We read the terminal's reply.
print \$SECONDS
" > .zshrc
% exec zsh  # Starting zsh is still instantaneous.
0.0557880000
% SECONDS=0; mc; print $SECONDS  # Starting mc is now really slow.

11.5728380000
%

The problem is here: https://github.com/MidnightCommander/mc/blob/a88a626e76139259e5b6fc0db39045f051e243dd/src/subshell/common.c#L1378

You print commands to the shell as if it were user input or terminal input. This interferes with the read statement in the .zshrc file: The terminal's reply is now buried inside the characters you are printing. As a result, the read statement hangs until it times out and most of the commands you print don't get executed.

Expected behavior

Don't print to the shell. If you want to execute commands, just pass them straight to Zsh by using the -c flag. See https://zsh.sourceforge.io/Doc/Release/Invocation.html#Invocation-2

mc debug info

% LC_MESSAGES=C mc -F
Home directory: /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX
Profile root directory: /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX

[System data]
    Config directory: /usr/local/Cellar/midnight-commander/4.8.26/etc/mc/
    Data directory:   /usr/local/Cellar/midnight-commander/4.8.26/share/mc/
    File extension handlers: /usr/local/Cellar/midnight-commander/4.8.26/libexec/mc/ext.d/
    VFS plugins and scripts: /usr/local/Cellar/midnight-commander/4.8.26/libexec/mc/
        extfs.d:        /usr/local/Cellar/midnight-commander/4.8.26/libexec/mc/extfs.d/
        fish:           /usr/local/Cellar/midnight-commander/4.8.26/libexec/mc/fish/

[User data]
    Config directory: /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.config/mc/
    Data directory:   /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.local/share/mc/
        skins:          /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.local/share/mc/skins/
        extfs.d:        /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.local/share/mc/extfs.d/
        fish:           /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.local/share/mc/fish/
        mcedit macros:  /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.local/share/mc/mc.macros
        mcedit external macros: /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.local/share/mc/mcedit/macros.d/macro.*
    Cache directory:  /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.cache/mc/
% LC_MESSAGES=C mc -F
mc --configure-options
Home directory: /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX
Profile root directory: /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX

[System data]
    Config directory: /usr/local/Cellar/midnight-commander/4.8.26/etc/mc/
    Data directory:   /usr/local/Cellar/midnight-commander/4.8.26/share/mc/
    File extension handlers: /usr/local/Cellar/midnight-commander/4.8.26/libexec/mc/ext.d/
    VFS plugins and scripts: /usr/local/Cellar/midnight-commander/4.8.26/libexec/mc/
        extfs.d:        /usr/local/Cellar/midnight-commander/4.8.26/libexec/mc/extfs.d/
        fish:           /usr/local/Cellar/midnight-commander/4.8.26/libexec/mc/fish/

[User data]
    Config directory: /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.config/mc/
    Data directory:   /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.local/share/mc/
        skins:          /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.local/share/mc/skins/
        extfs.d:        /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.local/share/mc/extfs.d/
        fish:           /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.local/share/mc/fish/
        mcedit macros:  /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.local/share/mc/mc.macros
        mcedit external macros: /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.local/share/mc/mcedit/macros.d/macro.*
    Cache directory:  /private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.J1v4nVJX/.cache/mc/
 '--disable-debug' '--disable-dependency-tracking' '--disable-silent-rules' '--prefix=/usr/local/Cellar/midnight-commander/4.8.26' '--without-x' '--with-screen=slang' '--enable-vfs-sftp' 'CC=clang' 'PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig:/usr/local/opt/pcre/lib/pkgconfig:/usr/local/opt/openssl@1.1/lib/pkgconfig:/usr/local/opt/readline/lib/pkgconfig:/usr/local/opt/sqlite/lib/pkgconfig:/usr/local/opt/tcl-tk/lib/pkgconfig:/usr/local/opt/xz/lib/pkgconfig:/usr/local/opt/python@3.9/lib/pkgconfig:/usr/local/opt/glib/lib/pkgconfig:/usr/local/opt/libssh2/lib/pkgconfig:/usr/local/opt/libpng/lib/pkgconfig:/usr/local/opt/s-lang/lib/pkgconfig' 'PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/11'
% mc -V
GNU Midnight Commander 4.8.26
Built with GLib 2.66.4
Built with S-Lang 2.3.2 with terminfo database
With builtin Editor
With subshell support as default
With support for background operations
With mouse support on xterm
With internationalization support
With multiple codepages support
Virtual File Systems:
 cpiofs, tarfs, sfs, extfs, ftpfs, sftpfs, fish
Data types:
 char: 8; int: 32; long: 64; void *: 64; size_t: 64; off_t: 64;

Change History

comment:1 Changed 3 years ago by marlonrichert

  • Keywords zsh .zshrc added
  • Summary changed from `mc` interferes with `read` in `.zshrc` causing 10 second `mc` startup delay to `subshell/common.c` interferes with `read` in `.zshrc` causing 10 second `mc` startup delay

comment:2 Changed 3 years ago by marlonrichert

  • Keywords init_subshell added
  • Summary changed from `subshell/common.c` interferes with `read` in `.zshrc` causing 10 second `mc` startup delay to `subshell/common.c/init_subshell` interferes with `read` in `.zshrc` causing 10 second `mc` startup delay

comment:3 Changed 3 years ago by balta2ar

  • Cc baltazar.bz@… added

comment:4 Changed 3 years ago by andrew_b

Looks like duplicate of #3580.

comment:5 Changed 3 years ago by ossi

no. there, a "naturally slow" startup of the shell is just exposed by mc. here, we're talking about active interference with the script's own bi-directional communication with the tty.

this problem could be avoided by wrapping the invoked init script into an own script that outputs a readiness indicator for synchronization purposes, like "<< MC subshell READY! >>>".

any one-time initialization commands could be injected this way as well (though the traditional method would still have be used for shells with no init file support, but the paths are shell-specific anyway).

generally, i'd recommend doing as much of the protocol as possible over the auxiliary pipes which we now have anyway.

comment:6 Changed 3 years ago by marlonrichert

  • Summary changed from `subshell/common.c/init_subshell` interferes with `read` in `.zshrc` causing 10 second `mc` startup delay to subshell/common.c/init_subshell interferes with read in .zshrc causing 10 second mc startup delay

comment:7 Changed 3 years ago by ossi

speaking of using a wrapper script, that should be seen in the context of #4254.

Note: See TracTickets for help on using tickets.