From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxim Nikulin Newsgroups: gmane.emacs.bugs Subject: bug#44824: [PATCH] org.el: Avoid xdg-open silent failure Date: Sat, 20 Mar 2021 22:45:16 +0700 Message-ID: <214cd672-a9c6-b7d4-754e-df2e552f2b2e__45597.510160745$1616256718$gmane$org@gmail.com> References: <87y2gfcape.fsf_-_@gnus.org> <87a6st7oi1.fsf@gnus.org> <108399a5-66ad-eee6-572b-b3f2181e4e6c@gmail.com> <87lfccxs5a.fsf@gnus.org> <875z3f2bwx.fsf@gnus.org> <838s8aak8j.fsf@gnu.org> <83sg6i8rht.fsf@gnu.org> <5f1a0018-56a4-7f00-68bc-eeb93631f102@gmail.com> <83lfca8k4e.fsf@gnu.org> <83y2g96ta6.fsf@gnu.org> <7635bde2-8590-f555-0d3b-7fa818d812c6@gmail.com> <83o8h56p7o.fsf__8661.17158891342$1612110869$gmane$org@gnu.org> <87zgyzls41.fsf@kyleam.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------8A9F5E7AADCBE8693FAE8F3D" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33309"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 Cc: 44824@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 20 17:11:53 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lNeCe-0008VC-F6 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 20 Mar 2021 17:11:52 +0100 Original-Received: from localhost ([::1]:56678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNeCd-0001Ym-Cr for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 20 Mar 2021 12:11:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48216) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNdne-0005sS-ME; Sat, 20 Mar 2021 11:46:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41485) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lNdne-0003sX-ER; Sat, 20 Mar 2021 11:46:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lNdne-0001Sl-CN; Sat, 20 Mar 2021 11:46:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Maxim Nikulin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, emacs-orgmode@gnu.org Resent-Date: Sat, 20 Mar 2021 15:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44824 X-GNU-PR-Package: emacs,org-mode X-GNU-PR-Keywords: moreinfo Original-Received: via spool by 44824-submit@debbugs.gnu.org id=B44824.16162551485597 (code B ref 44824); Sat, 20 Mar 2021 15:46:02 +0000 Original-Received: (at 44824) by debbugs.gnu.org; 20 Mar 2021 15:45:48 +0000 Original-Received: from localhost ([127.0.0.1]:53031 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lNdnP-0001SD-P7 for submit@debbugs.gnu.org; Sat, 20 Mar 2021 11:45:48 -0400 Original-Received: from mail-lj1-f171.google.com ([209.85.208.171]:39635) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lNdnJ-0001Rw-QT for 44824@debbugs.gnu.org; Sat, 20 Mar 2021 11:45:45 -0400 Original-Received: by mail-lj1-f171.google.com with SMTP id u4so15652410ljo.6 for <44824@debbugs.gnu.org>; Sat, 20 Mar 2021 08:45:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:newsgroups:references:cc:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=7IDt7rtMz3R6+AVQq+zFTuxL8nuA+KWhUVAJ+1Dh1Dw=; b=tO4IsL4NKKIhZce23QcPFyEHTvJeA1n5Q2IBVSWog+ozH4VoLxZWbqNuX6quTE4EQQ MOUB+2x1BiqrOxm/HMtgLfUqMnm+4GbWy023O18iB5TIfupcDoFzWiXu18akSd2p91cx BY+JVSQSRHadlw1qq3Z1E1Ux8mhdfVFoF3ZTKkweagWLkVCgBwSnU0SRhkYg3aR4T3fQ ZCXFxpYFebDUUbNDJkJGfVBtuHCFLmOw7mz/PcmI8iUfoY1PIGqnkG5SB/s0ckZd1THU vo2D0aqyKiPhKl8DmHZUFG/cGXPeF/N3wcwWhi7NuD0CVPmgWAhuUXBjl0HyDhywC2Zk Rd9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:newsgroups:references:cc:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=7IDt7rtMz3R6+AVQq+zFTuxL8nuA+KWhUVAJ+1Dh1Dw=; b=JmphHWKadlwuxDQyyVZNHIoBGuI25ZH+eZ/WEbk3NHIx4w1vJkYfeqkZYKNWSm4JIo V+6B3Yu8qt++kKGS9ghqAwUiqcZRmU+A24NMyxgYJhTj+G5UMUaEulbZy5cCiSAzgrqk ygIgNQC7M/H54VFAL60Neeei8QJmEtkGZhUJy+gkprWAZcGI9j7ECdLiXm5doL88iDFI GoSxMYR2Oid2S31vQVoY4X4bZgHlxdTP/p0WhftAU9Ch+BDTvhU9aMMPeujpOkjXMd41 sJaFyGUh5yB64R4eWTgK0Zpq9huoNGBqSTtAoHOKcqOZuyQKui9hQIdyprvcTkCxacKf p5Mg== X-Gm-Message-State: AOAM531l1Vp5wISsgle8pGNW3a8lBKDI/n7izKsQ0qX7dNS/Z03kTunS G5+W5rRoim1zMgf2uGRLT1BsQtQDNyA= X-Google-Smtp-Source: ABdhPJxafbdXLGiGl4nfPrBD/p60hhv81X1vyJH3cz+yC3Rl0wE72mH1ZewUFnDyzY7A+8Fj2c5rrQ== X-Received: by 2002:a2e:87d5:: with SMTP id v21mr4049302ljj.195.1616255135328; Sat, 20 Mar 2021 08:45:35 -0700 (PDT) Original-Received: from [192.168.0.101] (nat-0-0.nsk.sibset.net. [5.44.169.181]) by smtp.googlemail.com with ESMTPSA id v10sm963225lfb.238.2021.03.20.08.45.33 for <44824@debbugs.gnu.org> (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 20 Mar 2021 08:45:34 -0700 (PDT) X-Google-Original-From: Maxim Nikulin Original-Newsgroups: gmane.emacs.orgmode In-Reply-To: <87zgyzls41.fsf@kyleam.com> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Mailman-Approved-At: Sat, 20 Mar 2021 12:11:24 -0400 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:202742 Archived-At: This is a multi-part message in MIME format. --------------8A9F5E7AADCBE8693FAE8F3D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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. --------------8A9F5E7AADCBE8693FAE8F3D Content-Type: text/x-patch; charset=UTF-8; name="org-open-file-make-process-v2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="org-open-file-make-process-v2.patch" commit 5eca7764d94dd46b9f9a7792d1b786a3f03b20b6 Author: Max Nikulin 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)) --------------8A9F5E7AADCBE8693FAE8F3D--