unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Vasilij Schneidermann <v.schneidermann@gmail.com>
Cc: 25778-done@debbugs.gnu.org
Subject: bug#25778: 25.1; [PATCH] Drastically simplify xdg-open check
Date: Thu, 9 Mar 2017 19:13:18 -0800	[thread overview]
Message-ID: <71da2828-56f3-2c5d-9326-08fb952657a0@cs.ucla.edu> (raw)
In-Reply-To: <CAPGgwWRPPCSjYiLV8dQVtijP=Zm3Ok67d898Aasi_J0AseCfkg@mail.gmail.com>

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

Thanks for the bug report. I installed the attached somewhat-more-ambitious 
patch that works along the line that you suggested. Although every heuristic in 
this area will be wrong sometimes, I think nowadays we're probably better off 
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 does a 
'signal (SIGHUP, SIG_DFL)' before it execs (!). This may help to explain why 
nobody noticed when Emacs stopped using nohup. Although nohup may have been 
needed for ancient GNOME versions, I don't think we need to worry about these 
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 
wrong.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Simplify-checks-for-xdg-open-and-xdg-email.patch --]
[-- Type: text/x-diff; name="0001-Simplify-checks-for-xdg-open-and-xdg-email.patch", Size: 5679 bytes --]

From 095e7d126ee1fc56cb1ec0f9ab1a9cdd6417a232 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
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))))
 
-;; FIXME this duplicates much of the logic from browse-url-can-use-xdg-open.
 (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=org.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")))
 
 (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, KDE, 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)
 
@@ -944,36 +944,14 @@ browse-url-default-browser
 
 (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 child
-       ;; to finish.  This child may then be killed when the parent dies.
-       ;; Use nohup to work around.  See bug#7166, bug#8917, bug#9779 and
-       ;; http://lists.gnu.org/archive/html/emacs-devel/2009-07/msg00279.html
-       (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=org.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")))
 
 ;;;###autoload
 (defun browse-url-xdg-open (url &optional ignored)
-- 
2.7.4


      parent reply	other threads:[~2017-03-10  3:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-17 18:16 bug#25778: 25.1; [PATCH] Drastically simplify xdg-open check Vasilij Schneidermann
2017-02-17 18:38 ` Eli Zaretskii
2017-02-17 18:55   ` Vasilij Schneidermann
2017-02-18  3:39     ` Glenn Morris
2017-02-18  3:46       ` Glenn Morris
2017-02-18  8:55         ` Vasilij Schneidermann
2017-02-19  0:31           ` Glenn Morris
2017-02-19 13:06             ` Vasilij Schneidermann
2017-02-18  7:58     ` Eli Zaretskii
2017-02-18  8:50       ` Vasilij Schneidermann
2017-03-10  3:13 ` Paul Eggert [this message]

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.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=71da2828-56f3-2c5d-9326-08fb952657a0@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=25778-done@debbugs.gnu.org \
    --cc=v.schneidermann@gmail.com \
    /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.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).