From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id uD14NwVkLmB5bAAA0tVLHw (envelope-from ) for ; Thu, 18 Feb 2021 12:56:37 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id qFtGMwVkLmByTgAA1q6Kng (envelope-from ) for ; Thu, 18 Feb 2021 12:56:37 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 07B46223EA for ; Thu, 18 Feb 2021 13:56:37 +0100 (CET) Received: from localhost ([::1]:40092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lCirE-0001Yp-2P for larch@yhetil.org; Thu, 18 Feb 2021 07:56:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38606) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lCiqq-0001Yh-MI for emacs-orgmode@gnu.org; Thu, 18 Feb 2021 07:56:12 -0500 Received: from ciao.gmane.io ([116.202.254.214]:55292) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lCiqo-0007TZ-Ts for emacs-orgmode@gnu.org; Thu, 18 Feb 2021 07:56:12 -0500 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1lCiqm-00018V-I6 for emacs-orgmode@gnu.org; Thu, 18 Feb 2021 13:56:08 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Maxim Nikulin Subject: [PATCH] org.el: Avoid xdg-open silent failure Date: Thu, 18 Feb 2021 19:56:03 +0700 Message-ID: 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> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------9156A09DD498A91DAE617094" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 In-Reply-To: <83o8h56p7o.fsf__8661.17158891342$1612110869$gmane$org@gnu.org> Content-Language: en-US Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 44824@debbugs.gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -1.76 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 07B46223EA X-Spam-Score: -1.76 X-Migadu-Scanner: scn0.migadu.com X-TUID: g+sr3eKnKNPI This is a multi-part message in MIME format. --------------9156A09DD498A91DAE617094 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 31/01/2021 23:33, Eli Zaretskii wrote: >> From: Maxim Nikulin >> Date: Sun, 31 Jan 2021 22:57:57 +0700 >> Cc: 44824@debbugs.gnu.org >> >>>> To fix the problem it is better to use (make-process :connection-type >>>> 'pipe ...) that unfortunately has no higher level wrappers. >>> >>> Wouldn't it work to let-bind process-connection-type to nil around the >>> function that starts the async subprocess? >> >> Sorry, for me it easier to reason how to express it in terms of system >> calls and terminal process groups than if let-bind could override a >> variable when lexical-bind is set to true. > > Well, I think we should try this, because if it works, it will show us > a way to fix the problem. (I don't see how lexical-binding could > interfere with let-binding.) I have prepared a patch that uses `make-process'. I hope, error reporting is improved a bit, but in the case of this particular problem failure is still quiet since xdg-open exits successfully. I could not estimate effect of such change on windows, so pipe process is used only on linux. I am unsure concerning mac however. Another question is if failure message should be suppressed when `waiting-for-user-input-p' returns truth to keep user prompt and input unaffected. --------------9156A09DD498A91DAE617094 Content-Type: text/x-patch; charset=UTF-8; name="open-file-pipe-process.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="open-file-pipe-process.patch" commit 0001bff24864ee16598b4701a05cf40e9abc83af 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. 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 7d8733448..a199a65c9 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -8645,6 +8645,15 @@ opened in Emacs." (when add-auto-mode (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist)))) +(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 +of `make-process'." + (unless (string-match "finished" event) + (message "Command %s: %s." + (mapconcat 'identity (process-command proc) " ") + (substring event 0 -1)))) + ;;;###autoload (defun org-open-file (path &optional in-emacs line search) "Open the file at PATH. @@ -8766,7 +8775,17 @@ If the file does not exist, throw an error." (save-window-excursion (message "Running %s...done" cmd) - (start-process-shell-command cmd nil cmd) + (if (eq system-type 'gnu/linux) + ;; Handlers 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 'org--error-process-sentinel + :command (list shell-file-name shell-command-switch cmd)) + (start-process-shell-command cmd nil cmd)) (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait)))) ((or (stringp cmd) (eq cmd 'emacs)) --------------9156A09DD498A91DAE617094--