On 27/05/2022 22:18, Ihor Radchenko wrote:
Max Nikulin writes:

With this exact init.el, trying to run
(let ((process-connection-type nil))
    (start-process-shell-command "1" nil "xdg-open ~/.bashrc"))

Does it mean that you can not reproduce it with emacsclient instead of
xdg-open? Anyway I can not reproduce it with Emacs-27.1 from
Ubuntu-20.04.

I have reported this to Emacs. The more precise steps are in
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=55672

As expected, nobody wishes to dig into obscure X11 issue.

You may try the attached patch. I do not consider it as unambiguous improvement since almost all errors are swallowed due to requirement to interpret viewer command using shell. The same approach settled on `browse-url' after several fixes, but there at least wrong executable name may be reported.

I suspect that you faced the bug working on another issue, so you do not really suffer from it.
From 01c5625d4c9b47573b1b3c8fb9d5672ff87b6696 Mon Sep 17 00:00:00 2001
From: Max Nikulin <maniku...@gmail.com>
Date: Thu, 2 Jun 2022 23:55:09 +0700
Subject: [PATCH] org.el: Use `call-process' to launch external viewers

lisp/org.el (org-open-file): Another attempt to make launching
of viewers more reliable by using approach from `browse-url'
with hope to alleviate (bug#55672).  Unfortunately any errors
are silently ignored.
---
 lisp/org.el | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 95dff27ad..2cc122f5f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8015,16 +8015,19 @@ If the file does not exist, throw an error."
 
       (save-window-excursion
 	(message "Running %s...done" cmd)
-        ;; Handlers such as "gio open" and kde-open5 start viewer in background
-        ;; and exit immediately.  Use pipe connection type instead of pty to
-        ;; avoid killing children processes with SIGHUP when temporary terminal
-        ;; session is finished.
-        ;;
-        ;; TODO: Once minimum Emacs version is 25.1 or above, consider using
-        ;; the `make-process' invocation from 5db61eb0f929 to get more helpful
-        ;; error messages.
-        (let ((process-connection-type nil))
-	  (start-process-shell-command cmd nil cmd))
+        ;; Handlers such as "gio open" and kde-open5 start viewer in
+        ;; background and exit immediately.  As a result
+        ;; `start-shell-process' with default pty
+        ;; `process-connection-type', children processes are killed
+        ;; with SIGHUP when temporary terminal session is finished.
+        ;; Pipe processes have other set of problems, see (bug#55672),
+        ;; (bug#12972) message 47.  Shoot and forget method borrowed
+        ;; from `browse-url-xdg-open' has an advantage that launched
+        ;; viewer may run after quitting from Emacs.  It is hard to
+        ;; avoid shell here since it is required by mailcap
+        ;; specification, but with shell all errors are silently
+        ;; ignored.
+        (call-process shell-file-name nil 0 nil shell-command-switch cmd)
 	(and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))))
      ((or (stringp cmd)
 	  (eq cmd 'emacs))
-- 
2.25.1

Reply via email to