Page 1 of 1

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

Posted: Sun Dec 12, 2010 5:48 am
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!

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

Posted: Tue Dec 14, 2010 12:59 am
by oops66
Hello,
...Right that works, thank you for sharing your solution.

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

Posted: Sun Dec 26, 2010 2:00 pm
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" "$@"