6464usage () {
6565 cat << EOF
6666Usage: $0 [OPTIONS]
67+ The following options may be given as the first argument:
6768 --no-defaults Don't read the system defaults file
6869 --defaults-file=FILE Use the specified defaults file
6970 --defaults-extra-file=FILE Also use defaults from the specified file
71+
72+ Other options:
7073 --ledir=DIRECTORY Look for mysqld in the specified directory
7174 --open-files-limit=LIMIT Limit the number of open files
7275 --core-file-size=LIMIT Limit core files to the specified size
@@ -205,7 +208,12 @@ parse_arguments() {
205208 case " $arg " in
206209 # these get passed explicitly to mysqld
207210 --basedir=* ) MY_BASEDIR_VERSION=" $val " ;;
208- --datadir=* ) DATADIR=" $val " ;;
211+ --datadir=* )
212+ case $val in
213+ /) DATADIR=$val ;;
214+ * ) DATADIR=" ` echo $val | sed ' s;/*$;;' ` " ;;
215+ esac
216+ ;;
209217 --pid-file=* ) pid_file=" $val " ;;
210218 --plugin-dir=* ) PLUGIN_DIR=" $val " ;;
211219 --user=* ) user=" $val " ; SET_USER=1 ;;
@@ -387,63 +395,70 @@ set_malloc_lib() {
387395 add_mysqld_ld_preload " $malloc_lib "
388396}
389397
398+ find_basedir_from_cmdline () {
399+ for arg in " $@ " ; do
400+ case $arg in
401+ --basedir=* )
402+ MY_BASEDIR_VERSION=" ` echo " $arg " | sed -e ' s;^--[^=]*=;;' ` "
403+ # Convert to full path
404+ cd " $MY_BASEDIR_VERSION "
405+ if [ $? -ne 0 ] ; then
406+ log_error " --basedir set to '$MY_BASEDIR_VERSION ', however could not access directory"
407+ exit 1
408+ fi
409+ MY_BASEDIR_VERSION=" ` pwd` "
410+ ;;
411+ esac
412+ done
413+ }
390414
391415#
392416# First, try to find BASEDIR and ledir (where mysqld is)
393417#
394418
395- if echo ' @pkgdatadir@' | grep ' ^@prefix@' > /dev/null
396- then
397- relpkgdata=` echo ' @pkgdatadir@' | sed -e ' s,^@prefix@,,' -e ' s,^/,,' -e ' s,^,./,' `
419+ oldpwd=" ` pwd` "
420+
421+ # Args not parsed yet, check if --basedir was given on command line
422+ find_basedir_from_cmdline " $@ "
423+
424+ # --basedir is already overridden on command line
425+ if test -n " $MY_BASEDIR_VERSION " -a -d " $MY_BASEDIR_VERSION " ; then
426+ # Search for mysqld and set ledir
427+ for dir in @INSTALL_SBINDIR@ libexec sbin bin ; do
428+ if test -x " $MY_BASEDIR_VERSION /$dir /mysqld" ; then
429+ ledir=" $MY_BASEDIR_VERSION /$dir "
430+ break
431+ fi
432+ done
433+
398434else
399- # pkgdatadir is not relative to prefix
400- relpkgdata=' @pkgdatadir@'
401- fi
435+ # Basedir should be parent dir of bindir, unless some non-standard
436+ # layout is used
402437
403- case " $0 " in
404- /* )
405- MY_PWD=' @prefix@'
406- ;;
407- * )
408- MY_PWD=` dirname $0 `
409- MY_PWD=` dirname $MY_PWD `
410- ;;
411- esac
412- # Check for the directories we would expect from a binary release install
413- if test -n " $MY_BASEDIR_VERSION " -a -d " $MY_BASEDIR_VERSION "
414- then
415- # BASEDIR is already overridden on command line. Do not re-set.
438+ cd " ` dirname $0 ` "
439+ if [ -h " $0 " ] ; then
440+ realpath=" ` ls -l " $0 " | awk ' {print $NF}' ` "
441+ cd " ` dirname " $realpath " ` "
442+ fi
443+ cd ..
444+ MY_PWD=" ` pwd` "
445+
446+ # Search for mysqld and set ledir and BASEDIR
447+ for dir in @INSTALL_SBINDIR@ libexec sbin bin ; do
448+ if test -x " $MY_PWD /$dir /mysqld" ; then
449+ MY_BASEDIR_VERSION=" $MY_PWD "
450+ ledir=" $MY_BASEDIR_VERSION /$dir "
451+ break
452+ fi
453+ done
416454
417- # Use BASEDIR to discover le.
418- if test -x " $MY_BASEDIR_VERSION /libexec/mysqld"
419- then
420- ledir=" $MY_BASEDIR_VERSION /libexec"
421- elif test -x " $MY_BASEDIR_VERSION /sbin/mysqld"
422- then
423- ledir=" $MY_BASEDIR_VERSION /sbin"
424- else
425- ledir=" $MY_BASEDIR_VERSION /bin"
455+ # If we still didn't find anything, use the compiled-in defaults
456+ if test -z " $MY_BASEDIR_VERSION " ; then
457+ MY_BASEDIR_VERSION=' @prefix@'
458+ ledir=' @libexecdir@'
426459 fi
427- elif test -f " $relpkgdata " /english/errmsg.sys -a -x " $MY_PWD /bin/mysqld"
428- then
429- MY_BASEDIR_VERSION=" $MY_PWD " # Where bin, share and data are
430- ledir=" $MY_PWD /bin" # Where mysqld is
431- # Check for the directories we would expect from a source install
432- elif test -f " $relpkgdata " /english/errmsg.sys -a -x " $MY_PWD /libexec/mysqld"
433- then
434- MY_BASEDIR_VERSION=" $MY_PWD " # Where libexec, share and var are
435- ledir=" $MY_PWD /libexec" # Where mysqld is
436- elif test -f " $relpkgdata " /english/errmsg.sys -a -x " $MY_PWD /sbin/mysqld"
437- then
438- MY_BASEDIR_VERSION=" $MY_PWD " # Where sbin, share and var are
439- ledir=" $MY_PWD /sbin" # Where mysqld is
440- # Since we didn't find anything, used the compiled-in defaults
441- else
442- MY_BASEDIR_VERSION=' @prefix@'
443- ledir=' @libexecdir@'
444460fi
445461
446-
447462#
448463# Second, try to find the data directory
449464#
@@ -456,10 +471,6 @@ then
456471 then
457472 defaults=" --defaults-extra-file=$DATADIR /my.cnf"
458473 fi
459- # Next try where the source installs put it
460- elif test -d $MY_BASEDIR_VERSION /var/mysql
461- then
462- DATADIR=$MY_BASEDIR_VERSION /var
463474# Or just give up and use our compiled-in default
464475else
465476 DATADIR=@localstatedir@
@@ -490,21 +501,10 @@ export MYSQL_HOME
490501
491502# Get first arguments from the my.cnf file, groups [mysqld] and [mysqld_safe]
492503# and then merge with the command line arguments
493- if test -x " $MY_BASEDIR_VERSION /bin/my_print_defaults"
494- then
504+ if test -x " $MY_BASEDIR_VERSION /bin/my_print_defaults" ; then
495505 print_defaults=" $MY_BASEDIR_VERSION /bin/my_print_defaults"
496- elif test -x ` dirname $0 ` /my_print_defaults
497- then
498- print_defaults=" ` dirname $0 ` /my_print_defaults"
499- elif test -x ./bin/my_print_defaults
500- then
501- print_defaults=" ./bin/my_print_defaults"
502- elif test -x @bindir@/my_print_defaults
503- then
506+ elif test -x " @bindir@/my_print_defaults" ; then
504507 print_defaults=" @bindir@/my_print_defaults"
505- elif test -x @bindir@/mysql_print_defaults
506- then
507- print_defaults=" @bindir@/mysql_print_defaults"
508508else
509509 print_defaults=" my_print_defaults"
510510fi
@@ -515,6 +515,8 @@ append_arg_to_args () {
515515
516516args=
517517
518+ cd " $oldpwd "
519+
518520SET_USER=2
519521parse_arguments ` $print_defaults $defaults --loose-verbose mysqld server`
520522if test $SET_USER -eq 2
613615logdir=` dirname " $err_log " `
614616# Change the err log to the right user, if possible and it is in use
615617if [ $logging = " file" -o $logging = " both" ]; then
616- if [ ! -f " $err_log " -a ! -h " $err_log " ]; then
618+ if [ ! -e " $err_log " -a ! -h " $err_log " ]; then
617619 if test -w / -o " $USER " = " root" ; then
618620 case $logdir in
619621 /var/log)
@@ -633,7 +635,7 @@ if [ $logging = "file" -o $logging = "both" ]; then
633635 fi
634636 fi
635637
636- if [ -f " $err_log " ]; then # Log to err_log file
638+ if [ -f " $err_log " -o -p " $err_log " ]; then # Log to err_log file
637639 log_notice " Logging to '$err_log '."
638640 elif [ " x$user " = " xroot" ]; then # running as root, mysqld can create log file; continue
639641 echo " Logging to '$err_log '." >&2
0 commit comments