.desktop file not honoring PATH environment variable

Bug #252571 reported by Juan Ignacio Saitua
4
Affects Status Importance Assigned to Milestone
kdelibs
Fix Released
Medium
kdelibs (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

Binary package hint: kdelibs

Hi,

This is the situation:
  - I have myapp in /usr/bin/myapp and in /opt/bin/myapp
  - I also have myapp_entry.desktop in /usr/share/applications with the Exec line as "Exec=myapp"
  - I added /opt/bin into PATH (editing /etc/environment). So PATH has the following: /opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Now, when I launch "kdialog --msgbox `echo $PATH`" using ALT+F2 it shows correctly: /opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

When I launch "myapp" using ALT+F2 it runs /opt/bin/myapp as expected.
But, and this is what I think is a BUG, when I launch "myapp_entry" using ALT+F2 it runs /usr/bin/myapp and not /opt/bin/myapp as I would expect.

My system:
  Description: Ubuntu 8.04.1
  Release: 8.04
  kdelibs: 4:3.5.9-0ubuntu7.1

I asked about this issue on kde-linux mailing list (http://lists.kde.org/?l=kde-linux&m=121706343932070&w=2) , then I reported a BUG mainstream (https://bugs.kde.org/show_bug.cgi?id=167502). Maybe this is a kubuntu only issue, I'm not sure, so that's why I'm posting it here too. Sorry if this is not the way to go.

Thank you.

Revision history for this message
In , Juan Ignacio Saitua (jisaitua) wrote :

Version: (using KDE 3.5.9)
Installed from: Ubuntu Packages
OS: Linux

This is the situation:
 - I have myapp in /usr/bin/myapp and in /opt/bin/myapp
 - I also have myapp_entry.desktop in /usr/share/applications with the Exec line as "Exec=myapp"
 - I added /opt/bin into PATH (editing /etc/environment). So PATH has the following: /opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Now, when I launch "kdialog --msgbox `echo $PATH`" using ALT+F2 it shows correctly: /opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

When I launch "myapp" using ALT+F2 it runs /opt/bin/myapp as expected.
But, and this is what I think is a BUG, when I launch "myapp_entry" using ALT+F2 it runs /usr/bin/myapp and not /opt/bin/myapp as I would expect.

description: updated
Revision history for this message
Juan Ignacio Saitua (jisaitua) wrote :

More info:
I deleted /usr/bin/myapp and ran myapp_entry using ALT+F2. It executes /opt/bin/myapp as it should. My guess is that the .desktop file launcher (klauncher?) is prepending /usr/bin to the PATH variable.
Any comments?

Revision history for this message
Juan Ignacio Saitua (jisaitua) wrote :

Found where the problem is. It's in the KStandardDirs::findExe() function. From line 937 (http://api.kde.org/3.5-api/kdelibs-apidocs/kdecore/html/kstandarddirs_8cpp-source.html#l00937)

 QString p = QString("%1/%2").arg(kfsstnd_defaultbindir()).arg(real_appname);

you can see that it uses function kfsstnd_defaultbindir() to get the absolute path to the application. KStandardDirs::kfsstnd_defaultbindir() returns __KDE_BINDIR and, from the ubuntu packages, the default compiled value for __KDE_BINDIR is /usr/bin. So, it doesn't matter what you set in your PATH environment variable, but it always will execute /usr/bin/myapp.

IMHO, I think that KStandardDirs::findExe() should use KStandardDirs::kfsstnd_defaultbindir() as the last option to find the absolute path to the application (and not as the second one, as is coded right now).

Revision history for this message
In , Juan Ignacio Saitua (jisaitua) wrote :

Found where the problem is. It's in the KStandardDirs::findExe() function. From line 937 (http://api.kde.org/3.5-api/kdelibs-apidocs/kdecore/html/kstandarddirs_8cpp-source.html#l00937)

QString p = QString("%1/%2").arg(kfsstnd_defaultbindir()).arg(real_appname);

you can see that it uses function kfsstnd_defaultbindir() to get the absolute path to the application. KStandardDirs::kfsstnd_defaultbindir() returns __KDE_BINDIR and, from the ubuntu packages, the default compiled value for __KDE_BINDIR is /usr/bin. So, it doesn't matter what you set in your PATH environment variable, but it always will execute /usr/bin/myapp.

IMHO, I think that KStandardDirs::findExe() should use KStandardDirs::kfsstnd_defaultbindir() as the last option to find the absolute path to the application (and not as the second one, as is coded right now).

Any comments? Thanks...

Changed in kdelibs:
status: Unknown → New
Revision history for this message
Endolith (endolith) wrote :

Does your myapp_entry.desktop have a Path entry?

Exec=myapp
Path=/opt/bin

Revision history for this message
Juan Ignacio Saitua (jisaitua) wrote :

No, it has no Path entry. I can also put directly "Exec=/opt/bin/myapp", but I don't want to edit *.desktop files lying in /usr/share/applications.
Maybe I need to explain my real scenario: we are using a thinclient environment where we need to tweak many applications so they "just work" for the end users (e.g. sound, cd burning, 3d graphics). Our first approach was to edit the *.desktop files to run those specific applications with the corresponding tweak (e.g. use padsp to launch java to have remote sound). That approach doesn't scale well, because after every system update, some *.desktop files where replaced with newer ones, and our "tweaks" get loosed. Our next approach was to use "wrappers" for those specific applications. Those "wrappers" lay in /opt/bin. So when some one starts "java.desktop" it really should start "/opt/bin/java" (and that runs "padsp /usr/bin/java").
BTW: Our current workaround was to edit directly the libkdecore.so.4.2.0 library and replace the hard coded /usr/bin path with /opt/bin (see previous post for details about the PATH issue). A really nasty hack, but it work for us.

Revision history for this message
Jonathan Thomas (echidnaman) wrote :

Closing the downstream task in favor of tracking it at the bugs.kde.org task.

Changed in kdelibs (Ubuntu):
status: New → Invalid
Changed in kdelibs:
importance: Unknown → Medium
Revision history for this message
In , Andrew-crouthamel (andrew-crouthamel) wrote :

Dear Bug Submitter,

This bug has been stagnant for a long time. Could you help us out and re-test if the bug is valid in the latest version? I am setting the status to NEEDSINFO pending your response, please change the Status back to REPORTED when you respond.

Thank you for helping us make KDE software even better for everyone!

Changed in kdelibs:
status: New → Incomplete
Revision history for this message
In , Andrew-crouthamel (andrew-crouthamel) wrote :

Dear Bug Submitter,

This is a reminder that this bug has been stagnant for a long time. Could you help us out and re-test if the bug is valid in the latest version?

Thank you for helping us make KDE software even better for everyone!

Changed in kdelibs:
status: Incomplete → New
Revision history for this message
In , H-klene (h-klene) wrote :

Created attachment 130404
Screenshot

Trying to use an environment variable in the working directory (even though it is suggested by the edit dialog) will break the search for the executable and not run the program. In addition usage of "~" also fails to resolve $HOME.

Revision history for this message
In , Alexander-lohnau (alexander-lohnau) wrote :

(In reply to Holger from comment #4)
> Created attachment 130404 [details]
> Screenshot
>
> Trying to use an environment variable in the working directory (even though
> it is suggested by the edit dialog) will break the search for the executable
> and not run the program. In addition usage of "~" also fails to resolve
> $HOME.

Can you please file two separate bugs for this. Thanks!

Revision history for this message
In , H-klene (h-klene) wrote :
Revision history for this message
In , David Faure (faure) wrote :

Is the original bug still present?

KStandardDirs is no longer used, there's no __KDE_BINDIR anymore, etc.

Revision history for this message
In , A-samirh78 (a-samirh78) wrote :

I tested, looks fixed to me.

Changed in kdelibs:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.