Skip to content

Commit a647b3e

Browse files
committed
Merge branch 'mysql-5.6' into mysql-5.7
2 parents 261f626 + 304519f commit a647b3e

File tree

2 files changed

+102
-24
lines changed

2 files changed

+102
-24
lines changed

scripts/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,13 @@ STRING(REGEX REPLACE "[ ]+$" "" CFLAGS "${CFLAGS}")
244244
STRING(REGEX REPLACE "[ ]+$" "" CXXFLAGS "${CXXFLAGS}")
245245

246246
IF(UNIX)
247-
# FIND_PROC and CHECK_PID are used by mysqld_safe
247+
# SHELL_PATH, FIND_PROC, CHECK_PID are used by mysqld_safe
248+
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
249+
SET (SHELL_PATH "/bin/bash")
250+
ELSE()
251+
SET (SHELL_PATH "/bin/sh")
252+
ENDIF()
253+
248254
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
249255
SET (FIND_PROC
250256
"ps wwwp $PID | grep -v mysqld_safe | grep -- $MYSQLD > /dev/null")

scripts/mysqld_safe.sh

Lines changed: 95 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!@SHELL_PATH@
22
# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
33
# This file is public domain and comes with NO WARRANTY of any kind
44
#
@@ -132,9 +132,22 @@ log_generic () {
132132
echo "$msg"
133133
case $logging in
134134
init) ;; # Just echo the message, don't save it anywhere
135-
file) echo "$msg" >> "$err_log" ;;
135+
file)
136+
if [ -w / -o "$USER" = "root" ]; then
137+
true
138+
else
139+
echo "$msg" >> "$err_log"
140+
fi
141+
;;
136142
syslog) logger -t "$syslog_tag_mysqld_safe" -p "$priority" "$*" ;;
137-
both) echo "$msg" >> "$err_log"; logger -t "$syslog_tag_mysqld_safe" -p "$priority" "$*" ;;
143+
both)
144+
if [ -w / -o "$USER" = "root" ]; then
145+
true
146+
else
147+
echo "$msg" >> "$err_log"
148+
fi
149+
logger -t "$syslog_tag_mysqld_safe" -p "$priority" "$*"
150+
;;
138151
*)
139152
echo "Internal program error (non-fatal):" \
140153
" unknown logging method '$logging'" >&2
@@ -153,12 +166,23 @@ log_notice () {
153166
eval_log_error () {
154167
cmd="$1"
155168
case $logging in
156-
file) cmd="$cmd >> "`shell_quote_string "$err_log"`" 2>&1" ;;
169+
file)
170+
if [ -w / -o "$USER" = "root" ]; then
171+
cmd="$cmd > /dev/null 2>&1"
172+
else
173+
cmd="$cmd >> "`shell_quote_string "$err_log"`" 2>&1"
174+
fi
175+
;;
157176
syslog)
158177
cmd="$cmd --log-syslog=1 --log-syslog-facility=$syslog_facility '--log-syslog-tag=$syslog_tag' > /dev/null 2>&1"
159178
;;
160179
both)
161-
cmd="$cmd --log-syslog=1 --log-syslog-facility=$syslog_facility '--log-syslog-tag=$syslog_tag' >> "`shell_quote_string "$err_log"`" 2>&1" ;;
180+
if [ -w / -o "$USER" = "root" ]; then
181+
cmd="$cmd --log-syslog=1 --log-syslog-facility=$syslog_facility '--log-syslog-tag=$syslog_tag' > /dev/null 2>&1"
182+
else
183+
cmd="$cmd --log-syslog=1 --log-syslog-facility=$syslog_facility '--log-syslog-tag=$syslog_tag' >> "`shell_quote_string "$err_log"`" 2>&1"
184+
fi
185+
;;
162186
*)
163187
echo "Internal program error (non-fatal):" \
164188
" unknown logging method '$logging'" >&2
@@ -613,12 +637,48 @@ then
613637
else
614638
logging=file
615639
fi
640+
fi
616641

