diff options
author | Terje Rosten <terje.rosten@oracle.com> | 2017-02-13 14:55:29 +0100 |
---|---|---|
committer | Terje Rosten <terje.rosten@oracle.com> | 2017-02-13 14:56:28 +0100 |
commit | b7f33d22d8f1af07deac57a3d51ac750788b812f (patch) | |
tree | ccfb2836089186003b40fbe8e2a10dc5ea618b02 | |
parent | df6e0160a4c3414d207020c0a1cfc8f79d1ea7bc (diff) | |
download | mariadb-git-b7f33d22d8f1af07deac57a3d51ac750788b812f.tar.gz |
Bug#25144379 MYSQLD PROCESS DOES NOT INCLUDE FULL PATH WHEN STARTING MYSQL SERVER
Fix of Bug#25088048 caused paths to be relative, not absolute, this
proved to be problematic.
Fix is to still ignore current working directory, however switch to
using full path of basedir, which is set to parent directory of bin/
directory where mysqld_safe is located.
References to legacy tool mysql_print_defaults are removed, only
my_print_defaults is used these days.
This will also fix:
Bug#11745176 (11192) MYSQLD_SAFE ONLY EVALUATES --DEFAULTS-FILE OPTION WHEN IT IS THE FIRST OP
Bug#23013510 (80866) MYSQLD_SAFE SHOULD NOT SEARCH $MY_BASEDIR_VERSION/VAR AS DATADIR
Bug#25244898 (84173) MYSQLD_SAFE --NO-DEFAULTS & SILENTLY DOES NOT WORK ANY MORE
Bug#25261472 (84219) INITSCRIPT ERRORS WHEN LAUCHING MYSQLD_SAFE IN NON DEFAULT BASEDIR
Bug#25319392 (84263) MYSQL.SERVER (MYSQL SERVER STARTUP SCRIPT) CAN NOT WORK,AND EXPORT SOME ERROR.
Bug#25319457 MYSQLD_SAFE MIGHT FAIL IF $DATADIR HAS TRAILING /
Bug#25341981 MYSQLD_SAFE ASSUMES INCORRECT BASEDIR WHEN EXECUTED WITH ABSOLUTE PATH
Bug#25356221 (84427) MYSQLD_SAFE FAILS TO START WHEN USING A FIFO FOR LOG-ERROR (REGRESSION)
Bug#25365194 (84447) MYSQLD_SAFE DOESN'T CHECK EXISTENCE OF GIVEN BASEDIR PARAMETER
Bug#25377815 ERRORS WHILE STARTING MYSQLD_SAFE WITH SYM LINK ENABLED
-rw-r--r-- | scripts/mysqld_safe.sh | 134 | ||||
-rw-r--r-- | support-files/mysql.server.sh | 14 |
2 files changed, 69 insertions, 79 deletions
diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index 5148ecfc888..7116211f8e6 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -64,9 +64,12 @@ esac usage () { cat <<EOF Usage: $0 [OPTIONS] + The following options may be given as the first argument: --no-defaults Don't read the system defaults file --defaults-file=FILE Use the specified defaults file --defaults-extra-file=FILE Also use defaults from the specified file + + Other options: --ledir=DIRECTORY Look for mysqld in the specified directory --open-files-limit=LIMIT Limit the number of open files --core-file-size=LIMIT Limit core files to the specified size @@ -205,7 +208,12 @@ parse_arguments() { case "$arg" in # these get passed explicitly to mysqld --basedir=*) MY_BASEDIR_VERSION="$val" ;; - --datadir=*) DATADIR="$val" ;; + --datadir=*) + case $val in + /) DATADIR=$val ;; + *) DATADIR="`echo $val | sed 's;/*$;;'`" ;; + esac + ;; --pid-file=*) pid_file="$val" ;; --plugin-dir=*) PLUGIN_DIR="$val" ;; --user=*) user="$val"; SET_USER=1 ;; @@ -387,63 +395,70 @@ set_malloc_lib() { add_mysqld_ld_preload "$malloc_lib" } +find_basedir_from_cmdline () { + for arg in "$@"; do + case $arg in + --basedir=*) + MY_BASEDIR_VERSION="`echo "$arg" | sed -e 's;^--[^=]*=;;'`" + # Convert to full path + cd "$MY_BASEDIR_VERSION" + if [ $? -ne 0 ] ; then + log_error "--basedir set to '$MY_BASEDIR_VERSION', however could not access directory" + exit 1 + fi + MY_BASEDIR_VERSION="`pwd`" + ;; + esac + done +} # # First, try to find BASEDIR and ledir (where mysqld is) # -if echo '@pkgdatadir@' | grep '^@prefix@' > /dev/null -then - relpkgdata=`echo '@pkgdatadir@' | sed -e 's,^@prefix@,,' -e 's,^/,,' -e 's,^,./,'` +oldpwd="`pwd`" + +# Args not parsed yet, check if --basedir was given on command line +find_basedir_from_cmdline "$@" + +# --basedir is already overridden on command line +if test -n "$MY_BASEDIR_VERSION" -a -d "$MY_BASEDIR_VERSION" ; then + # Search for mysqld and set ledir + for dir in @INSTALL_SBINDIR@ libexec sbin bin ; do + if test -x "$MY_BASEDIR_VERSION/$dir/mysqld" ; then + ledir="$MY_BASEDIR_VERSION/$dir" + break + fi + done + else - # pkgdatadir is not relative to prefix - relpkgdata='@pkgdatadir@' -fi + # Basedir should be parent dir of bindir, unless some non-standard + # layout is used -case "$0" in - /*) - MY_PWD='@prefix@' - ;; - *) - MY_PWD=`dirname $0` - MY_PWD=`dirname $MY_PWD` - ;; -esac -# Check for the directories we would expect from a binary release install -if test -n "$MY_BASEDIR_VERSION" -a -d "$MY_BASEDIR_VERSION" -then - # BASEDIR is already overridden on command line. Do not re-set. + cd "`dirname $0`" + if [ -h "$0" ] ; then + realpath="`ls -l "$0" | awk '{print $NF}'`" + cd "`dirname "$realpath"`" + fi + cd .. + MY_PWD="`pwd`" + + # Search for mysqld and set ledir and BASEDIR + for dir in @INSTALL_SBINDIR@ libexec sbin bin ; do + if test -x "$MY_PWD/$dir/mysqld" ; then + MY_BASEDIR_VERSION="$MY_PWD" + ledir="$MY_BASEDIR_VERSION/$dir" + break + fi + done - # Use BASEDIR to discover le. - if test -x "$MY_BASEDIR_VERSION/libexec/mysqld" - then - ledir="$MY_BASEDIR_VERSION/libexec" - elif test -x "$MY_BASEDIR_VERSION/sbin/mysqld" - then - ledir="$MY_BASEDIR_VERSION/sbin" - else - ledir="$MY_BASEDIR_VERSION/bin" + # If we still didn't find anything, use the compiled-in defaults + if test -z "$MY_BASEDIR_VERSION" ; then + MY_BASEDIR_VERSION='@prefix@' + ledir='@libexecdir@' fi -elif test -f "$relpkgdata"/english/errmsg.sys -a -x "$MY_PWD/bin/mysqld" -then - MY_BASEDIR_VERSION="$MY_PWD" # Where bin, share and data are - ledir="$MY_PWD/bin" # Where mysqld is -# Check for the directories we would expect from a source install -elif test -f "$relpkgdata"/english/errmsg.sys -a -x "$MY_PWD/libexec/mysqld" -then - MY_BASEDIR_VERSION="$MY_PWD" # Where libexec, share and var are - ledir="$MY_PWD/libexec" # Where mysqld is -elif test -f "$relpkgdata"/english/errmsg.sys -a -x "$MY_PWD/sbin/mysqld" -then - MY_BASEDIR_VERSION="$MY_PWD" # Where sbin, share and var are - ledir="$MY_PWD/sbin" # Where mysqld is -# Since we didn't find anything, used the compiled-in defaults -else - MY_BASEDIR_VERSION='@prefix@' - ledir='@libexecdir@' fi - # # Second, try to find the data directory # @@ -456,10 +471,6 @@ then then defaults="--defaults-extra-file=$DATADIR/my.cnf" fi -# Next try where the source installs put it -elif test -d $MY_BASEDIR_VERSION/var/mysql -then - DATADIR=$MY_BASEDIR_VERSION/var # Or just give up and use our compiled-in default else DATADIR=@localstatedir@ @@ -490,21 +501,10 @@ export MYSQL_HOME # Get first arguments from the my.cnf file, groups [mysqld] and [mysqld_safe] # and then merge with the command line arguments -if test -x "$MY_BASEDIR_VERSION/bin/my_print_defaults" -then +if test -x "$MY_BASEDIR_VERSION/bin/my_print_defaults" ; then print_defaults="$MY_BASEDIR_VERSION/bin/my_print_defaults" -elif test -x `dirname $0`/my_print_defaults -then - print_defaults="`dirname $0`/my_print_defaults" -elif test -x ./bin/my_print_defaults -then - print_defaults="./bin/my_print_defaults" -elif test -x @bindir@/my_print_defaults -then +elif test -x "@bindir@/my_print_defaults" ; then print_defaults="@bindir@/my_print_defaults" -elif test -x @bindir@/mysql_print_defaults -then - print_defaults="@bindir@/mysql_print_defaults" else print_defaults="my_print_defaults" fi @@ -515,6 +515,8 @@ append_arg_to_args () { args= +cd "$oldpwd" + SET_USER=2 parse_arguments `$print_defaults $defaults --loose-verbose mysqld server` if test $SET_USER -eq 2 @@ -613,7 +615,7 @@ fi logdir=`dirname "$err_log"` # Change the err log to the right user, if possible and it is in use if [ $logging = "file" -o $logging = "both" ]; then - if [ ! -f "$err_log" -a ! -h "$err_log" ]; then + if [ ! -e "$err_log" -a ! -h "$err_log" ]; then if test -w / -o "$USER" = "root"; then case $logdir in /var/log) @@ -633,7 +635,7 @@ if [ $logging = "file" -o $logging = "both" ]; then fi fi - if [ -f "$err_log" ]; then # Log to err_log file + if [ -f "$err_log" -o -p "$err_log" ]; then # Log to err_log file log_notice "Logging to '$err_log'." elif [ "x$user" = "xroot" ]; then # running as root, mysqld can create log file; continue echo "Logging to '$err_log'." >&2 diff --git a/support-files/mysql.server.sh b/support-files/mysql.server.sh index cb13d2f10ba..a2781ce3338 100644 --- a/support-files/mysql.server.sh +++ b/support-files/mysql.server.sh @@ -200,15 +200,8 @@ wait_for_pid () { # Get arguments from the my.cnf file, # the only group, which is read from now on is [mysqld] -if test -x ./bin/my_print_defaults -then - print_defaults="./bin/my_print_defaults" -elif test -x $bindir/my_print_defaults -then +if test -x "$bindir/my_print_defaults"; then print_defaults="$bindir/my_print_defaults" -elif test -x $bindir/mysql_print_defaults -then - print_defaults="$bindir/mysql_print_defaults" else # Try to find basedir in /etc/my.cnf conf=/etc/my.cnf @@ -225,11 +218,6 @@ else print_defaults="$d/bin/my_print_defaults" break fi - if test -x "$d/bin/mysql_print_defaults" - then - print_defaults="$d/bin/mysql_print_defaults" - break - fi done fi |