Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't foreground or background mpv from terminal after suspending it with Ctrl-Z #14355

Open
6 tasks done
walterigle opened this issue Jun 14, 2024 · 14 comments
Open
6 tasks done

Comments

@walterigle
Copy link

walterigle commented Jun 14, 2024

mpv Information

mpv 0.38.0 Copyright © 2000-2024 mpv/MPlayer/mplayer2 projects
 built on Jun  6 2024 18:51:45
libplacebo version: v6.338.2
FFmpeg version: 4.4.4
FFmpeg library versions:
   libavutil       56.70.100
   libavcodec      58.134.100
   libavformat     58.76.100
   libswscale      5.9.100
   libavfilter     7.110.100
   libswresample   3.9.100

Important Information

  • Platform version: OpenBSD current
  • GPU model, driver and version: Intel 82Q965 Video
  • Source:
  • Introduced in version: 0.38.0

Reproduction Steps

  • Play something from the terminal
  • Press Ctrl-Z
  • Execute bg
  • Execute fg

The more similar issue I found reported is the one described in this
report in 2020:

#8120

Except for in my case pressing Enter doesn't work, I have to kill the
process.

It doesn't happen with mpv 0.38.0 under Debian testing, nor with mpv
0.37 under Freebsd 14.1. So far this only happens on OpenBSD.

Expected Behavior

mpv should leave the suspended state.

Actual Behavior

mpv stays in suspended state.

Log File

output.txt

Sample Files

No response

I carefully read all instruction and confirm that I did the following:

  • I tested with the latest mpv version to validate that the issue is not already fixed.
  • I provided all required information including system and mpv version.
  • I produced the log file with the exact same set of files, parameters, and conditions used in "Reproduction Steps", with the addition of --log-file=output.txt.
  • I produced the log file while the behaviors described in "Actual Behavior" were actively observed.
  • I attached the full, untruncated log file.
  • I attached the backtrace in the case of a crash.
@guidocella
Copy link
Contributor

Can't reproduce on Linux.

@walterigle
Copy link
Author

walterigle commented Jun 14, 2024 via email

@walterigle
Copy link
Author

walterigle commented Jun 14, 2024 via email

@guidocella
Copy link
Contributor

Probably caused by something in b75b56f. But none of the developers use BSD.

@walterigle
Copy link
Author

walterigle commented Jun 15, 2024

I forgot to mention that, as a workaround, I use this setting in mpv.conf:

profile=builtin-pseudo-gui

With that the problem desappears.

@walterigle
Copy link
Author

Probably caused by something in b75b56f. But none of the developers use BSD.

Today I downloaded and compiled mpv 0.38.0 from source. Painfully (since I didn't find a way of downloading the diff from github) I reverted the diff from the b75b56f commit you pointed me out. Well, you nailed it, that's the change that introduced the regression. Without those changes the issue disappears.

@kasper93
Copy link
Contributor

@N-R-K: Do you want to take a look into it?

@N-R-K
Copy link
Contributor

N-R-K commented Jun 27, 2024

@N-R-K: Do you want to take a look into it?

Sure, I'll look at it. But it may take me a bit.

In the meanwhile, if you (@walterigle) can use gdb to step through what's going on in osdep/terminal-unix.c::terminal_thread() when you press ctrl+z, that would help out a lot since I don't use openbsd myself.

@walterigle
Copy link
Author

walterigle commented Jun 27, 2024

@N-R-K: Do you want to take a look into it?

Sure, I'll look at it. But it may take me a bit.

In the meanwhile, if you (@walterigle) can use gdb to step through what's going on in osdep/terminal-unix.c::terminal_thread() when you press ctrl+z, that would help out a lot since I don't use openbsd myself.

I've used gdb very rarely against core files, asked by some developer in
a report bug. Tell me if what I did below is useful. I ran the program
under gdb, then I suspended with Ctrl-Z and the run fg twice.

If I did it wrong tell me which command should I use, please.

$ gdb ~/Desktop/mpv-0.38.0/build/mpv
[...]
This GDB was configured as "amd64-unknown-openbsd7.5"...
(gdb) run --no-config ~/Videos/video.mp4
Starting program: ~/Desktop/mpv-0.38.0/build/mpv --no-config ~/Videos/video.mp4
Error while reading shared library symbols:
Dwarf Error: wrong version in compilation unit header (is 4, should be 2) [in module /usr/libexec/ld.so]
(+) Video --vid=1 () (h264 640x480 30.000fps)
(+) Audio --aid=1 (
) (aac 2ch 48000Hz)
Error while reading shared library symbols:
Dwarf Error: wrong version in compilation unit header (is 4, should be 2) [in module /usr/libexec/ld.so]
Error while reading shared library symbols:
[...] (same message repeated several times)
Dwarf Error: wrong version in compilation unit header (is 4, should be 2) [in module /usr/libexec/ld.so]
[vo/gpu] Disabling scaler #0 lanczos (GLSL version too old).
[vo/gpu] Disabling scaler #1 hermite (GLSL version too old).
[vo/gpu] Disabling linear/sigmoid scaling (GLSL version too old).
[vo/gpu] correct-downscaling requires non-bilinear scaler.
AO: [sndio] 48000Hz stereo 2ch s16
VO: [gpu] 640x480 yuv420p
Error while reading shared library symbols:
Dwarf Error: wrong version in compilation unit header (is 4, should be 2) [in module /usr/libexec/ld.so]
[...] (same message repeated several times)
AV: 00:00:01 / 00:04:52 (0%) A-V: -0.001
Program received signal SIGTSTP, Stopped (user).
[Switching to thread 561222]
_thread_sys_poll () at /tmp/-:2
2 /tmp/-: No such file or directory.
in /tmp/-
Current language: auto; currently asm
(gdb) fg
Continuing.

Program received signal SIGTSTP, Stopped (user).
_thread_sys_poll () at /tmp/-:2
2 in /tmp/-
(gdb) fg
Continuing.

Program received signal SIGTSTP, Stopped (user).
[Switching to thread 163324]
0x00000100166fec67 in av_mallocz () from /usr/local/lib/libavutil.so.15.0
(gdb) fg
Continuing.

Program received signal SIGTSTP, Stopped (user).
[Switching to thread 160557]
futex () at /tmp/-:2
2 /tmp/-: No such file or directory.
in /tmp/-
(gdb) fg
Continuing.

Program received signal SIGTSTP, Stopped (user).
futex () at /tmp/-:2
2 in /tmp/-
(gdb)

@walterigle walterigle reopened this Jun 27, 2024
@walterigle
Copy link
Author

walterigle commented Jun 27, 2024

I accidentally closed the issue, thanks I found how to reopen it again. :-) Guys, wouldn't be easier to use a mailing list?