617-
if [ ! -f "$err_log" ]; then # if error log already exists,
618-
touch "$err_log" # we just append. otherwise,
619-
chmod "$fmode" "$err_log" # fix the permissions here!
642+
logdir=`dirname "$err_log"`
643+
# Change the err log to the right user, if possible and it is in use
644+
if [ $logging = "file" -o $logging = "both" ]; then
645+
if [ ! -f "$err_log" -a ! -h "$err_log" ]; then
646+
if test -w / -o "$USER" = "root"; then
647+
case $logdir in
648+
/var/log)
649+
(
650+
umask 0137
651+
set -o noclobber
652+
> "$err_log" && chown $user "$err_log"
653+
) ;;
654+
*) ;;
655+
esac
656+
else
657+
(
658+
umask 0137
659+
set -o noclobber
660+
> "$err_log"
661+
)
662+
fi
620663
fi
621664

665+
if [ -f "$err_log" ]; then # Log to err_log file
666+
log_notice "Logging to '$err_log'."
667+
elif [ "x$user" = "xroot" ]; then # running as root, mysqld can create log file; continue
668+
echo "Logging to '$err_log'." >&2
669+
else
670+
case $logdir in
671+
# We can't create $err_log, however mysqld can; continue
672+
/tmp|/var/tmp|/var/log/mysql|$DATADIR)
673+
echo "Logging to '$err_log'." >&2
674+
;;
675+
# We can't create $err_log and don't know if mysqld can; error out
676+
*)
677+
log_error "error: log-error set to '$err_log', however file don't exists. Create writable for user '$user'."
678+
exit 1
679+
;;
680+
esac
681+
fi
622682
fi
623683

624684
USER_OPTION=""
@@ -628,11 +688,6 @@ then
628688
then
629689
USER_OPTION="--user=$user"
630690
fi
631-
# Change the err log to the right user, if it is in use
632-
if [ $want_syslog -eq 0 -a ! -h "$err_log" ]; then
633-
touch "$err_log"
634-
chown $user "$err_log"
635-
fi
636691
if test -n "$open_files"
637692
then
638693
ulimit -n $open_files
@@ -645,15 +700,12 @@ then
645700
fi
646701

647702
safe_mysql_unix_port=${mysql_unix_port:-${MYSQL_UNIX_PORT:-@MYSQL_UNIX_ADDR@}}
648-
# Make sure that directory for $safe_mysql_unix_port exists
703+
# Check that directory for $safe_mysql_unix_port exists
649704
mysql_unix_port_dir=`dirname $safe_mysql_unix_port`
650705
if [ ! -d $mysql_unix_port_dir ]
651706
then
652-
if [ ! -h $mysql_unix_port_dir ]; then
653-
mkdir $mysql_unix_port_dir
654-
chown $user $mysql_unix_port_dir
655-
chmod 755 $mysql_unix_port_dir
656-
fi
707+
log_error "Directory '$mysql_unix_port_dir' for UNIX socket file don't exists."
708+
exit 1
657709
fi
658710

659711
# If the user doesn't specify a binary, we assume name "mysqld"
@@ -842,11 +894,31 @@ do
842894

843895
eval_log_error "$cmd"
844896

897+
# hypothetical: log was renamed but not
898+
# flushed yet. we'd recreate it with
899+
# wrong owner next time we log, so set
900+
# it up correctly while we can!
901+
845902
if [ $want_syslog -eq 0 -a ! -f "$err_log" -a ! -h "$err_log" ]; then
846-
touch "$err_log" # hypothetical: log was renamed but not
847-
chown $user "$err_log" # flushed yet. we'd recreate it with
848-
chmod "$fmode" "$err_log" # wrong owner next time we log, so set
849-
fi # it up correctly while we can!
903+
if test -w / -o "$USER" = "root"; then
904+
logdir=`dirname "$err_log"`
905+
case $logdir in
906+
/var/log)
907+
(
908+
umask 0137
909+
set -o noclobber
910+
> "$err_log" && chown $user "$err_log"
911+
) ;;
912+
*) ;;
913+
esac
914+
else
915+
(
916+
umask 0137
917+
set -o noclobber
918+
> "$err_log"
919+
)
920+
fi
921+
fi
850922

851923
end_time=`date +%M%S`
852924

0 commit comments

Comments
 (0)