summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-29 06:46:00 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-29 06:46:00 -0700
commit8ffa2748cf62e40eadaa464e50fcf89a3e8309d0 (patch)
tree9d25097932b0d02efd2755f750ca0a4dd5ffbf12
parentcc630b15fae496bc39fe74dcca900271ecbd0482 (diff)
downloadtxr-8ffa2748cf62e40eadaa464e50fcf89a3e8309d0.tar.gz
txr-8ffa2748cf62e40eadaa464e50fcf89a3e8309d0.tar.bz2
txr-8ffa2748cf62e40eadaa464e50fcf89a3e8309d0.zip
doc-lookup: handle xdg-open not terminating.
It is common for web browsers like firefox not to fork themselves into the background when initially run from the command line. Only when an additional instance is executed does that instance terminate immediately, passing the URL to the existing instance. (Which also does not constitute forking into the background, but does have the effect of an immediate exit.) User Paul A. Patience reports that some installations of xdg-open have the isssue of not handling this situation; these versions of xdg-open wait for the browser to terminate, which causes xdg-open to hang until the browser is closed if it is the initial instance. * stdlib/doc-lookup.tl (detached-run): New function. Like run, but forks into the background, running the process in a detached grandchild whose parent terminates, so that it becomes an orphan parented to the init daemon. We redirect *stdout* to *stdnull* because the first instance of the browser can spit ugly, meaningless diagnostics when it terminates. (open-url): Use detached-run instad of run. Don't check the return value for zero; there is no integer exit status.
-rw-r--r--stdlib/doc-lookup.tl20
1 files changed, 13 insertions, 7 deletions
diff --git a/stdlib/doc-lookup.tl b/stdlib/doc-lookup.tl
index 46c60d6e..1d02049e 100644
--- a/stdlib/doc-lookup.tl
+++ b/stdlib/doc-lookup.tl
@@ -17,16 +17,22 @@
(ret :unknown))
u.sysname])))
+(defun detached-run (program args)
+ (match-case (fork)
+ (@(= 0) (if (zerop (fork))
+ (exit* (let ((*stdout* *stdnull*))
+ (run program args)))
+ (exit* 0)))
+ (@(< @res 0) (error "fork failed"))))
+
(caseql os-symbol
((:linux :macos :solaris :solaris10 :android)
(defun open-url (url)
- (if (zerop (run (caseql os-symbol
- ((:linux :solaris :android) "xdg-open")
- (:solaris10 "/usr/dt/bin/sdtwebclient")
- (:macos "open"))
- (list url)))
- t
- (error `~s: failed to open ~s` 'open-url url))))
+ (detached-run (caseql os-symbol
+ ((:linux :solaris :android) "xdg-open")
+ (:solaris10 "/usr/dt/bin/sdtwebclient")
+ (:macos "open"))
+ (list url))))
((:cygwin :cygnal)
(with-dyn-lib "shell32.dll"
(deffi shell-execute "ShellExecuteW"