From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#25778: 25.1; [PATCH] Drastically simplify xdg-open check Date: Thu, 9 Mar 2017 19:13:18 -0800 Organization: UCLA Computer Science Department Message-ID: <71da2828-56f3-2c5d-9326-08fb952657a0@cs.ucla.edu> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------F1833AC51374AB44DB69F9C0" X-Trace: blaine.gmane.org 1489115658 5649 195.159.176.226 (10 Mar 2017 03:14:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 10 Mar 2017 03:14:18 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 Cc: 25778-done@debbugs.gnu.org To: Vasilij Schneidermann Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Mar 10 04:14:11 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cmB0M-0000F2-AR for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Mar 2017 04:14:10 +0100 Original-Received: from localhost ([::1]:37178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmB0Q-0007ir-Bz for geb-bug-gnu-emacs@m.gmane.org; Thu, 09 Mar 2017 22:14:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmB0H-0007i9-QC for bug-gnu-emacs@gnu.org; Thu, 09 Mar 2017 22:14:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmB0E-0003UP-JE for bug-gnu-emacs@gnu.org; Thu, 09 Mar 2017 22:14:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:50058) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cmB0E-0003UB-FS for bug-gnu-emacs@gnu.org; Thu, 09 Mar 2017 22:14:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cmB0E-00051S-6Q for bug-gnu-emacs@gnu.org; Thu, 09 Mar 2017 22:14:02 -0500 In-Reply-To: Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Fri, 10 Mar 2017 03:14:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 25778 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Mail-Followup-To: 25778@debbugs.gnu.org, eggert@cs.ucla.edu, v.schneidermann@gmail.com Original-Received: via spool by 25778-done@debbugs.gnu.org id=D25778.148911561419233 (code D ref 25778); Fri, 10 Mar 2017 03:14:01 +0000 Original-Received: (at 25778-done) by debbugs.gnu.org; 10 Mar 2017 03:13:34 +0000 Original-Received: from localhost ([127.0.0.1]:48257 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cmAzl-000509-MU for submit@debbugs.gnu.org; Thu, 09 Mar 2017 22:13:34 -0500 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:47146) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cmAzj-0004zj-Cz for 25778-done@debbugs.gnu.org; Thu, 09 Mar 2017 22:13:32 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 8959D160069; Thu, 9 Mar 2017 19:13:25 -0800 (PST) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id vnOIayqARkwq; Thu, 9 Mar 2017 19:13:24 -0800 (PST) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 06FAB160079; Thu, 9 Mar 2017 19:13:24 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id x4oVmZNkCif1; Thu, 9 Mar 2017 19:13:23 -0800 (PST) Original-Received: from [192.168.1.9] (unknown [47.153.188.248]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id DA54F160069; Thu, 9 Mar 2017 19:13:23 -0800 (PST) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:130413 Archived-At: This is a multi-part message in MIME format. --------------F1833AC51374AB44DB69F9C0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Thanks for the bug report. I installed the attached somewhat-more-ambitio= us=20 patch that works along the line that you suggested. Although every heuris= tic in=20 this area will be wrong sometimes, I think nowadays we're probably better= off=20 simply using xdg-open if it's available and if there's a display. It turns out that nohup is ineffective on xdg-open, as xdg-open's child d= oes a=20 'signal (SIGHUP, SIG_DFL)' before it execs (!). This may help to explain = why=20 nobody noticed when Emacs stopped using nohup. Although nohup may have be= en=20 needed for ancient GNOME versions, I don't think we need to worry about t= hese=20 old GNOME versions in future Emacs releases. I'm closing the bug report as I think the bug is fixed. We can reopen it = if I'm=20 wrong. --------------F1833AC51374AB44DB69F9C0 Content-Type: text/x-diff; name="0001-Simplify-checks-for-xdg-open-and-xdg-email.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-Simplify-checks-for-xdg-open-and-xdg-email.patch" =46rom 095e7d126ee1fc56cb1ec0f9ab1a9cdd6417a232 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 9 Mar 2017 19:01:19 -0800 Subject: [PATCH] Simplify checks for xdg-open and xdg-email browse-url's xdg-open detection was too picky on some GNU/Linux desktops; see Bug#25778. Simplify the code by assuming xdg-open works if it is executable, as nowadays this is more likely to be correct than trying to use heuristics from a few years ago. Don't test for nohup: it is ineffective nowadays, as xdg-open's child uses the default action for SIGHUP even if xdg-open's invoker ignores SIGHUP. While we're at it, allow for Wayland here, as "emacs -nw" might be running in a non-X Wayland terminal. * lisp/mail/emacsbug.el (report-emacs-bug-can-use-xdg-email): * lisp/net/browse-url.el (browse-url-can-use-xdg-open): Simplify to a test for DISPLAY and whether the helper program is executable. Allow WAYLAND_DISPLAY as an option. --- lisp/mail/emacsbug.el | 29 ++++------------------------- lisp/net/browse-url.el | 40 +++++++++------------------------------- 2 files changed, 13 insertions(+), 56 deletions(-) diff --git a/lisp/mail/emacsbug.el b/lisp/mail/emacsbug.el index ecb7db6..c1aec69 100644 --- a/lisp/mail/emacsbug.el +++ b/lisp/mail/emacsbug.el @@ -77,33 +77,12 @@ report-emacs-bug-can-use-osx-open (equal (executable-find "open") "/usr/bin/open") (memq system-type '(darwin)))) =20 -;; FIXME this duplicates much of the logic from browse-url-can-use-xdg-o= pen. (defun report-emacs-bug-can-use-xdg-email () "Return non-nil if the \"xdg-email\" command can be used. -xdg-email is a desktop utility that calls your preferred mail client. -This requires you to be running either Gnome, KDE, or Xfce4." - (and (getenv "DISPLAY") - (executable-find "xdg-email") - (or (getenv "GNOME_DESKTOP_SESSION_ID") - ;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also. - (condition-case nil - (eq 0 (call-process - "dbus-send" nil nil nil - "--dest=3Dorg.gnome.SessionManager" - "--print-reply" - "/org/gnome/SessionManager" - "org.gnome.SessionManager.CanShutdown")) - (error nil)) - (equal (getenv "KDE_FULL_SESSION") "true") - ;; FIXME? browse-url-can-use-xdg-open also accepts LXDE. - ;; Is that no good here, or just overlooked? - (condition-case nil - (eq 0 (call-process - "/bin/sh" nil nil nil - "-c" - ;; FIXME use string-match rather than grep. - "xprop -root _DT_SAVE_MODE|grep xfce4")) - (error nil))))) +xdg-email is a desktop utility that calls your preferred mail client." + (and ;; See browse-url-can-use-xdg-open. + (or (getenv "DISPLAY") (getenv "WAYLAND_DISPLAY")) + (executable-find "xdg-email"))) =20 (defun report-emacs-bug-insert-to-mailer () "Send the message to your preferred mail client. diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el index 04b49c4..20ae072 100644 --- a/lisp/net/browse-url.el +++ b/lisp/net/browse-url.el @@ -45,7 +45,7 @@ ;; browse-url-generic arbitrary ;; browse-url-default-windows-browser MS-Windows browser ;; browse-url-default-macosx-browser macOS browser -;; browse-url-xdg-open Free Desktop xdg-open on Gnome, KD= E, Xfce4, LXDE +;; browse-url-xdg-open freedesktop.org xdg-open ;; browse-url-kde KDE konqueror (kfm) ;; browse-url-elinks Elinks Don't know (tried with= 0.12.GIT) =20 @@ -944,36 +944,14 @@ browse-url-default-browser =20 (defun browse-url-can-use-xdg-open () "Return non-nil if the \"xdg-open\" program can be used. -xdg-open is a desktop utility that calls your preferred web browser. -This requires you to be running either Gnome, KDE, Xfce4 or LXDE." - (and (getenv "DISPLAY") - (executable-find "xdg-open") - ;; xdg-open may call gnome-open and that does not wait for its ch= ild - ;; to finish. This child may then be killed when the parent dies= =2E - ;; Use nohup to work around. See bug#7166, bug#8917, bug#9779 an= d - ;; http://lists.gnu.org/archive/html/emacs-devel/2009-07/msg00279= =2Ehtml - (executable-find "nohup") - (or (getenv "GNOME_DESKTOP_SESSION_ID") - ;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also. - (condition-case nil - (eq 0 (call-process - "dbus-send" nil nil nil - "--dest=3Dorg.gnome.SessionManager" - "--print-reply" - "/org/gnome/SessionManager" - "org.gnome.SessionManager.CanShutdown")) - (error nil)) - (equal (getenv "KDE_FULL_SESSION") "true") - (condition-case nil - (eq 0 (call-process - "/bin/sh" nil nil nil - "-c" - ;; FIXME use string-match rather than grep. - "xprop -root _DT_SAVE_MODE|grep xfce4")) - (error nil)) - (member (getenv "DESKTOP_SESSION") '("LXDE" "Lubuntu")) - (equal (getenv "XDG_CURRENT_DESKTOP") "LXDE")))) - +xdg-open is a desktop utility that calls your preferred web browser." + ;; The exact set of situations where xdg-open works is complicated, + ;; and it would be a pain to duplicate xdg-open's situation-specific + ;; code here, as the code is a moving target. So assume that + ;; xdg-open will work if there is a graphical display; this should + ;; be good enough for platforms Emacs is likely to be running on. + (and (or (getenv "DISPLAY") (getenv "WAYLAND_DISPLAY")) + (executable-find "xdg-open"))) =20 ;;;###autoload (defun browse-url-xdg-open (url &optional ignored) --=20 2.7.4 --------------F1833AC51374AB44DB69F9C0--