Xdg-open / xdg-utils: a security hazard?

I just noticed these programs after doing an update on my laptop. In particular, web browsers started suggesting I open things with "xdg-open" -- I'm suspicious of anything that "auto-decides" what program to run in order to open something. This is one of the main reasons I got away from Windows -- I open things by either:
- Starting the program first, then using whatever load/open command it has or dragging a file onto it.
or
- Explicitly opening a file with a specific program, either by "programname filename" from the terminal, or by right-click menu in a graphical file manager.
I've gone to great lengths to cripple most of the desktop MIME functionality that comes with KDE apps, because of its insistence on associating .exe files with WINE (look -- now you can accidentally run something by double-clicking it!).
How long before we start seeing malware that works because of xdg-open, xdg-email, an so on? Hopefully no one ever helpfully adds extensions like ".sh" to xdg-open... ("oh, it looks like you just downloaded / someone just e-mailed you a shell script. Would you like me to open it for you? Look, I'll save you the trouble of chmod +x ing it...")
Am I just being overly paranoid?
~Felix.

ngoonee wrote:
thetrivialstuff wrote:Am I just being overly paranoid?
Yes you are, modifying xdg-open behaviour would require access to your machine (network or physical) which means you're screwed anyway. The more serious problem is *.desktop files, I saw a blog on that a while back.
I think the .desktop files is the problem I'm after -- I'm not assuming that a machine will be compromised by an attacker modifying xdg's behaviour; I'm assuming that some well-intentioned package maintainer will have opened up a security hole by associating some file type that shouldn't have an association (e.g. .exe's opening with WINE makes it possible to run arbitrary code if you can get the user to double-click it, or just accidentally bump "open" instead of "save" in Firefox).
Likewise, poor defaults in web browser packages' "out of the box" configuration could set filetypes to have a default of "open" instead of "save", and then you have to pray that whoever packaged the mime defaults for that file type picked a sane default association. (For example, I've seen browser packages configured to auto-view PDF files if there's a suitable viewer on the system. Not a good idea if the PDF viewer in question supports JavaScript in PDF's.)
~Felix.