@avih
Copy link
Member

avih commented Jun 27, 2024

Guys, wouldn't be easier to use a mailing list?

To some for sure, but for many it would become much less accessible.

Anyway, it is what it is... and it's not too hard to click the "reopen" button either ;)

@walterigle
Copy link
Author

Let's see if now I got what N-R-K asked me:

(gdb) bt
#0 _thread_sys_poll () at /tmp/-:2
#1 0x613eec4373e1d889 in ?? ()
#2 0x0000040d55a06632 in _libc_poll_cancel (fds=Variable "fds" is not available.
)
at /usr/src/lib/libc/sys/w_poll.c:27
#3 0x0000040af7107838 in terminal_thread () at ../osdep/terminal-unix.c:417
#4 0x0000040d504fcc42 in _rthread_start (v=Unhandled dwarf expression opcode 0xa3
)
at /usr/src/lib/librthread/rthread.c:96
#5 0x0000040d55a3d17a in __tfork_thread ()
at /usr/src/lib/libc/arch/amd64/sys/tfork_thread.S:87
#6 0x0000040d55a3d17a in __tfork_thread ()
at /usr/src/lib/libc/arch/amd64/sys/tfork_thread.S:87
Previous frame identical to this frame (corrupt stack?)
(gdb)

@N-R-K
Copy link
Contributor

N-R-K commented Jun 27, 2024

I think gdb was not a good suggestion. What I really wanted was some overview of what the hell is going on. Here's a quick and dirty patch that adds some logging (untested, not sure if it even compiles):

diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c
index 6f7054887..892570b68 100644
--- a/osdep/terminal-unix.c
+++ b/osdep/terminal-unix.c
@@ -437,6 +437,8 @@ static void quit_request_sighandler(int signum)
     errno = saved_errno;
 }
 
+#define LOG(MSG) (fprintf(stderr, "%d: " MSG "\n", __LINE__), fflush(stderr))
+
 static MP_THREAD_VOID terminal_thread(void *ptr)
 {
     mp_thread_set_name("terminal/input");
@@ -461,13 +463,16 @@ static MP_THREAD_VOID terminal_thread(void *ptr)
         bool is_fg = tcgetpgrp(tty_in) == getpgrp();
         int r = polldev(fds, stdin_ok && is_fg ? 3 : 2, buf.len ? ESC_TIMEOUT : INPUT_TIMEOUT);
         if (fds[0].revents) {
+            LOG("got death pipe activity");
             do_deactivate_getch2();
             break;
         }
         if (fds[1].revents & POLLIN) {
+            LOG("got stop/cont pipe activity");
             int8_t c = -1;
             (void)read(stop_cont_pipe[0], &c, 1);
             if (c == PIPE_STOP) {
+                LOG("stopping");
                 do_deactivate_getch2();
                 if (isatty(STDERR_FILENO)) {
                     (void)write(STDERR_FILENO, TERM_ESC_RESTORE_CURSOR,
@@ -479,13 +484,16 @@ static MP_THREAD_VOID terminal_thread(void *ptr)
                 // effectively the same thing.
                 raise(SIGSTOP);
             } else if (c == PIPE_CONT) {
+                LOG("continuing");
                 getch2_poll();
             }
         }
         if (fds[2].revents) {
             int retval = read(tty_in, &buf.b[buf.len], BUF_LEN - buf.len);
-            if (!retval || (retval == -1 && errno != EINTR && errno != EAGAIN && errno != EIO))
+            if (!retval || (retval == -1 && errno != EINTR && errno != EAGAIN && errno != EIO)) {
+                LOG("breaking out");
                 break; // EOF/closed
+            }
             if (retval > 0) {
                 buf.len += retval;
                 process_input(input_ctx, false);

Not sure if it will reveal anything interesting or not, but worth a shot.

@walterigle
Copy link
Author

walterigle commented Jun 27, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants