Bug #5006 mysql_config reports invalid info when it is run from a symbolic link
Submitted: 11 Aug 2004 22:50 Modified: 9 Sep 2004 16:25
Reporter: Dan Voeks Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.0.20 OS:Linux (Red Hat Enterprise Linux 3)
Assigned to: Victor Vagin CPU Architecture:Any

[11 Aug 2004 22:50] Dan Voeks
Description:
if mysql_config is executed via a symbolic link (say in /usr/local/bin/mysql_config), it reports different (and incorrect) information than if it is run by specifying its actual path (say /usr/local/mysql/bin/mysql_config).

How to repeat:
install mysql into /usr/local/mysql
create a symlink for /usr/local/mysql/bin/mysql_config in /usr/local/bin
execute /usr/local/bin/mysql_config --libs
execute /usr/local/mysql/bin/mysql_config --libs
compare the results

Suggested fix:
modify the code so that it correctly detects library locations regardless of what path is used to execute the binary
[11 Aug 2004 23:48] Matthew Lord
This also occurs with 4.1.3-beta.  I tested this on x86 linux (RH 9  2.4.21 #12 SMP)

booty-[~]$mysql_config
Usage: /usr/local/mysql/bin/mysql_config [OPTIONS]
Options:
        --cflags         [-I/usr/local/mysql/include/mysql -mcpu=pentiumpro]
        --include        [-I/usr/local/mysql/include/mysql]
        --libs           [-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib -lssl 
-lcrypto]
        --libs_r         [-L/usr/local/mysql/lib/mysql -lmysqlclient_r -lpthread -lz -lcrypt -lnsl -lm 
-lpthread -L/usr/lib -lssl -lcrypto]
        --socket         [/tmp/mysql.sock]
        --port           [3306]
        --version        [4.1.3-beta]
        --libmysqld-libs [-L/usr/local/mysql/lib/mysql -lmysqld -lpthread -lz -lcrypt -lnsl -lm 
-lpthread -lrt]
booty-[~]$/usr/bin/mysql_config 
Usage: /usr/bin/mysql_config [OPTIONS]
Options:
        --cflags         [-I/usr/include -mcpu=pentiumpro]
        --include        [-I/usr/include]
        --libs           [-L/usr/lib -lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib -lssl -lcrypto]
        --libs_r         [-L/usr/lib -lmysqlclient_r -lpthread -lz -lcrypt -lnsl -lm -lpthread -L/usr/lib -lssl 
-lcrypto]
        --socket         [/tmp/mysql.sock]
        --port           [3306]
        --version        [4.1.3-beta]
        --libmysqld-libs [-L/usr/lib -lmysqld -lpthread -lz -lcrypt -lnsl -lm -lpthread -lrt]
[6 Sep 2004 15:07] Victor Vagin
subj: bk commit into 4.0 tree (vva:1.1957)

ChangeSet
  1.1957 04/09/06 18:49:16 vva@eagle.mysql.r18.ru +1 -0
  added resolving of soft links in mysql_config
  (fixed Bug #5006 mysql_config reports 
   invalid info when it is run from a symbolic link)
[9 Sep 2004 16:25] Victor Vagin
OK, i wrote patch:

----------------------------------------
--- 1.11/scripts/mysql_config.sh	Fri Feb 20 15:02:31 2004
+++ 1.12/scripts/mysql_config.sh	Mon Sep  6 18:49:08 2004
@@ -67,7 +67,25 @@
    esac
 }
 
+resolve_links()
+{
+  full_path=$1
+  ls_result=`ls -l $full_path`
+  echo $ls_result|grep -e "->" > /dev/null
+  errcode=$?
+  if test "x$errcode" != "x0"; then
+    echo "$full_path"
+  else
+    new_path=`echo $ls_result|sed -e 's;.*-> ;;'`
+    dname=`dirname $full_path`
+    interim_path=$dname/$new_path
+    final_path=`resolve_links $interim_path`
+    echo "$final_path"
+  fi
+}
+
 me=`get_full_path $0`
+me=`resolve_links $me`
 
 basedir=`echo $me | sed -e 's;/bin/mysql_config;;'`
----------------------------------------

But after discussion with the team we decided that it isn't a real bug

actually, One may want to symlink mysql_config to another dir to pretend MySQL was installed there. One shouldn't symlink it otherwise.

so we won't push the fix into the repository to not support superfluous code.

to settle the problem, you can apply the patch independently
or use cd command to run mysql_config in the right directory
[9 Sep 2004 16:55] Dan Voeks
This most definitely is a bug.  Executing a binary program via a symlink should NEVER result in different behavior than when executed directly.