Bug 108591 - xdg-open path is hardcoded
Summary: xdg-open path is hardcoded
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
5.3.0.3 release
Hardware: All Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:7.2.0
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-17 16:16 UTC by lvernschrock
Modified: 2023-12-20 07:09 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
patch that makes LibreOffice look for xdg-open in the path (1.11 KB, patch)
2017-06-17 16:21 UTC, lvernschrock
Details

Note You need to log in before you can comment on or make changes to this bug.
Description lvernschrock 2017-06-17 16:16:35 UTC
Description:
Ideally, LibreOffice would look in the PATH for xdg-open and use it if found.

If it can't find it in the PATH nor at /usr/bin/xdg-open, then it should display a reasonable error message via the GUI. Something like:
"LibreOffice needs xdg-open to open links, but could not find it." 

This causes a problem for NixOS which doesn't install software under /usr, but uses symlinks to added packages to the PATH. I suppose this could also be a problem on other *nix distributions if a non-root user wants to use a custom xdg-open by adding it to a folder in the PATH before /usr/bin.

(I put the earliest version affected to 5.3.0.3 since that is the earliest I've tested, but I'm sure the problem exists in earlier versions as well.)

Steps to Reproduce:
1. Place xdg-open somewhere in your PATH, but not in /usr/bin/xdg-open
2. Launch LibreOffice Calc from a terminal emulator
3. Type a URL in a cell and hit the enter key
4. Hold down Ctrl and click the link.

Actual Results:  
In the terminal emulator, the following message prints:
sh: /usr/bin/xdg-open: No such file or directory

No message is displayed to the user.

Expected Results:
LibreOffice should find xdg-open and use it to open the link, causing your default browser to pop up and load the page.


Reproducible: Always

User Profile Reset: No

Additional Info:


User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0
Comment 1 lvernschrock 2017-06-17 16:21:38 UTC
Created attachment 134083 [details]
patch that makes LibreOffice look for xdg-open in the path

This patch should solve the problem. Credit goes to Linus Heckemann for creating it.

This patch also fixes the 'File > Send > Email Document' when xdg-open is in the PATH but not at /usr/bin/xdg-open
Comment 2 Buovjaga 2017-06-18 18:03:50 UTC
(In reply to lvernschrock from comment #1)
> Created attachment 134083 [details]
> patch that makes LibreOffice look for xdg-open in the path
> 
> This patch should solve the problem. Credit goes to Linus Heckemann for
> creating it.
> 
> This patch also fixes the 'File > Send > Email Document' when xdg-open is in
> the PATH but not at /usr/bin/xdg-open

Please submit the patch via gerrit:
https://wiki.documentfoundation.org/Development/gerrit
https://wiki.documentfoundation.org/Development/gerrit/SubmitPatch
Comment 3 Xisco Faulí 2017-06-18 18:05:54 UTC
Moving to NEW...
Comment 4 QA Administrators 2018-06-19 02:45:29 UTC Comment hidden (obsolete)
Comment 5 QA Administrators 2020-10-09 04:17:11 UTC Comment hidden (obsolete)
Comment 6 Buovjaga 2021-02-07 11:48:45 UTC
I submitted the patch now and attributed it to Linus Heckemann https://gerrit.libreoffice.org/c/core/+/110530
Comment 7 David H. Gutteridge 2021-04-07 02:54:34 UTC
Part of this patch set won't necessarily behave as intended, depending on the OS.

diff --git a/shell/source/unix/misc/senddoc.sh b/shell/source/unix/misc/senddoc.sh
index 4519e01f26e2..8985711a2c01 100755
--- a/shell/source/unix/misc/senddoc.sh
+++ b/shell/source/unix/misc/senddoc.sh
@@ -393,6 +393,8 @@ case `basename "$MAILER" | sed 's/-.*$//'` in
             MAILER=/usr/bin/kde-open
         elif [ -x /usr/bin/xdg-open ] ; then
             MAILER=/usr/bin/xdg-open
+        elif type -p xdg-open >/dev/null 2>&1 ; then
+            MAILER="$(type -p xdg-open)"
         else
             echo "Unsupported mail client: `basename $MAILER | sed 's/-.*^//'`"
             exit 2

This uses "type -p", but that's not portable.

For example, with Debian's dash as /bin/sh:

$ /bin/sh
$ type -p xdg-open
-p: not found
xdg-open is /usr/bin/xdg-open
$ echo $?
127

Or with NetBSD's /bin/sh (with newer than 8.0):

$ /bin/sh
$ type -p xdg-open
type: usage: type name...
$ echo $?
2

"command -v" is probably a better choice here.
Comment 8 Buovjaga 2021-04-07 06:40:58 UTC
(In reply to David H. Gutteridge from comment #7)
> "command -v" is probably a better choice here.

Thanks, I updated https://gerrit.libreoffice.org/c/core/+/110530

John also had some comments in the patch, so if someone could give feedback on those, it would be great.
Comment 9 David H. Gutteridge 2021-04-08 03:33:51 UTC
I can offer the perspective of someone involved with downstream packaging (for NetBSD and others). One of our users hit this issue on NetBSD. BSDs as a rule don't install most third-party software to /usr/bin, they isolate it elsewhere by policy (with NetBSD, the default being /usr/pkg/bin, with most other BSDs, it's /usr/local/bin). So patches like these are welcomed.

There is of course a risk with simply looking for xdg-open. Sometimes, what we do in this case is substitute our own (user-configurable at build time) paths over whatever the upstream software expects. I don't know if you want to deal with that additional complexity at your end. You're making a reasonable effort to find something appropriate already.

I'd be inclined to prefer xdg-open over kde-open, as xdg-open is intended to be a standard/cross-desktop tool, and so I'd expect either it would be more commonly available by default (not with us, but with mainstream Linux distros), and probably a less complex external dependency. (That said, I don't know if the KDE version offers some advantage I don't know about.)

Thanks,

Dave
Comment 10 Commit Notification 2021-05-28 09:26:18 UTC
Linus Heckemann committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/85462ef7aed85bcfb0e0628c5252a07c369ff606

tdf#108591 Don't hardcode xdg-open path

It will be available in 7.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 11 bobbie78 2023-12-20 07:09:01 UTC Comment hidden (spam)