On 28/06/2025 17:51, Max Nikulin wrote:

The player is killed by SIGPIPE when it tries to write a warning to stderr.

Anush, please, specify

- Linux distribution and version
      lsb_release -a
- Desktop environment/window manager
      echo "$XDG_CURRENT_DESKTOP"
- mpv version and package type

I have found "-D" option of strace that makes debugging of the issue more convenient. Without it a process started from Emacs does not become a background one. Try

(let* ((movie "~/big_buck_bunny.webm")
       (movie-cmd
        (format
         "strace -D -tt -f -s 128 -o /tmp/xdg-open.strace xdg-open %s"
         (shell-quote-argument (expand-file-name movie)))))
  (let ((process-connection-type nil))
    (start-process-shell-command "strace" nil movie-cmd)))

and inspect /tmp/xdg-open.strace. Pay attention to lines with "execve", e.g.

37946 18:08:46.246366 execve("/usr/bin/kaffeine", ["/usr/bin/kaffeine", ...

and lines at the end of the file like

37946 18:08:46.548691 write(2, "29-06-25 18:08:46.548 [Warning ] ", 33) = -1 EPIPE (Broken pipe) 37946 18:08:46.548714 --- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=37946, si_uid=1000} ---
37956 18:08:46.548739 <... poll resumed> <unfinished ...>) = ?
37952 18:08:46.548751 <... futex resumed>) = ?
37956 18:08:46.548786 +++ killed by SIGPIPE +++
37952 18:08:46.548801 +++ killed by SIGPIPE +++
37954 18:08:46.548998 <... futex resumed>) = ?
37953 18:08:46.549005 <... futex resumed>) = ?
37951 18:08:46.549008 <... futex resumed>) = ?
37950 18:08:46.549012 <... poll resumed> <unfinished ...>) = ?
37954 18:08:46.549026 +++ killed by SIGPIPE +++
37953 18:08:46.549030 +++ killed by SIGPIPE +++
37951 18:08:46.549033 +++ killed by SIGPIPE +++
37950 18:08:46.555547 +++ killed by SIGPIPE +++
37946 18:08:46.555594 +++ killed by SIGPIPE +++

Does player die due to SIGPIPE in your case?

In the meanwhile I have discovered that kde-open5 does not set SIGPIPE handler as well. (In the case of `org-open-file' and xdg-open it should not matter since kde-open5 is running as a foreground process, so `start-process-shell-command' is waiting for its completion.) It has happened so that I have minimal KDE install and "file:" scheme handler is not configured

    kde-open5 file.mp4
kf.service.services: KApplicationTrader: mimeType "x-scheme-handler/file" not found

The following shell snippet

    {
        kde-open5 file.mp4 2>&1 ;
        rv=$? ; printf 'exit code %s: %s\n' "$rv" "$(kill -l "$rv")" 1>&2 ;
    } | true

Prints

    exit code 141: PIPE

It is due to an attempt to print the warning.

What I do not like with the `call-process' 0 approach is that it swallows all errors. In the case of systemd user session, the following command may be used instead of simple xdg-open

systemd-run --user --slice=app.slice -- xdg-open ~/big_buck_bunny.webm

to make possible errors visible in "journalctl --user -e" output.

Without systemd and when ~/.xsession-errors is present, it would be nice to redirect stderr there, but I am unsure if Wayland has a similar file and that Emacs API allows it.

Since closing other end of the pipe created for stderr cause trouble, I have tried to start player with closed stderr (2>&- in shell). The result is even more bizarre. Kaffeine opens X11 connection with fd 2, but still writes log messages to this file descriptor. So do not do it.

When trying to reproduce the issue, an important point is that desktop environments start media type handlers in background. Fallback code in xdg-open does not do it. Add "&" to shell command

(let ((movie-cmd
       (format "xdg-open %s &" (shell-quote-argument
                                (expand-file-name movie)))))
  (let ((process-connection-type nil))
    (start-process-shell-command "xdg-open" nil movie-cmd)))

However not all applications are affected.

Reply via email to