Page 1 of 1

Bug in standalone subsonic.sh

PostPosted: Sat Oct 30, 2010 9:10 am
by delcypher
Hi came across a bug today when trying out Subsonic 4.1 in the bash shell script.

The bug is on lines 103-105

Code: Select all
if [ -e /bin/readlink ] || [ -e /usr/bin/readlink ]; then
    cd $(dirname $(readlink $0))
fi


In my case $0='./subsonic.sh' and I have readlink (GNU coreutils) 8.6

Because I have readlink installed the if statement succeeds. The command $(readlink $0) returns nothing as it only returns a value if the file soft link. In my case ./subsonic.sh is not a soft link.

so then the command becomes
cd $(dirname )

dirname returns an error because it has no argument. Which means the finally executed command is just cd. This changes directory to the user's home directory which consequently causes subsonic to not start because the command to start subsonic assumes the jar file is in the current directory.

Code: Select all

${JAVA} -Xmx${SUBSONIC_MAX_MEMORY}m \
  -Dsubsonic.home=${SUBSONIC_HOME} \
  -Dsubsonic.host=${SUBSONIC_HOST} \
  -Dsubsonic.port=${SUBSONIC_PORT} \
  -Dsubsonic.contextPath=${SUBSONIC_CONTEXT_PATH} \
  -Dsubsonic.defaultMusicFolder=${SUBSONIC_DEFAULT_MUSIC_FOLDER} \
  -Dsubsonic.defaultPodcastFolder=${SUBSONIC_DEFAULT_PODCAST_FOLDER} \
  -Dsubsonic.defaultPlaylistFolder=${SUBSONIC_DEFAULT_PLAYLIST_FOLDER} \
  -jar subsonic-booter-jar-with-dependencies.jar > ${LOG} 2>&1 &


I propose these set of commands instead of the if statement shown at the beginning.

Code: Select all
#if script was executed via symbolic link we should change to the directory of the file linked to
if [ -n "$(which readlink 2> /dev/null)" -a -n "$(readlink $0 2> /dev/null)" ]; then
    cd $(dirname $(readlink $0))
fi


Hope someone finds this useful.

PostPosted: Sat Oct 30, 2010 9:17 am
by sindre_mehus
Hi,

Thanks for pointing that out. I am aware of it and have fixed it in the next release.

My fix (which another friendly user suggested) is slightly different, but achieves the same:

Code: Select all
cd $(dirname $0)
if [ -L $0 ] && ([ -e /bin/readlink ] || [ -e /usr/bin/readlink ]); then
    cd $(dirname $(readlink $0))
fi


Thanks,
Sindre