Ticket #3121 (reopened defect) — at Version 21

Opened 11 years ago

Last modified 21 months ago

Subshell/Command line prompt is empty/missing

Reported by: z0rc Owned by:
Priority: major Milestone: 4.8.30
Component: mc-core Version: 4.8.28
Keywords: subshell Cc: egmont@…, congest, aurrak, reagle, tonal.promsoft@…
Blocked By: Blocking:
Branch state: merged Votes for changeset:

Description (last modified by andrew_b) (diff)

See attached screenshot. The issue persist with TERM=(xterm|screen).*. Tested with konsole and xterm both on current Debian Sid, Ubuntu 12.04 and Ubuntu 13.10. Tested with bash and zsh. The issue doesn't exists with 'linux' terminal (without xorg, plain console at Ctrl+Alt+F1)

mc -V
GNU Midnight Commander 4.8.11
Built with GLib 2.36.4
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 and Linux console
With support for X11 events
With internationalization support
With multiple codepages support
Virtual File Systems: cpiofs, tarfs, sfs, extfs, ext2undelfs, ftpfs, sftpfs, fish
Data types: char: 8; int: 32; long: 64; void *: 64; size_t: 64; off_t: 64;

I bisected issue to:

e35f044ccdd41922f925c99e6d50930ea8c7c47e is the first bad commit
commit e35f044ccdd41922f925c99e6d50930ea8c7c47e
Author: Andrew Borodin <aborodin@vmail.ru>
Date:   Tue Jan 1 19:53:11 2013 +0400

    (subshell_prompt): changed to GString.
    
    (read_subshell_prompt): refactoring to ret rid of low-level memory reallocation.
    
    Signed-off-by: Andrew Borodin <aborodin@vmail.ru>

Change History

Changed 11 years ago by z0rc

comment:1 Changed 11 years ago by andrew_b

Sorry, but I'm unable reproduce this bug.

comment:2 Changed 11 years ago by andrew_b

  • Cc aborodin@… removed
  • Version changed from master to 4.8.11
  • Component changed from mc-tty to mc-core

comment:3 Changed 11 years ago by andrew_b

Ok, let step by step.

Is it happened immediately after start or after any actions?
What is your $PS1?
Does your $PS1 depend on your $TERM value or any other condition?

comment:4 Changed 11 years ago by z0rc

OK, I've made additional tests. I was wrong about bash, it happens only with zsh. $PS1 is irrelevant as see this behavior with empty zshrc. Though it happens, but not so often. Usually this happens with mc start and the prompt may appear on dir change ...or may not. From my perspective it's more like race condition somewhere and the heavier my zshrc, the often it happens.

Just in case you can check my zshrc at https://github.com/z0rc/dotfiles/blob/master/zshrc.

I'll try to dig into gdb later this week.

comment:5 follow-up: ↓ 7 Changed 11 years ago by egmont

I can't reproduce, just looking at the code, but line 1022: g_string_set_size (subshell_prompt, 0) is fishy, it's inside the while(select(...)) loop that takes care of assembling multiple short reads, but I guess it should be before that loop.

comment:6 Changed 11 years ago by egmont

  • Cc egmont@… added

comment:7 in reply to: ↑ 5 Changed 11 years ago by andrew_b

Replying to egmont:

I can't reproduce, just looking at the code, but line 1022: g_string_set_size (subshell_prompt, 0) is fishy, it's inside the while(select(...)) loop that takes care of assembling multiple short reads, but I guess it should be before that loop.

This was fixed in #3001.

comment:8 follow-up: ↓ 9 Changed 11 years ago by z0rc

I'm continuing my investigation. Current situation:

