Skip to content

Commit cdd57aa

Browse files
committed
Bug#25088048 ADDITIONAL ISSUES IN MYSQLD_SAFE
Don't read --ledir option from config file. Ignore current working for finding location of mysqld Remove use of chown/chmod in scripts. Be helpful only when basedir is /var/log or /var/lib. Removed unused systemd files for SLES. Set explicit basedir in scripts.
1 parent a63185e commit cdd57aa

File tree

9 files changed

+41
-138
lines changed

9 files changed

+41
-138
lines changed

packaging/rpm-oel/mysql-systemd-start

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ install_db () {
2222
datadir=$(get_option mysqld datadir "/var/lib/mysql")
2323

2424
# Restore log, dir, perms and SELinux contexts
25-
[ -d "$datadir" ] || install -d -m 0755 -omysql -gmysql "$datadir" || exit 1
25+
if [ ! -d "$datadir" -a ! -h "$datadir" -a "x$(basedir "$datadir")" = "x/var/lib" ]; then
26+
install -d -m 0755 -omysql -gmysql "$datadir" || exit 1
27+
fi
2628
log=/var/log/mysqld.log
2729
[ -e $log ] || touch $log
2830
chmod 0640 $log

packaging/rpm-oel/mysql.init

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,19 @@ start(){
7070
ret=0
7171
else
7272
# prepare for start
73-
touch "$errlogfile"
74-
chown mysql:mysql "$errlogfile"
75-
chmod 0640 "$errlogfile"
73+
if [ ! -e "$errlogfile" -a ! -h "$errlogfile" -a "x$(dirname "$errlogfile")" = "x/var/log" ]; then
74+
install /dev/null -m0640 -omysql -gmysql "$errlogfile"
75+
fi
7676
[ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"
7777
if [ ! -d "$datadir/mysql" ] ; then
7878
# First, make sure $datadir is there with correct permissions
79-
if [ ! -e "$datadir" -a ! -h "$datadir" ]
80-
then
81-
mkdir -p "$datadir" || exit 1
79+
if [ ! -d "$datadir" -a ! -h "$datadir" -a "x$(basedir "$datadir")" = "x/var/lib" ]; then
80+
install -d -m0755 -omysql -gmysql "$datadir" || exit 1
81+
fi
82+
if [ ! -h "$datadir" -a "x$(basedir "$datadir")" = "x/var/lib" ]; then
83+
chown mysql:mysql "$datadir"
84+
chmod 0755 "$datadir"
8285
fi
83-
chown mysql:mysql "$datadir"
84-
chmod 0755 "$datadir"
8586
if [ -x /sbin/restorecon ]; then
8687
/sbin/restorecon "$datadir"
8788
for dir in /var/lib/mysql-files ; do
@@ -94,13 +95,14 @@ start(){
9495
# Now create the database
9596
action $"Initializing MySQL database: " /usr/bin/mysql_install_db --rpm --datadir="$datadir" --user=mysql
9697
ret=$?
97-
chown -R mysql:mysql "$datadir"
9898
if [ $ret -ne 0 ] ; then
9999
return $ret
100100
fi
101101
fi
102-
chown mysql:mysql "$datadir"
103-
chmod 0755 "$datadir"
102+
if [ ! -h "$datadir" -a "x$(basedir "$datadir")" = "x/var/lib" ]; then
103+
chown mysql:mysql "$datadir"
104+
chmod 0755 "$datadir"
105+
fi
104106
# Pass all the options determined above, to ensure consistent behavior.
105107
# In many cases mysqld_safe would arrive at the same conclusions anyway
106108
# but we need to be sure. (An exception is that we don't force the

packaging/rpm-oel/mysqld.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ PermissionsStartOnly=true
3434
ExecStartPre=/usr/bin/mysql-systemd-start pre
3535

3636
# Start main service
37-
ExecStart=/usr/bin/mysqld_safe
37+
ExecStart=/usr/bin/mysqld_safe --basedir=/usr
3838

3939
# Don't signal startup success before a ping works
4040
ExecStartPost=/usr/bin/mysql-systemd-start post

packaging/rpm-sles/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -20,7 +20,6 @@ IF(UNIX)
2020
# Left in current directory, to be taken during build
2121
CONFIGURE_FILE(mysql.spec.in ${CMAKE_CURRENT_BINARY_DIR}/${SPECFILENAME} @ONLY)
2222
FOREACH(fedfile my.cnf my_config.h mysql.init
23-
mysqld.service mysql-systemd-start mysql.conf
2423
filter-requires.sh filter-provides.sh)
2524
CONFIGURE_FILE(${fedfile} ${CMAKE_CURRENT_BINARY_DIR}/${fedfile} COPYONLY)
2625
ENDFOREACH()

packaging/rpm-sles/mysql-systemd-start

Lines changed: 0 additions & 66 deletions
This file was deleted.

packaging/rpm-sles/mysql.conf

Lines changed: 0 additions & 1 deletion
This file was deleted.

packaging/rpm-sles/mysql.init

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ get_option () {
4949
datadir=$(get_option mysqld datadir "/var/lib/mysql")
5050
socket=$(get_option mysqld socket "$datadir/mysql.sock")
5151
pidfile=$(get_option mysqld_safe pid-file "/var/run/mysql/mysqld.pid")
52-
logfile=$(get_option mysqld_safe log-error "/var/log/mysql/mysqld.log")
5352

5453
install_db () {
5554
# Note: something different than datadir=/var/lib/mysql requires
@@ -58,14 +57,16 @@ install_db () {
5857
logfile=$(get_option mysqld_safe log-error "/var/log/mysql/mysqld.log")
5958

6059
# Restore log, dir, perms and SELinux contexts
61-
[ -d "$datadir" ] || install -d -m 0755 -omysql -gmysql "$datadir" || return 1
60+
if [ ! -d "$datadir" -a ! -h "$datadir" -a "x$(basedir "$datadir")" = "x/var/lib" ]; then
61+
install -d -m 0755 -omysql -gmysql "$datadir" || return 1
62+
fi
6263

63-
[ -e $logfile ] || touch $logfile || return 1
64-
chmod 0640 $logfile
65-
chown mysql:mysql $logfile || return 1
64+
if [ ! -e "$logfile" -a ! -h "$logfile" -a "x$(dirname "$logfile")" = "x/var/log/mysql" ]; then
65+
install /dev/null -omysql -gmysql "$logfile" || return 1
66+
fi
6667
if [ -x /usr/sbin/restorecon ]; then
6768
/usr/sbin/restorecon "$datadir"
68-
/usr/sbin/restorecon $logfile
69+
/usr/sbin/restorecon "$logfile"
6970
fi
7071

7172
# If special mysql dir is in place, skip db install

packaging/rpm-sles/mysqld.service

Lines changed: 0 additions & 48 deletions
This file was deleted.

scripts/mysqld_safe.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,13 @@ parse_arguments() {
218218

219219
# mysqld_safe-specific options - must be set in my.cnf ([mysqld_safe])!
220220
--core-file-size=*) core_file_size="$val" ;;
221-
--ledir=*) ledir="$val" ;;
221+
--ledir=*)
222+
if [ -z "$pick_args" ]; then
223+
log_error "--ledir option can only be used as command line option, found in config file"
224+
exit 1
225+
fi
226+
ledir="$val"
227+
;;
222228
--malloc-lib=*) set_malloc_lib "$val" ;;
223229
--mysqld=*)
224230
if [ -z "$pick_args" ]; then
@@ -394,7 +400,15 @@ else
394400
relpkgdata='@pkgdatadir@'
395401
fi
396402

397-
MY_PWD=`pwd`
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
398412
# Check for the directories we would expect from a binary release install
399413
if test -n "$MY_BASEDIR_VERSION" -a -d "$MY_BASEDIR_VERSION"
400414
then

0 commit comments

Comments
 (0)