Skip to content

Commit b7f33d2

Browse files
committed
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
1 parent df6e016 commit b7f33d2

File tree

2 files changed

+69
-79
lines changed

2 files changed

+69
-79
lines changed

scripts/mysqld_safe.sh

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ esac
6464
usage () {
6565
cat <<EOF
6666
Usage: $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+
398434
else
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@'
444460
fi
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
464475
else
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"
508508
else
509509
print_defaults="my_print_defaults"
510510
fi
@@ -515,6 +515,8 @@ append_arg_to_args () {
515515

516516
args=
517517

518+
cd "$oldpwd"
519+
518520
SET_USER=2
519521
parse_arguments `$print_defaults $defaults --loose-verbose mysqld server`
520522
if test $SET_USER -eq 2
@@ -613,7 +615,7 @@ fi
613615
logdir=`dirname "$err_log"`
614616
# Change the err log to the right user, if possible and it is in use
615617
if [ $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

support-files/mysql.server.sh

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,8 @@ wait_for_pid () {
200200

201201
# Get arguments from the my.cnf file,
202202
# the only group, which is read from now on is [mysqld]
203-
if test -x ./bin/my_print_defaults
204-
then
205-
print_defaults="./bin/my_print_defaults"
206-
elif test -x $bindir/my_print_defaults
207-
then
203+
if test -x "$bindir/my_print_defaults"; then
208204
print_defaults="$bindir/my_print_defaults"
209-
elif test -x $bindir/mysql_print_defaults
210-
then
211-
print_defaults="$bindir/mysql_print_defaults"
212205
else
213206
# Try to find basedir in /etc/my.cnf
214207
conf=/etc/my.cnf
@@ -225,11 +218,6 @@ else
225218
print_defaults="$d/bin/my_print_defaults"
226219
break
227220
fi
228-
if test -x "$d/bin/mysql_print_defaults"
229-
then
230-
print_defaults="$d/bin/mysql_print_defaults"
231-
break
232-
fi
233221
done
234222
fi
235223

0 commit comments

Comments
 (0)