Breakpoint 3, setup_cmdline () at layout.c:816
816     {
(gdb) bt full
#0  setup_cmdline () at layout.c:816
        prompt_len = <optimized out>
        y = <optimized out>
        tmp_prompt = <optimized out>
#1  0x0000000000436752 in do_load_prompt () at layout.c:1328
        ret = <optimized out>
#2  0x0000000000436779 in load_prompt (fd=<optimized out>, unused=<optimized out>) at layout.c:1350
No locals.
#3  0x00000000004334b0 in check_selects (select_set=select_set@entry=0x7fffffffcf40) at key.c:592
        p = 0x7ff1a0
#4  0x0000000000434a78 in check_selects (select_set=0x7fffffffcf40) at key.c:559
No locals.
#5  tty_get_event (event=event@entry=0x7fffffffd000, redo_event=0, block=block@entry=1) at key.c:2069
        nfd = <optimized out>
        select_set = {fds_bits = {0 <repeats 16 times>}}
        c = <optimized out>
        flag = 1
        time_out = {tv_sec = 8375264, tv_usec = 0}
        time_addr = <optimized out>
        dirty = 1
#6  0x000000000041a417 in frontend_dlg_run (h=0x7fb640) at dialog.c:567
        d_key = <optimized out>
        event = {buttons = 0, x = -1, y = 13, type = (GPM_UP | GPM_DOUBLE)}
#7  dlg_run (h=0x7fb640) at dialog.c:1256
No locals.
#8  0x000000000043bdf5 in create_panels_and_run_mc () at midnight.c:959
No locals.
#9  do_nc () at midnight.c:1774
        ret = <optimized out>
        midnight_colors = {1, 1, 1, 1, 1}
#10 0x000000000040a065 in main (argc=1, argv=0x7fffffffd288) at main.c:400
        error = 0x0
        config_migrated = 0
        config_migrate_msg = 0x7ffff7ffe5c0 " \345\377\367\377\177"
        exit_code = 1
(gdb) print subshell_prompt->str
$23 = (gchar *) 0x823c60 "\033[0m\033[27m\033[24m\033[J[mc][\033[01;33mkoumakan\033[00m][\033[01;32m~/rebuild\033[00m]% \033[K"
(gdb) cont
Continuing.

Breakpoint 3, setup_cmdline () at layout.c:816
816     {
(gdb) bt full
#0  setup_cmdline () at layout.c:816
        prompt_len = <optimized out>
        y = <optimized out>
        tmp_prompt = <optimized out>
#1  0x0000000000436752 in do_load_prompt () at layout.c:1328
        ret = <optimized out>
#2  0x0000000000436779 in load_prompt (fd=<optimized out>, unused=<optimized out>) at layout.c:1350
No locals.
#3  0x00000000004334b0 in check_selects (select_set=select_set@entry=0x7fffffffcf40) at key.c:592
        p = 0x7ff1a0
#4  0x0000000000434a78 in check_selects (select_set=0x7fffffffcf40) at key.c:559
No locals.
#5  tty_get_event (event=event@entry=0x7fffffffd000, redo_event=0, block=block@entry=1) at key.c:2069
        nfd = <optimized out>
        select_set = {fds_bits = {0 <repeats 16 times>}}
        c = <optimized out>
        flag = 1
        time_out = {tv_sec = 8375264, tv_usec = 0}
        time_addr = <optimized out>
        dirty = 1
#6  0x000000000041a417 in frontend_dlg_run (h=0x7fb640) at dialog.c:567
        d_key = <optimized out>
        event = {buttons = 0, x = -1, y = 13, type = (GPM_UP | GPM_DOUBLE)}
#7  dlg_run (h=0x7fb640) at dialog.c:1256
No locals.
#8  0x000000000043bdf5 in create_panels_and_run_mc () at midnight.c:959
No locals.
#9  do_nc () at midnight.c:1774
        ret = <optimized out>
        midnight_colors = {1, 1, 1, 1, 1}
#10 0x000000000040a065 in main (argc=1, argv=0x7fffffffd288) at main.c:400
        error = 0x0
        config_migrated = 0
        config_migrate_msg = 0x7ffff7ffe5c0 " \345\377\367\377\177"
        exit_code = 1
(gdb) print subshell_prompt->str
$24 = (gchar *) 0x802ce0 "\033[?1h\033="

This is strange as at directory change we enter setup_cmdline two times, first enter with correct prompt, second with bogus. At second break I can see the valid prompt in mc, which later gets changed to nothing. I'll continue to dig this up. If you have any hints, please share.

comment:9 in reply to: ↑ 8 Changed 11 years ago by andrew_b

I think you should check subshell_prompt in read_subshell_prompt().

comment:10 Changed 11 years ago by z0rc

Please close this as invalid. It appears my problem after all. Though it wasn't obvious to spot. Basically zsh has two prompts: left and right, mc was interpreting both of them. I had an option to set RPROMPT to be "" (empty string) if zsh is running under mc, it was working just fine. Right now I have to completely undefine RPROMPT, so mc won't interpret it.

comment:11 Changed 11 years ago by andrew_b

  • Status changed from new to closed
  • Resolution set to invalid
  • Milestone Future Releases deleted

comment:12 Changed 11 years ago by z0rc

  • Status changed from closed to reopened
  • Resolution invalid deleted
  • Milestone set to Future Releases

I spoke to soon and reopening this ticket. Sorry.

RPROMPT has nothing to do with this as it won't affect the situation, as I though initially. "\033[?1h\033=" is present always, event when RPROMPT isn't set. This looks like mark of prompt end, as they present event with empty PROMPT.

I still think this is some kind of race condition. I can catch empty prompt comes after valid when setting up just watch on subshell_prompt variable. But when I break on read_subshell_prompt the empty shell won't appear and issue won't show up. Also I cannot catch issue under strace, then mc behaves just fine.

comment:13 Changed 11 years ago by andrew_b

  • Blocked By 3125 added

comment:14 Changed 11 years ago by andrew_b

  • Blocked By 3125 removed

comment:15 Changed 11 years ago by andrew_b

  • Status changed from reopened to closed
  • Resolution set to fixed
  • Milestone changed from Future Releases to 4.8.12

Changed 5 years ago by xor512

/etc/skel/.zshrc from manjaro-zsh-config package

Changed 5 years ago by xor512

no prompt (happens after typing ls -> enter several times)

Changed 5 years ago by xor512

.zshrc from manjaro forum which probably do not depend on manjaro-zsh-config package and can be probably used on plain Arch

comment:16 Changed 5 years ago by xor512

  • Status changed from closed to reopened
  • Resolution fixed deleted

This still happens with config from manjaro-zsh-config package in 5.4.15-2-MANJARO. The prompt is approx. 9 out of 10 times there but once in a while after typing a command (like ls) it is gone. To bring it back one has to type some command again (one or more times).

This is the standard config from manjaro-zsh-config and can be found in /etc/skel/.zshrc after installing manjaro-zsh-config package.

I've created a topic on a forum: https://forum.manjaro.org/t/prompt-disappears-in-zsh-mc-after-typing-comands-sometimes/122552 but I think this may be also an issue with mc vs zsh, which is to be fixed in mc.

To reproduce the issue one should use the config attached https://midnight-commander.org/attachment/ticket/3121/.zshrc (I'm not sure it will work without the full manjaro-zsh-config package though and that this package can be installed on plain Arch easily, however the issue is also reproducible with the another config: https://forum.manjaro.org/t/unstable-manjaro-zsh-config/17899/105 (which seems to be not "Manjaro-specific" and is attached as https://midnight-commander.org/attachment/ticket/3121/.zshrc_arch) and then type "ls -> enter > ls -> enter..." until prompt is gone. This does not always happen but often enough (1 times out of 10 approx). By "does not always happen" I mean that it always happens if you will type "ls -> enter" enough for it to happen. But how many times one has to do it is random. I confirm that it seems like a race condition. It does not happen without .zshrc file at all.

I'm using xfce4-terminal, but this also happens in xterm (see https://midnight-commander.org/attachment/ticket/3121/prompt_sometimes_disappears.png).

I have a workaround for this based on the comment: https://midnight-commander.org/ticket/3121?cnum_edit=16#comment:10 in .zshrc:

# mc f... up prompt (it disappears after running commands) sometimes for some reason
if ps $PPID | grep mc; then
    # this removes git_prompt_string cool stuff but I have no other solution for now
    RPROMPT=""
fi

but this removes some goodies one make for git in RPROMPT.

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

comment:17 follow-up: ↓ 19 Changed 3 years ago by kvaster

I'm using zsh with mc and I have disabled rprompt for mc. But I still have empty prompt sometimes. It seems that zsh adds empty line from time to time. There is already check in mc in set_prompt_string function, but zsh adds empty line with escape sequences. I've created simple UGLY patch and now prompt works as expected with zsh and git goodies:

diff --git a/src/subshell/common.c b/src/subshell/common.c
index 65f5718..5b5162f 100644
--- a/src/subshell/common.c
+++ b/src/subshell/common.c
@@ -724,10 +724,30 @@ parse_subshell_prompt_string (const char *buffer, int bytes)
 static void
 set_prompt_string (void)
 {
+    int m, i;
+
     if (mc_global.mc_run_mode != MC_RUN_FULL)
         return;

-    if (subshell_prompt_temp_buffer->len != 0)
+    m = 0;
+    for (i = 0; i < subshell_prompt_temp_buffer->len; i++) {
+        char c = subshell_prompt_temp_buffer->str[i];
+        if (c == 27) {
+            m = 2;
+        } else if (m == 0) {
+            m = 1;
+            break;
+        } else if (m == 2) {
+            m = c == '[' ? 3 : 0;
+        } else if (m == 3) {
+            m = c == '?' ? 4 : 0;
+        } else if (m == 4) {
+            if (c < '0' || c > '9')
+                m = 0;
+        }
+    }
+
+    if (m == 1)
         g_string_assign (subshell_prompt, subshell_prompt_temp_buffer->str);

     setup_cmdline ();

comment:18 Changed 3 years ago by zaytsev

  • Cc congest, aurrak, reagle added

Could this be the solution for the zsh problem in #4198 ?

comment:19 in reply to: ↑ 17 Changed 3 years ago by andrew_b

Replying to kvaster:

I've created simple UGLY patch and now prompt works as expected with zsh and git goodies:

It would be great if you provide more or less detailed description about your code.

comment:20 Changed 3 years ago by andrew_b

It seems to me that patch in comment:17 does the same as function strip_ctrl_codes().

comment:21 Changed 3 years ago by andrew_b

  • Description modified (diff)
  • Milestone changed from 4.8.12 to Future Releases

Related to #4258.

Note: See TracTickets for help on using tickets.