Skip to content

Commit f9fd52d

Browse files
author
Ed Morley
committed
Make get_option() handle duplicate options in my_print_defaults output
get_option() was added by #53 to extract `socket` and `pid-file` from my_print_defaults. However if a custom mysql configuration file has been added, my_print_defaults returns duplicates (it merely lists all options specified in any config file and doesn't de-dupe). In these cases, `ret` would equal `/var/run/mysqld/mysqld.sock /var/lib/mysql/mysql.sock`, causing: `/entrypoint.sh: line 9: [: /var/run/mysqld/mysqld.sock: binary operator expected` As such, get_option() should just return the last matching option found in the my_print_defaults output - which should correspond to the one in the custom configuration file (rather than say the global default). Fixes #74.
1 parent f1b05ac commit f9fd52d

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

5.5/docker-entrypoint.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ get_option () {
55
local section=$1
66
local option=$2
77
local default=$3
8-
ret=$(my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2-)
8+
# my_print_defaults can output duplicates, if an option exists both globally and in
9+
# a custom config file. We pick the last occurence, which is from the custom config.
10+
ret=$(my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2- | tail -n1)
911
[ -z $ret ] && ret=$default
1012
echo $ret
1113
}

5.6/docker-entrypoint.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ get_option () {
55
local section=$1
66
local option=$2
77
local default=$3
8-
ret=$(my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2-)
8+
# my_print_defaults can output duplicates, if an option exists both globally and in
9+
# a custom config file. We pick the last occurence, which is from the custom config.
10+
ret=$(my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2- | tail -n1)
911
[ -z $ret ] && ret=$default
1012
echo $ret
1113
}

5.7/docker-entrypoint.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ get_option () {
55
local section=$1
66
local option=$2
77
local default=$3
8-
ret=$(my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2-)
8+
# my_print_defaults can output duplicates, if an option exists both globally and in
9+
# a custom config file. We pick the last occurence, which is from the custom config.
10+
ret=$(my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2- | tail -n1)
911
[ -z $ret ] && ret=$default
1012
echo $ret
1113
}
@@ -77,6 +79,7 @@ if [ "$1" = 'mysqld' ]; then
7779
echo 'FLUSH PRIVILEGES ;' >> "$tempSqlFile"
7880

7981
mysql -uroot < "$tempSqlFile"
82+
8083
rm -f "$tempSqlFile"
8184
kill $(cat $PIDFILE)
8285
for i in $(seq 30 -1 0); do
@@ -95,4 +98,3 @@ if [ "$1" = 'mysqld' ]; then
9598
fi
9699

97100
exec "$@"
98-

0 commit comments

Comments
 (0)