Bug 253831 - misc/mc More than 1 copy of mc application does not start in sysutils/screen
Summary: misc/mc More than 1 copy of mc application does not start in sysutils/screen
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Alexey Dokuchaev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-24 22:42 UTC by Vladyslav V. Prodan
Modified: 2024-09-18 17:45 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladyslav V. Prodan 2021-02-24 22:42:42 UTC
More than 1 copy of mc application does not start in sysutils/screen.

Runs only in -U mode (--nosubshell)

Using gdb, I got an approximate reason for the application crash. 
(gdb) where
#0  0x00000008009b3f4f in strlen () from /lib/libc.so.7
#1  0x000000000027788e in ?? ()
#2  0x0000000000276d6c in ?? ()
#3  0x0000000000251791 in ?? ()
#4  0x00000000002447d2 in ?? ()
#5  0x0000000000244c35 in ?? ()
#6  0x0000000000251678 in ?? ()
#7  0x000000000023631f in ?? ()
#8  0x0000000000235bd0 in ?? ()
#9  0x000000080031b000 in ?? ()
#10 0x0000000000000000 in ?? ()


# uname -a
FreeBSD vb-12.2.0.domain.com 12.2-STABLE FreeBSD 12.2-STABLE #0 r369260M: Sat Feb 13 11:28:24 EET 2021     root@vb-12.2.0.domain.com:/usr/obj/usr/src/amd64.amd64/sys/vb-12.2.0.domain.com.1  amd64

# env LC_CTYPE=C LC_ALL=C mc -V
GNU Midnight Commander 4.8.26
Built with GLib 2.66.7
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;


gettext-0.21                   GNU gettext meta package
gettext-runtime-0.21           GNU gettext runtime libraries and programs
gettext-tools-0.21             GNU gettext development and translation tools
glib-2.66.7,1                  Some useful routines of C programming (current stable version)
gmake-4.3_2                    GNU version of 'make' utility

mc-nox11-4.8.26                Midnight Commander, a free Norton Commander Clone
Comment 1 Vladyslav V. Prodan 2021-02-24 22:47:46 UTC
>Runs only in -U mode (--nosubshell)
pardon me. The -u option
Comment 2 Cy Schubert freebsd_committer freebsd_triage 2021-02-25 04:06:12 UTC
That backtrace is kind-of useless. Can you rebuild mc WITH_DEBUG. We may need to set DEBUG_CFLAGS="-O0 -g" later as well. But let's try WITH_DEBUG first, hopefully the compiler won't optimize out too many variables.

