xnview.sh infinitely eats memory (fixed xnview.sh included)

Bugs and Suggestions in XnView MP or XnConvert MP which have been resolved.

Moderators: helmut, XnTriq, xnview

*Dark Dragon*
Posts: 8
Joined: Sat Dec 11, 2010 11:35 pm

xnview.sh infinitely eats memory (fixed xnview.sh included)

Post by *Dark Dragon* »

I have tried 0.32 version of XnViewMP (for Linux) but when I tried to run it, it started to infinitely "eat" memory and CPU. This happened because of this part in xnview.sh:

Code: Select all

dirname=`dirname $0`
To reproduce the problem create a symbolic link to xnview.sh like this:

Code: Select all

ln -s "`pwd`"/xnview.sh /usr/local/bin/xnview
Try to run /usr/local/bin/xnview and xnview.sh will call itself infinitely. If you give different name to the symlink or extract XnViewMP package to a directory with space(s) (like "XnViewMP 0.32") xnview.sh will fail too because it can't handle spaces and can't resolve symlinks. To solve these problems, I edited xnview.sh and now it looks like this:

Code: Select all

#!/bin/sh
dirname="$(dirname "$(readlink "$0")")"
export LD_LIBRARY_PATH="$dirname"/lib
export QT_PLUGIN_PATH="$dirname"/lib
"$dirname"/xnview "$@"
This version of xnview.sh fixes all bugs in the original xnview.sh.

Of course I give you permission to use the fixed version of xnview.sh for any purpose (I hope you include it in next version of XnViewMP :) ).

Thank you very much for making XnViewMP and supporting Linux. You did wonderful work!
User avatar
oops66
XnThusiast
Posts: 2005
Joined: Tue Jul 17, 2007 1:17 am
Location: France

Re: xnview.sh infinitely eats memory (fixed xnview.sh includ

Post by oops66 »

Hello,
...Right that works, thank you for sharing your solution.
XnViewMP Linux X64 - Debian - X64
User avatar
Karl02
Posts: 134
Joined: Mon Sep 03, 2007 1:00 pm
Location: Germany

Re: xnview.sh infinitely eats memory (fixed xnview.sh includ

Post by Karl02 »

This code is now included in XnViewMP v0.33, but unfortunately it doesn't work if xnview.sh is called from another directory or via more than one link. :(

Fortunately, there is a "-e" option in readlink to get the canonical path (see "man readlink"). :D

With this enhancement and putting the whole path and file names in quotation marks, the code will be as follows:

Code: Select all

#!/bin/sh
dirname="$(dirname "$(readlink -e "$0")")"
export LD_LIBRARY_PATH="$dirname/lib"
export QT_PLUGIN_PATH="$dirname/lib"
"$dirname/xnview" "$@"
-- Karl