emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Maxim Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Cc: 44824@debbugs.gnu.org
Subject: Re: bug#44824: [PATCH] org.el: Avoid xdg-open silent failure
Date: Sat, 20 Mar 2021 22:45:16 +0700	[thread overview]
Message-ID: <214cd672-a9c6-b7d4-754e-df2e552f2b2e@gmail.com> (raw)
In-Reply-To: <87zgyzls41.fsf@kyleam.com>

[-- Attachment #1: Type: text/plain, Size: 1782 bytes --]

On 19/03/2021 10:50, Kyle Meyer wrote:
> Maxim Nikulin writes:
> A few comments in addition to Eli's advice to drop the
> (eq system-type 'gnu/linux) condition...

Feel free to commit the change suggested in
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=44824#82
instead of this patch.

>> +(defun org--error-process-sentinel (proc event)
>> +  "Show a message if process failed (exited with non-zero code
>> +or killed by a signal.  Pass the function as :SENTINEL argument
> 
> Please rework the first sentence so that it fits on the first line,
> though I'd be in favor dropping the function and using a lambda in the
> make-process call.

My impression is that org-open-file function is already too long and 
complex. Another reason to use standalone function is that I am unsure 
if elisp compiler and interpreter are smart enough to reuse single 
instance of lambda. I was afraid that every opened file caused creation 
of new sentinel possibly with a closure containing chain of stack 
frames. On the other hand even in worst case memory footprint is 
negligible in comparison to any GUI viewer.

>> +  (unless (string-match "finished" event)
> 
> There's no need for substring matching, right?  So it could be
> 
>    (equal event "finished\n")

I was surprised by final "\n" that is not always suitable and I was in 
doubts concerning its stability. I would prefer something like

     (starts-with event "finished")

Certainly match-data is not necessary, so even match-string-p is better.

>    (when (and (memq (process-status proc) '(exit signal))
>               (/= (process-exit-status proc) 0))

Thank you, I was too lazy to implement such kind of check myself. 
Certainly this variant is better.

I hope, I have addressed other your comments in the updated patch.


[-- Attachment #2: org-open-file-make-process-v2.patch --]
[-- Type: text/x-patch, Size: 2616 bytes --]

commit 5eca7764d94dd46b9f9a7792d1b786a3f03b20b6
Author: Max Nikulin <manikulin@gmail.com>
Date:   Wed Feb 17 16:35:58 2021 +0000

    org.el: Avoid xdg-open silent failure
    
    * lisp/org.el (org-open-file): Use 'pipe :connection-type instead of
    'pty to prevent killing of background process on handler exit.
    (Bug#44824)
    
    Problem happens only in some desktop environments where configured
    through `org-file-apps' or mailcap handlers 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 launches 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, so the change
    does not affect "needsterminal" and "copiousoutput" mailcap features,
    they are not supported as earlier.
    
    If handler main process fails then show a message with exit reason.
    Output (including error messages) is ignored as before.
    Gtk application tends to report significant amount of failed asserts
    hardly informative for majority of users.

diff --git a/lisp/org.el b/lisp/org.el
index 4db2dbe04..c58708a5f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8768,7 +8768,21 @@ If the file does not exist, throw an error."
 
       (save-window-excursion
 	(message "Running %s...done" cmd)
-	(start-process-shell-command cmd nil cmd)
+        ;; 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.
+        (make-process
+         :name "org-open-file" :connection-type 'pipe :noquery t
+         :buffer nil ; use "*Messages*" 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 cmd))
 	(and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))))
      ((or (stringp cmd)
 	  (eq cmd 'emacs))

  reply	other threads:[~2021-03-20 15:45 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAFbX=UpDN9XtTr3osTC6B=V0trvatayw5WF0gMjGWAWfQQkAXg@mail.gmail.com>
     [not found] ` <f395c79a-c3e3-52c7-3fbb-608e94868e8e@gmail.com>
2021-01-27  3:36   ` bug#44824: 27.1; Org export as pdf and open file does not open it Lars Ingebrigtsen
2021-01-27  8:33     ` gbiotti
2021-01-28  3:02       ` Lars Ingebrigtsen
2021-01-28 11:20         ` gbiotti
2021-01-28 11:31         ` gbiotti
2021-01-29  4:51           ` Lars Ingebrigtsen
2021-01-29  6:59             ` Geraldo Biotti
2021-01-30  6:09               ` Lars Ingebrigtsen
2021-01-30  7:50                 ` Geraldo Biotti
2021-01-30  8:42                 ` Eli Zaretskii
2021-01-30 13:31                   ` Maxim Nikulin
2021-01-30 13:49                     ` Eli Zaretskii
2021-01-30 15:58                       ` Maxim Nikulin
2021-01-30 16:28                         ` Eli Zaretskii
2021-01-31 11:15                           ` Maxim Nikulin
2021-01-31 11:37                             ` tomas
2021-01-31 15:05                             ` Eli Zaretskii
2021-01-31 15:17                               ` Andreas Schwab
2021-01-31 15:34                                 ` Eli Zaretskii
2021-01-31 15:21                               ` Lars Ingebrigtsen
2021-01-31 15:57                               ` Maxim Nikulin
2021-01-31 16:33                                 ` Eli Zaretskii
2021-01-31 17:07                                   ` Maxim Nikulin
     [not found]                                 ` <83o8h56p7o.fsf__8661.17158891342$1612110869$gmane$org@gnu.org>
2021-02-18 12:56                                   ` [PATCH] org.el: Avoid xdg-open silent failure Maxim Nikulin
2021-02-18 14:48                                     ` bug#44824: " Eli Zaretskii
     [not found]                                     ` <83a6s15t51.fsf__31631.6350990505$1613659778$gmane$org@gnu.org>
2021-02-19 12:29                                       ` Maxim Nikulin
2021-02-19 14:54                                         ` Eli Zaretskii
2021-02-19 16:45                                           ` Maxim Nikulin
2021-03-19  3:50                                     ` Kyle Meyer
2021-03-20 15:45                                       ` Maxim Nikulin [this message]
2021-03-21 15:01                                         ` Kyle Meyer
2021-01-30 16:39                     ` bug#44824: 27.1; Org export as pdf and open file does not open it gbiotti
2021-01-30 18:50                       ` Bhavin Gandhi
2021-01-31  7:17                   ` Lars Ingebrigtsen
2021-01-31  7:39                     ` Tim Cross
2021-01-31  9:09                       ` tomas
     [not found]         ` <108399a5-66ad-eee6-572b-b3f2181e4e6c__47986.5006914892$1611843550$gmane$org@gmail.com>
2021-01-28 16:10           ` Maxim Nikulin
     [not found]   ` <87y2gfcape.fsf_-___1545.58022493205$1611718675$gmane$org@gnus.org>
2021-01-27 12:14     ` Maxim Nikulin
2021-01-27 13:33       ` Maxim Nikulin
     [not found]     ` <0f4437bc-3e40-fe47-d6e7-d33c2fb7965a__46427.8968678386$1611759102$gmane$org@gmail.com>
2021-01-27 16:21       ` Glenn Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=214cd672-a9c6-b7d4-754e-df2e552f2b2e@gmail.com \
    --to=manikulin@gmail.com \
    --cc=44824@debbugs.gnu.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).