[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 920aaef: mailcap.el: Avoid xdg-open silent failure

From: Lars Ingebrigtsen
Subject: master 920aaef: mailcap.el: Avoid xdg-open silent failure
Date: Fri, 30 Jul 2021 08:01:55 -0400 (EDT)

branch: master
commit 920aaef9d95c7b6ac3cbb31f5d2217b620872cab
Author: Max Nikulin <manikulin@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    mailcap.el: Avoid xdg-open silent failure
    * lisp/net/mailcap.el (mailcap-view-file): Use 'pipe :connection-type
    instead of 'pty to prevent killing of background process on handler
    exit.  Avoid regression similar to Bug#44824.
    Problem happens only in some desktop environments where mailcap handler
    launches actual viewer (as defined in .desktop files and obtained from
    mimeapps.list) in background.  E.g. xdg-open invokes "gio open" or
    kde-open5 for Gnome or KDE accordingly and these handlers launch e.g.
    eog or okular in background.  As soon as main process exits, temporary
    terminal session created by `start-process-shell-command' is terminated.
    As a result background processes receive SIGHUP.
    Previously command were executed with no buffer as well, so the change
    does not affect "needsterminal" and "copiousoutput" mailcap features,
    they are not supported as earlier.
    If main process of the handler fails then show a message with exit
    reason.  Output (including error messages) is ignored as before.
    Gtk applications tend to report significant amount of failed asserts
    hardly informative for majority of users (bug#12972).
    Copyright-paperwork-exempt: yes
 lisp/net/mailcap.el | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el
index 54f7f41..f64897a 100644
--- a/lisp/net/mailcap.el
+++ b/lisp/net/mailcap.el
@@ -1177,7 +1177,25 @@ See \"~/.mailcap\", `mailcap-mime-data' and related 
files and variables."
                   (shell-quote-argument (convert-standard-filename file))
                   nil t))
-    (start-process-shell-command command nil command)))
+    ;; Handlers such as "gio open" and kde-open5 start viewer in background
+    ;; and exit immediately.  Avoid `start-process' since it assumes
+    ;; :connection-type `pty' and kills children processes with SIGHUP
+    ;; when temporary terminal session is finished (Bug#44824).
+    ;; An alternative is `process-connection-type' let-bound to nil for
+    ;; `start-process-shell-command' call (with no chance to report failure).
+    (make-process
+     :name "mailcap-view-file"
+     :connection-type 'pipe
+     :noquery t
+     :buffer nil ; "*Messages*" may be suitable for debugging
+     :sentinel (lambda (proc event)
+                 (when (and (memq (process-status proc) '(exit signal))
+                            (/= (process-exit-status proc) 0))
+                   (message
+                    "Command %s: %s."
+                    (mapconcat #'identity (process-command proc) " ")
+                    (substring event 0 -1))))
+     :command (list shell-file-name shell-command-switch command))))
 (provide 'mailcap)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]