Can you run more than one copy of mc in two different xterm or other windows? Can you run it in more than two tmux windows?
Comment 3 Vladyslav V. Prodan 2021-02-25 10:35:41 UTC
Can you explain step by step how to add DEBUG option to mc from /usr/ports?
Comment 4 Vladyslav V. Prodan 2021-02-25 10:51:53 UTC
(In reply to Vladislav V. Prodan from comment #3)

Enable debugging for select ports in /etc/make.conf: 
WITH_DEBUG_PORTS=       misc/mc misc/mc-nox11

?
Comment 5 Cy Schubert freebsd_committer freebsd_triage 2021-02-25 14:08:31 UTC
(In reply to Vladislav V. Prodan from comment #4)

That's one way to do it. I tend to, make -DWITH_DEBUG.

If when looking through the dump I discover the compiler has optimized out a variable I need to look at I will also turn off optimization:

make -DWITH_DEBUG DEBUG_FLAGS='-g -O0'

Let's try make -DWITH_DEBUG first. It may be all we need for now.
Comment 6 Vladyslav V. Prodan 2021-02-25 14:33:54 UTC
(In reply to Cy Schubert from comment #2)

I closed all screen and mc processes.
I run tmux with multiple windows.
And in any window mc does not start. 

```
mc:44469): GLib-CRITICAL **: 16:23:59.816: g_string_free: assertion 'string != NULL' failed
```
Comment 7 Vladyslav V. Prodan 2021-02-25 15:04:08 UTC
# gdb -v
GNU gdb (GDB) 10.1 [GDB v10.1 for FreeBSD]

                                                                                                                                               0x00000000002c8aa6 in str_utf8_make_make_term_form (text=0x0, length=18446744073709551615) at strutilutf8.c:454
454         if (length != 0 && text[0] != '\0')
(gdb) bt
#0  0x00000000002c8aa6 in str_utf8_make_make_term_form (text=0x0, length=18446744073709551615) at strutilutf8.c:454
#1  0x00000000002c7bfd in str_utf8_term_width2 (text=0x0, length=18446744073709551615) at strutilutf8.c:802
#2  0x00000000002c7c3c in str_utf8_term_width1 (text=0x0) at strutilutf8.c:811
#3  0x00000000002c2359 in str_term_width1 (text=0x0) at strutil.c:654
#4  0x000000000029c13f in setup_cmdline () at layout.c:976
#5  0x000000000029b179 in setup_panels () at layout.c:889
#6  0x000000000026320e in midnight_callback (w=0x801a95c00, sender=0x0, msg=MSG_INIT, parm=0, data=0x0) at filemanager.c:1498
#7  0x00000000002516da in send_message (w=0x801a95c00, sender=0x0, msg=MSG_INIT, parm=0, data=0x0) at ../../lib/widget/widget-common.h:243
#8  0x000000000025155b in dlg_init (h=0x801a95c00) at dialog.c:503
#9  0x0000000000251d95 in dlg_run (h=0x801a95c00) at dialog.c:574
#10 0x00000000002630dd in do_nc () at filemanager.c:1837
#11 0x000000000023dce0 in main (argc=1, argv=0x7fffffffda58) at main.c:463
(gdb)
Comment 8 Cy Schubert freebsd_committer freebsd_triage 2021-02-25 15:09:13 UTC
(In reply to Vladislav V. Prodan from comment #6)
This is consistent and expected. mc expects not to run under screen, tmux, or any other terminal multiplexer, or expects some object presented to it not to be NULL when presented by screen or tmux. The problem exists within mc and not in screen or tmux.
Comment 9 Cy Schubert freebsd_committer freebsd_triage 2021-02-25 15:11:48 UTC
(In reply to Vladislav V. Prodan from comment #7)
Was this a segmentation violation?

Type in: p *text
Comment 10 Vladyslav V. Prodan 2021-02-25 15:17:56 UTC
(In reply to Cy Schubert from comment #9)
(gdb) p *text
No symbol "text" in current context.
Comment 11 Vladyslav V. Prodan 2021-02-25 15:24:08 UTC
(In reply to Cy Schubert from comment #8)

In general, yes.
But if mc is started without a screen multiplexer (screen or tmux), then the ssh connection is broken, immediately after mc crashes.
Comment 12 Cy Schubert freebsd_committer freebsd_triage 2021-02-25 15:40:04 UTC
(In reply to Vladislav V. Prodan from comment #10)
Which stack frame are you in?
Comment 13 Cy Schubert freebsd_committer freebsd_triage 2021-02-25 15:46:28 UTC
(In reply to Vladislav V. Prodan from comment #11)
Understood but that still doesn't mitigate the fact that mc crashing under two different terminal multiplexers would be anything but an mc design decision or mc bug.
Comment 14 Cy Schubert freebsd_committer freebsd_triage 2021-02-25 15:47:24 UTC
mc maintainer may wish to update to 4.8.27.

https://midnight-commander.org/wiki/NEWS-4.8.27.
Comment 15 Cy Schubert freebsd_committer freebsd_triage 2021-02-25 15:48:07 UTC
Do you have ncurses port installed? If yes, what version?

uname -a, please.
Comment 16 Vladyslav V. Prodan 2021-02-25 15:55:06 UTC
(In reply to Cy Schubert from comment #15)
I am using system ncurses 

# uname -a
FreeBSD vb-12.2.0.domain.com 12.2-STABLE FreeBSD 12.2-STABLE #0 r369260M: Sat Feb 13 11:28:24 EET 2021     root@vb-12.2.0.domain.com:/usr/obj/usr/src/amd64.amd64/sys/vb-12.2.0.domain.com.1  amd64

# file /usr/local/bin/mc
/usr/local/bin/mc: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 12.2 (1202505), FreeBSD-style, with debug_info, not stripped

# ldd /usr/local/bin/mc
/usr/local/bin/mc:
        libslang.so.2 => /usr/local/lib/libslang.so.2 (0x80038d000)
        libssh2.so.1 => /usr/local/lib/libssh2.so.1 (0x8006b7000)
        libgmodule-2.0.so.0 => /usr/local/lib/libgmodule-2.0.so.0 (0x8006f5000)
        libglib-2.0.so.0 => /usr/local/lib/libglib-2.0.so.0 (0x8006fb000)
        libintl.so.8 => /usr/local/lib/libintl.so.8 (0x800831000)
        libutil.so.9 => /lib/libutil.so.9 (0x800840000)
        libthr.so.3 => /lib/libthr.so.3 (0x800858000)
        libc.so.7 => /lib/libc.so.7 (0x800885000)
        libncurses.so.8 => /lib/libncurses.so.8 (0x800c7d000)
        libdl.so.1 => /usr/lib/libdl.so.1 (0x800cd6000)
        libm.so.5 => /lib/libm.so.5 (0x800cda000)
        libz.so.6 => /lib/libz.so.6 (0x800d0c000)
        libssl.so.111 => /usr/lib/libssl.so.111 (0x800d28000)
        libcrypto.so.111 => /lib/libcrypto.so.111 (0x800dc0000)
        libpcre.so.1 => /usr/local/lib/libpcre.so.1 (0x8010b2000)
        libiconv.so.2 => /usr/local/lib/libiconv.so.2 (0x801155000)

# env LC_CTYPE=C LC_ALL=C mc -V
GNU Midnight Commander 4.8.26
Built with GLib 2.66.7
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 support for X11 events
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;
Comment 17 Vladyslav V. Prodan 2021-02-25 16:02:47 UTC
(In reply to Cy Schubert from comment #12)

(gdb) frame
#11 0x000000000023dce0 in main (argc=1, argv=0x7fffffffda58) at main.c:463
463             exit_code = do_nc ()? EXIT_SUCCESS : EXIT_FAILURE;
Comment 18 Cy Schubert freebsd_committer freebsd_triage 2021-02-25 16:09:44 UTC
(In reply to Vladislav V. Prodan from comment #17)

frame 1
p *text

Suspect that text is a NULL pointer.
Comment 19 Vladyslav V. Prodan 2021-02-25 16:17:05 UTC
(In reply to Cy Schubert from comment #18)

(gdb) frame 1
#1  0x00000000002c7bfd in str_utf8_term_width2 (text=0x0, length=18446744073709551615) at strutilutf8.c:802
802         result = str_utf8_make_make_term_form (text, length);
(gdb) p *text
Cannot access memory at address 0x0
Comment 20 Cy Schubert freebsd_committer freebsd_triage 2021-02-25 16:20:58 UTC
(In reply to Vladislav V. Prodan from comment #19)
type: l
Comment 21 Vladyslav V. Prodan 2021-02-25 16:57:40 UTC
(In reply to Cy Schubert from comment #20)
(gdb) l
797     static int
798     str_utf8_term_width2 (const char *text, size_t length)
799     {
800         const struct term_form *result;
801
802         result = str_utf8_make_make_term_form (text, length);
803         return result->width;
804     }
805
806     /* --------------------------------------------------------------------------------------------- */
Comment 22 Cy Schubert freebsd_committer freebsd_triage 2021-02-25 17:04:17 UTC
(In reply to Vladislav V. Prodan from comment #21)
I give up. That's not frame 1, it's frame 11. Please put a copy of your mc binary and the dump somewhere so I can fetch it.
Comment 23 Vladyslav V. Prodan 2021-02-25 17:17:55 UTC
(In reply to Cy Schubert from comment #22)

As you know
(gdb) quit
A debugging session is active.

        Inferior 1 [process 66102] will be killed.

Quit anyway? (y or n) y

https://mega.nz/folder/Qpxgwaxb#6QRwPG7A4s_AgswqUd5EKw
Comment 24 Cy Schubert freebsd_committer freebsd_triage 2021-02-25 17:54:08 UTC
This is for woodsb02:

In frame 4 at layout.c just above line 976 ENABLE_SUBSHELL appears it might be enabled. I don't have config.h to view, admin@support.od.ua can confirm.

At line 966 tmp_prompt gets the address of the prompt:

    char *tmp_prompt = (char *) mc_prompt;

Then here it's nuked:

#ifdef ENABLE_SUBSHELL
    if (mc_global.tty.use_subshell)
    {
        tmp_prompt = g_string_free (subshell_prompt, FALSE);
        (void) strip_ctrl_codes (tmp_prompt);
    }
#endif

At this point tmp_prompt is a NULL pointer because subshell_prompt is also a NULL pointer. I don't see where subshell_prompt is set anywhere. Likely a bug in mc that upsteam must fix.

Not much else I can do.
Comment 25 Vladyslav V. Prodan 2021-02-25 22:25:56 UTC
I created a ticket on the mc app development site -
https://midnight-commander.org/ticket/4213.
Comment 26 Zsolt Udvari freebsd_committer freebsd_triage 2024-08-25 19:35:39 UTC
^Triage: assign to maintainer (committer).
Comment 27 Alexey Dokuchaev freebsd_committer freebsd_triage 2024-09-18 17:23:29 UTC
I can't reproduce it with recent versions (4.8.31~32), had the bug been fixed since 2021 or we need more clear/precise steps to trigger it?
Comment 28 Vladyslav V. Prodan 2024-09-18 17:45:26 UTC
Ok. Let's close the ticket.