Similar Messages

  • Fixing xdg-open

    Hi all fellow archers!
    For quite some time, those of us running without a desktop environment have been struggling to cope with xdg-open for handling file opens (especially for Chromium).
    Although xdg-open has gotten a bit better over time (it now falls back to mimeopen if it doesn't know what to do).
    Unfortunately, this solution is not a "proper" one since mimeopen currently does not work with URIs, only with files.
    To get around this, I have made two minor adjustments to my system to make it handle even URIs gracefully.
    The first is a hack, the second a (small) patch to xdg-open:
    The hack:
    ln -s /usr/share/applications/mimeinfo.cache to /usr/share/applications/defaults.list
    this will make all applications that register MIME types using MimeType= in their .desktop files the default for their respective MIMEs.
    This is required since xdg-mime does not check mimeinfo.cache when looking up applications for mime types, only defaults.list files.
    If multiple applications happen to register for the same MIME type, I'm not sure which is chosen as the default, but this should be overridden in ~/.local/share/applications/defaults.list anyway.
    The second part, the patch, can be viewed here: http://pastebin.com/EduF8GjC
    For those not used to merging patches like this, download the raw .patch file from here: http://pastebin.com/download.php?i=EduF8GjC , and then run
    sudo patch /usr/bin/xdg-open <xdg-open_uri_patch.txt
    Note that you shouldn't normally just do what strangers like me tell you to, so have a look through the .patch file before patching /usr/bin/xdg-open to make sure I haven't done something naughty.
    There are also unreleased patches for this upstream here and here if you'd prefer using those, but they may not patch nicely against the current Arch version.
    Essentially, whenever a URI is being opened with the internal, generic opener, xdg-mime is queried for the default application for "x-scheme-handler/$scheme" where $scheme is the scheme part of the URI.
    That application is then started with the full URI the path to open.
    Now sit back and enjoy Chromium opening all your files correctly, even magnet:, mailto: and spotify: links (if you've got a client for each installed of course).
    Jon
    PS: The patch has also been submitted to the Portland/XdgUtils team as bug #44873
    EDIT: Turns out this has already been patched after a similar bugreport, just not released, in these commits. The patch is still needed until a release with these changes comes though. Feel free to use the upstream patches instead if you want.
    Last edited by Jonhoo (2012-01-17 22:49:21)

    I tried to find out what was going on using strace. Here is the output:
    strace -f /usr/bin/gvfs-open file.pdf 2>&1 | grep exec
    execve("/usr/lib/xfce4/exo-1/exo-helper-1",
    Why is gvfs-open resorting to xfce's opener while I am running gnome???
    A bit earlier in the trace, gvfs loads /usr/lib/gio/modules/libexo-module-1.so which is certainly the culprit.
    My question is then: how do I make gvfs-open use gnome's facilites?
    --- edit ---
    Looks like my problem:
    https://qa.mandriva.com/show_bug.cgi?id=62203
    --- edit 2 ---
    Some more info:
    http://penguincopter.blogspot.com/2010/ … ty-of.html
    Last edited by benob (2011-02-21 18:38:56)

  • Xdg-open for irc links in chromium

    Hey!
    I know that the first thing to do is search before bothering other people and I did it a lot. Google, posts, how-to`s, wikis... I see my last chance in asking this community
    So here is my problem:
    I use chromium as default browser and konversation for irc on lxde desktop. chromium uses xdg-open to associate files and links with programs. I tried everything I found but couldn`t get it to work. When I click on an IRC link, it asks me for opening the associated program, I confirm with yes and nothing happens. When trying to open an irc link from the terminal I get
    xdg-open: no method available for opening 'irc://...'
    I got it to work with mimeo, so please no suggestions in this direction, I would like to learn how to do it without it and so to learn it distribution independently.
    For anyone looking for it, this is the working mimeo solution
    $ yaourt -Sy mimeo xdg-utils-mimeo mime-type
    $ nano /home/tom/.config/mimeo.conf
    /usr/bin/konversation
      ^irc://
    # there have to be exactly two spaces in front of ^irc://
    This is the working solution in gnome using gconf:
    $ gconftool-2 --set --type=string /desktop/gnome/url-handlers/irc/command 'konversation "%s"
    $ gconftool-2 --set --type=bool /desktop/gnome/url-handlers/irc/enabled true
    $ gconftool-2 --set --type=bool /desktop/gnome/url-handlers/irc/need-terminal false
    This is what I tried in lxde:
    $ yaourt -Sy mime-type xdg-utils
    $ xdg-mime default konversation.desktop application/irc
    $ xdg-mime default konversation.desktop x-scheme-handler/irc
    $ xdg-mime default konversation.desktop application/x-xdg-protocol-irc
    $ nano /usr/share/applications/kde4/konversation.desktop
    MimeType=application/irc;x-scheme-handler/irc;x-xdg-protocol-irc
    $ nano /usr/share/mime/packages/irc.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
    <mime-type type="application/irc">
    <comment>irc url</comment>
    <magic priority="50">
    <match value="%irc://-" type="string" offset="0"/>
    </magic>
    <alias type="application/irc"/>
    </mime-type>
    </mime-info>
    $ update-mime-database /usr/share/mime/
    I appreciate every suggestion. I`ll be on the road for two days and will try your suggestions on the weekend and will give feedback.
    Please explain as understandable as possible, at best with all commands and paths to the files - this is the newbie corner, right?
    Thanks in advance
    Tom
    Last edited by archtom (2011-06-15 19:44:57)

    really noone? Would be so glad if anyone could help!
    Last edited by archtom (2011-06-20 20:21:06)

  • [SOLVED] Chromium not calling xdg-open

    Hi,
    I have been trying to get Chromium to call external applications based on their name and/or mime type. My desktop is XFCE.
    I have read about setting up the xdg-utils, and believe I have it configured. The following command line when run from bash opens up acroread and displays the PDF:
    xdg-open http://cran.r-project.org/doc/manuals/R-intro.pdf
    My ~/.local/share/applications/defaults.list file is:
    application/pdf=acroread.desktop;
    But when I click on the link in chromium I get the "Save File" dialog.
    As a test, I edited the /usr/bin/xdg-open shell script, and made it write to a file in /tmp when ever it is called. (The second line where I send the date to the /tmp/xdg-open.log file.)
    #!/bin/sh
    /usr/bin/date >> /tmp/xdg-open.log
    # xdg-open
    # Utility script to open a URL in the registered default application.
    # Refer to the usage() function below for usage.
    # Copyright 2009-2010, Fathi Boudra <[email protected]>
    When I try and download a PDF in chromium, it never adds to the /tmp/xdm-open.log file. (But does if I call it from the command line as I did above.)
    So to me, it looks like chromium isn't even calling the xdg-open script.
    Any one have any ideas?
    Thanks in advance.
    Last edited by landzend (2012-11-16 10:54:29)

    hiciu wrote:
    Hello,
    For me, chromium is not using xdg-open. You can verify it with:
    strace -e process chromium
    Then download something and try to open it from chromium. As for solution, try this: install perl-file-mimeinfo package and setup it with 'mimeopen --ask-default some-pdf-file.pdf'.
    landzend wrote:
    I have read about setting up the xdg-utils, and believe I have it configured. The following command line when run from bash opens up acroread and displays the PDF:
    xdg-open http://cran.r-project.org/doc/manuals/R-intro.pdf
    This is separate issue, it should run browser (http:// protocol), not acroread. Check this link: http://hiciu.org/some-pdf-file.pdf (harmless). All you know before you open it is the url, not the file type.
    Thanks. I already had the "perl-file-mimeinfo" installed.
    Yes. The link you gave above is type "image/jpeg", so the browser has to start the download to even know what it has coming.

  • [solved] Xdg-open to open everything with file manager

    I like to screw around with my system constantly and xdg-utils is an annoying utility to have to constantly fiddle with. I know there is a way to get xdg-open to open everything with the default file manager, but my google fu has failed me. As of right now I use pcmanfm, and I'm fairly certain I'm sticking with it for the long haul.
    Last edited by shamanstk (2010-05-11 17:57:15)

    Mr.Elendig wrote:perl-file-mimeinfo installed?
    This helped with a xdg-open anomaly. Before installing perl-file-* packages, pcmanfm used to open everything in firefox (which is set as default browser in xdg-open). Thought could be helpful to anyone having problems with applications using xdg-open.
    Last edited by shemz (2010-08-03 15:02:52)

  • Linopen - Yet another xdg-open replacement

    Inspired by Taylorchu's mimi, I decided to make xdg-open replacement written in bash that has somewhat flexible configuration.
    You can match either, extensions, mime types, mime groups, or regular expressions of the filename.
    You can also specify applications that you wish to open in terminal, and linopen knows when the process should be opened in new terminal or in your current open terminal.
    Example configuration
    # linopen configuration
    # enviroiment variables can be used
    # Specify your terminal emulator here
    # for terminal support.
    terminal=xterm
    # Specify all programs you want to
    # open in terminal like this:
    interm=vim
    # There are 4 ways to match filetypes.
    # The following examples are in the order
    # which linopen chooses the program as well.
    # 1. File extension
    # .png:sxiv
    # .mp4:mplayer
    # .txt:vim
    # 2. Mime type
    # image/png:sxiv
    # video/mp4:mplayer
    # text/plain:vim
    # 3. Mime category
    image:sxiv
    video:mplayer
    audio:mplayer->interm # you can also specify the interm rule explictly after '->'
    text:vim
    # 4. Regexp
    # Match some protocols by default
    ?'^http:\/\/':$BROWSER
    ?'^https:\/\/':$BROWSER
    ?'^www.':$BROWSER
    # Directory rule for directories
    # ideally you want to use file manager
    # here if you are a GUI user.
    directory:echo
    # Default rule just echoes back whatever
    # was feed. If you are using DE you could
    # just map a file manager here and it would
    # integrate with your system.
    default:echo
    PKGBUILD here
    Refer to the configuration file for more detailed how-to.
    There is also 'open' symlink to xdg-open to emulate Mac Os X behaviour.
    Last edited by Cloudef (2012-07-17 16:08:41)

    In this case it would be better to change the PKGBUILD to this
    # Maintainer: Cloudef <[email protected]>
    # Intelligent and suckless replacement for xdg-open
    pkgname=linopen
    pkgver=1.0
    pkgrel=1
    pkgdesc='Intelligent and suckless replacement for xdg-open'
    arch=('any')
    url='http://cloudef.eu'
    license=('WTFPL')
    provides=('xdg-utils')
    conflicts=('xdg-utils')
    backup=('etc/linopen.conf')
    source=('xdg-open' 'linopen.conf')
    package() {
    cd "$srcdir"
    mkdir -p "${pkgdir}/usr/bin"
    mkdir -p "${pkgdir}/etc"
    ln -s "/usr/bin/xdg-open" "$pkgdir/usr/bin/open"
    install -m755 xdg-open "${pkgdir}/usr/bin/"
    install -m755 linopen.conf "${pkgdir}/etc/"
    md5sums=('f5487fc4c305a20124da7bb164e6b04d'
    '2c9078f3ee82d619dc150bb44837d9e8')
    or (imho nicer) with this package function
    package() {
    install -Dm755 "$srcdir/xdg-open" "${pkgdir}/usr/bin/xdg-open"
    install -Dm755 "$srcdir/linopen.conf" "${pkgdir}/etc/linopen.conf"
    ln -s "/usr/bin/xdg-open" "$pkgdir/usr/bin/open"
    Last edited by Army (2012-07-03 16:04:13)

  • Xdg-open and i3wm

    Has anyone had any luck with trying to get xdg-open to work with magnet links in Chromium? My hopeful end result would be to have magnet links open in rtorrent (command line utility), but my current workaround is to use a Chrome plugin that turns magnet links into .torrent files.
    I'm also having issues with other URL scheme handlers such as irc:// and opening PDFs from within Chromium.
    I am running 3.6.11-1 ARCH #1, 64-bit machine, on a laptop.
    Thank you!

    anonymous_user wrote:However since it is a terminal application, I don't know how well it would work (if at all).
    It should.  I beleive there is even an option in desktop files to open in a terminal, but I've never relied on that.  I just build it into the exec line.  For example, to open a file in vim in urxvt I'd just have
    Exec=urxvt -c vim %s
    or something like that.

  • Best XDG Opener?

    What is the best XDG Opener? (Like rox, exo-open (XFCE), gnome-open, mimeopen, kioclient)
    Right now I'm using "rox", but I don't like how it comes with a file manager. I'd like to be able to have a seperate file manager and xdg opener, so I can pick and choose easily. Also rox can't open urls.

    It seems that xdg-open will always use one's browser if one does not have a major DE (that is KDE, Gnome or XFCE). This is denoted generic in xdg-utils.
    From the change log it seems that xdg-open would query mimeopen . This functionality is not present in xdg-open at the moment though. I might have something to do with this bug.
    I found a nice patch that will make query mimeopen when using xdg-open.
    The patch is located here.
    Basically one just needs to change the open_generic() function in /usr/bin/xdg-open to:
    open_generic()
    if mimeopen -v 2>/dev/null 1>&2; then
    mimeopen -n "$1"
    if [ $? -eq 0 ]; then
    exit_success
    fi
    fi
    IFS=":"
    for browser in $BROWSER; do
    if [ x"$browser" != x"" ]; then
    browser_with_arg=`echo "$browser" | sed s#%s#"$1"#`
    if [ x"$browser_with_arg" = x"$browser" ]; then "$browser" "$1";
    else $browser_with_arg;
    fi
    if [ $? -eq 0 ]; then exit_success;
    fi
    fi
    done
    exit_failure_operation_impossible "no method available for opening '$1'"
    It works well for me. I don't know why the removed this IMO essential feature. They mention something about protocols in the bug report. . . If somebody knows more please enlighten me.
    --Rasmus

  • Modify xdg-open to work better in gnome?

    /usr/bin/xdg-open uses gnome-open to open files, if it determines that the user uses Gnome. However, as documented here : https://bugs.launchpad.net/ubuntu/+sour … bug/209714 , since the new Gnome uses gvfs-open, gnome-open is deprecated. I believe it would be a simple matter for Arch devs to modify xdg-utils to comply, all they have to do is change the code in /usr/bin/xdg-open
    open_gnome()
    gnome-open "$1"
    if [ $? -eq 0 ]; then
    exit_success
    else
    exit_failure_operation_failed
    fi
    to
    open_gnome()
    gvfs-open "$1"
    if [ $? -eq 0 ]; then
    exit_success
    else
    exit_failure_operation_failed
    fi
    Any thoughts on this?

    /usr/bin/xdg-open uses gnome-open to open files, if it determines that the user uses Gnome. However, as documented here : https://bugs.launchpad.net/ubuntu/+sour … bug/209714 , since the new Gnome uses gvfs-open, gnome-open is deprecated. I believe it would be a simple matter for Arch devs to modify xdg-utils to comply, all they have to do is change the code in /usr/bin/xdg-open
    open_gnome()
    gnome-open "$1"
    if [ $? -eq 0 ]; then
    exit_success
    else
    exit_failure_operation_failed
    fi
    to
    open_gnome()
    gvfs-open "$1"
    if [ $? -eq 0 ]; then
    exit_success
    else
    exit_failure_operation_failed
    fi
    Any thoughts on this?

  • Xdg-open, magnets and KDE

    I had a problem to open magnet files from chromium. The torrent client didn't seem to launch.
    $ xdg-mime query default "x-scheme-handler/magnet"
    transmission-qt.desktop
    mime type seemed to be linked to the correct application.
    Trying to launch xdg-open from terminal :
    $ xdg-open "magnet:?somemagnet"
    QWidget: Cannot create a QWidget when no GUI is being used
    /usr/bin/xdg-open: line 513: 1568 Aborted (core dumped) kde-open --noninteractive "$1"
    I don't know why this doesn't work, or why I can't find any reference of other people with the same problem.
    I resolved the problem by patching xdg-open. I removed the --noninteractive flag from kde-open command, and all seems to work fine now. Still it troubles me why the xdg-open script doesn't work out of the box. Any ideas?

    Related bug reports in xdg-utils and KDE:
    Bug 269823 - kde-open --noninteractive foo.noassoc crashes
    Bug 16295 - xdg-open is inconsistent across desktop environments (also see http://cgit.freedesktop.org/xdg/xdg-uti … bf7ce76cb3)
    EDIT: I've opened a bug report at KDE: https://bugs.kde.org/show_bug.cgi?id=336117
    EDIT: And there's already a bug report in Arch: https://bugs.archlinux.org/task/40795
    Last edited by joschi (2014-06-12 12:24:56)

  • Is my HD Dead? Reformat Disk Utility Error: secure disk erase failed with the error could not open disk.

    Hi,
    Fed up with seeing the spinning beach ball I decided to reformat my MacBook Pro...
    After backing up everything on an external hard drive I put in the OSX install DVD, restarted the machine and held down 'C'.
    I followed the install prcedure, clicking next a few times etc...
    I then went into Utilities > Disk Utility. I chose 7-Pass to erase the Macintosh HD and set it off erasing.
    I checked the process an hour in and message on screen read:
    Secure disk erase failed with the error:
    could not open disk
    The internal hard drive no longer exists in the disk utility so I cant retry erasing it.
    The only thing that appears in disk utility is the OSX install DVD.
    I can't even shut down the mac as everything under the apple tab is greyed out!
    I'm guessing this means my hard drive is broken right?
    If anyone has any other ideas of what to try I'd really appreciate that.
    How do I turn the machine off?
    If my hard drive is gone then should I consider getting an SSD drive?
    Any recommendations for such a drive would be great.
    Hope you can help!

    Did you partition the drive?
    Extended Hard Drive Preparation
    1. Open Disk Utility in your Utilities folder. If you need to reformat your startup volume, then you must boot from your OS X Installer Disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Installer menu (Utilities menu for Tiger or Leopard.)
    2. After DU loads select your hard drive (this is the entry with the mfgr.'s ID and size) from the left side list. Note the SMART status of the drive in DU's status area. If it does not say "Verified" then the drive is failing or has failed and will need replacing. SMART info will not be reported on external drives. Otherwise, click on the Partition tab in the DU main window.
    3. Click on the Options button, set the partition scheme to GUID (only required for Intel Macs) then click on the OK button. Set the number of partitions from the dropdown menu (use 1 partition unless you wish to make more.) Set the format type to Mac OS Extended (Journaled.) Click on the Partition button and wait until the volume(s) mount on the Desktop.
    4. Select the volume you just created (this is the sub-entry under the drive entry) from the left side list. Click on the Erase tab in the DU main window.
    5. Set the format type to Mac OS Extended (Journaled.) Click on the Options button, check the button for Zero Data and click on OK to return to the Erase window.
    6. Click on the Erase button. The format process can take up to several hours depending upon the drive size.
    Steps 4-6 are optional but should be used on a drive that has never been formatted before, if the format type is not Mac OS Extended, if the partition scheme has been changed, or if a different operating system (not OS X) has been installed on the drive.

  • [SOLVED] xdg-open: no method available for opening

    I'm using Openbox. Whenever I try to use xdg-open to open a file or link from the command line, I get the error "xdg-open: no method available for opening". This happens with all files and links, regardless of type. I've tried editing ~/.local/share/applications/mimeapps.list, both manually and with xdg-mime; neither had any effect. I've also tried setting environment variables such as $BROWSER; that had no effect, either.
    Strangely, exo-open works with no problem (although the only way I've found to change file associations is by using Thunar). I would just switch to exo-open, except I've encountered a couple of programs that rely on xdg-open for opening web links and the like.
    Has anyone else seen this problem? At this point, I'm pretty confused, and I would appreciate any help. Thanks!
    Last edited by morganmay (2013-11-19 16:31:08)

    Was poking around with this again. I still haven't solved the problem, but I did notice an error that might be a clue. When I enter "xdg-settings get default-url-scheme-handler", I get the error "xdg-settings: unknown desktop environment". I don't have a DE installed, just openbox (although as far as I can tell, XDG doesn't require a DE).
    Does anyone know what this means? Searches for this error have only led me to threads recommending solutions that I've already tried without success (editing mimeapps.list, setting environment variables like BROWSER, etc.).

  • Xdg-open is opening files with no extension in wine notepad

    xdg-open is opening files with no extension in wine notepad. This is really annoying. How can I change it?

    Click on "Browse" button at the "Open With" dialog and navigate to the location, where acrord32.exe is located. Preferebly, it should be this location "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe" unless you have installed at some customized location.  I'm assuming you have installed Reader 9. Once you add Adobe Reader in the open with list, it would continue to appear next time onwards.

  • [solved] xdg-open url.jpg opens it in firefox

    Hello,
    I'm working on xfce. While clicking in psi IM to a http://....image.jpg link, the image gets opened in a new card of Firefox. Firefox is my default browser. In terminal
    xdg-open http://upload.koci.net.pl/uploads/crusader.jpg
    does the same. I wish this image to be opened in my image viewer, not in Firefox. In xfce's MIME type configuration I can see image image/jpeg is set to Ristretto.
    Last edited by mkkot (2013-06-11 15:29:41)

    Creating your own script could work.  But my best recommendation would be to use one of the ready made replacements for xdg-open.  I've never used it enough to have a real opinion on it, but you're not the first to be unsatisfied with xdg-open - and when archers are unsatisfied, they write solutions.
    There is a relatively recently active thread one one archers solution to this problem ... was it mimi or mimi-open, something like that.  I've never had a need for such a tool, but it seems to have been warmly received by other users, so it may do what you want.

  • Xdg-open is slow opening files

    Whenever I use xdg-open to open an application it takes a while until the application is shown, but if I try to open it with the application itself it works almost instantaneously. While using xdg-open I can notice a high increase of the cpu usage.
    What could it be that's causing this issue? Is there maybe a log file I can check to see what's going on under the hood? This issue is happening with gpicview (for images), nemo, and thunar; I haven't tried with other applications but I assume it's going to be the same.
    As relevant info I might add that I'm using openbox and no desktop environment. I'll upload any config files if requested, but I don't really know what to include as a start besides my mimeapps.list:
    #~/.local/share/applications/mimeapps.list
    [Default Applications]
    inode/directory=Thunar.desktop
    image/png=gpicview.desktop
    [Added Associations]
    image/png=gpicview.desktop;
    I've checked the wiki for xdg-open and all the forums (arch and outside of arch) and have just found people with the same issue, but no answers whatsoever.
    Any help on this would be much appreciated.

    After analyzing the loop (and the inner search_desktop_file function), I can tell that function is what's taking all the CPU time, also I can tell that only 3 iterations of the loop are run, one for each X, which have the values:
    $x_1 = Thunar.desktop /home/josep/.local/share/
    $x_2 = Thunar.desktop /usr/local/share/
    $x_3 = /usr/share/
    I can tell the first two searches take close to no time, and actually, the binary /usr/bin/thunar, which is located in the third iteration, doesn't take much time either, so surprisingly what's eating most of CPU resources is this part of the script:
    command="$(get_key "${file}" "Exec" | first_word)"
    command_exec=`which $command 2>/dev/null`
    arguments="$(get_key "${file}" "Exec" | last_word)"
    arg_one="`echo "$arg" | sed 's/[&*\\]/\\\\&/g'`"
    icon="$(get_key "${file}" "Icon")"
    if [ "${icon}" != "" ]
    then
    icon="--icon '${icon}'"
    else
    icon="''"
    fi
    # FIXME: Actually LC_MESSAGES should be used as described in
    # http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s04.html
    localised_name="'$(get_key "${file}" "Name")'"
    arguments_exec="$(echo "$arguments" | sed -e 's*%[fFuU]*"'"$arg_one"'"*g' \
    -e 's*%i*'"$icon"'*g' \
    -e 's*%c*'"$localised_name"'*g')"
    The first two variables command and command_exec are set to "thunar" and "/usr/bin/thunar", and this happens relatively fast (although it takes some time to find it, it's not even a 10% of the total time).
    EDIT: I think all signs lead to the disk read taking too long (for example the get_key function which reads the .desktop file looking for the asked key, takes too much), but this is weird, as I had never encountered this issue in other linux distributions, everything has ran always smooth and fine, despite not having a good machine.
    EDIT2: After finally tracking down the issue, I've found this loop: (inside the get_key function)
    while read line
    do
    echo "readline" 1>&2
    case "$line" in
    "[Desktop Entry]")
    desktop_entry="y"
    # Reset match flag for other groups
    desktop_entry=""
    # Only match Desktop Entry group
    if [ -n "${desktop_entry}" ]
    then
    echo "${line}" | grep -E "^${key}=" | cut -d= -f 2-
    fi
    esac
    done < "${file}"
    More than 90% of CPU time is spent in this function, but I can't see why. Parsing a .desktop file is not a difficult task by any means and even if this was reading the file every time, everything would be cached in the ram anyway, as modern OSs use paging for that matter (and by modern I mean not modern at all) and I'm well aware that linux does).
    So TL;DR I don't understand how can the simple task of parsing a .desktop file take more time than opening google chrome or gimp. Any help on that?
    Last edited by setzer22 (2014-07-27 19:07:43)

Maybe you are looking for