Skip to content

Commit d245dd7

Browse files
author
Tatjana Azundris Nuernberg
committed
Bug#11764559: UMASK IS IGNORED BY ERROR LOG
mysqld_safe script did not heed MySQL specific environment variable $UMASK, leading to divergent behavior between mysqld and mysqld_safe. Patch adds an approximation of mysqld's behavior to mysqld_safe, within the bounds dictated by attempt to have mysqld_safe run on even the most basic of shells (proper '70s sh, not just bash with a fancy symlink). Patch also adds approximation of said behavior to mysqld_multi (in perl). (backport) auto-merge
2 parents d0bca79 + 61ab1a4 commit d245dd7

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

scripts/mysqld_multi.sh

+22
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ $homedir = $ENV{HOME};
4848
$my_progname = $0;
4949
$my_progname =~ s/.*[\/]//;
5050

51+
52+
if (defined($ENV{UMASK})) {
53+
my $UMASK = $ENV{UMASK};
54+
my $m;
55+
my $fmode = "0640";
56+
57+
if(($UMASK =~ m/[^0246]/) || ($UMASK =~ m/^[^0]/) || (length($UMASK) != 4)) {
58+
printf("UMASK must be a 3-digit mode with an additional leading 0 to indicate octal.\n");
59+
printf("The first digit will be corrected to 6, the others may be 0, 2, 4, or 6.\n"); }
60+
else {
61+
$fmode= substr $UMASK, 2, 2;
62+
$fmode= "06${fmode}"; }
63+
64+
if($fmode != $UMASK) {
65+
printf("UMASK corrected from $UMASK to $fmode ...\n"); }
66+
67+
$fmode= oct($fmode);
68+
69+
umask($fmode);
70+
}
71+
72+
5173
main();
5274

5375
####

scripts/mysqld_safe.sh

+34-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,28 @@ syslog_tag_mysqld_safe=mysqld_safe
3232
trap '' 1 2 3 15 # we shouldn't let anyone kill us
3333
trap '' 13 # not even SIGPIPE
3434

35-
umask 007
35+
# MySQL-specific environment variable. First off, it's not really a umask,
36+
# it's the desired mode. Second, it follows umask(2), not umask(3) in that
37+
# octal needs to be explicit. Our shell might be a proper sh without printf,
38+
# multiple-base arithmetic, and binary arithmetic, so this will get ugly.
39+
# We reject decimal values to keep things at least half-sane.
40+
umask 007 # fallback
41+
UMASK="${UMASK-0640}"
42+
fmode=`echo "$UMASK" | sed -e 's/[^0246]//g'`
43+
octalp=`echo "$fmode"|cut -c1`
44+
fmlen=`echo "$fmode"|wc -c|sed -e 's/ //g'`
45+
if [ "x$octalp" != "x0" -o "x$UMASK" != "x$fmode" -o "x$fmlen" != "x5" ]
46+
then
47+
fmode=0640
48+
echo "UMASK must be a 3-digit mode with an additional leading 0 to indicate octal." >&2
49+
echo "The first digit will be corrected to 6, the others may be 0, 2, 4, or 6." >&2
50+
fi
51+
fmode=`echo "$fmode"|cut -c3-4`
52+
fmode="6$fmode"
53+
if [ "x$UMASK" != "x0$fmode" ]
54+
then
55+
echo "UMASK corrected from $UMASK to 0$fmode ..."
56+
fi
3657

3758
defaults=
3859
case "$1" in
@@ -547,6 +568,12 @@ then
547568
# Log to err_log file
548569
log_notice "Logging to '$err_log'."
549570
logging=file
571+
572+
if [ ! -e "$err_log" ]; then # if error log already exists,
573+
touch "$err_log" # we just append. otherwise,
574+
chmod "$fmode" "$err_log" # fix the permissions here!
575+
fi
576+
550577
else
551578
if [ -n "$syslog_tag" ]
552579
then
@@ -758,6 +785,12 @@ do
758785

759786
eval_log_error "$cmd"
760787

788+
if [ $want_syslog -eq 0 -a ! -e "$err_log" ]; then
789+
touch "$err_log" # hypothetical: log was renamed but not
790+
chown $user "$err_log" # flushed yet. we'd recreate it with
791+
chmod "$fmode" "$err_log" # wrong owner next time we log, so set
792+
fi # it up correctly while we can!
793+
761794
end_time=`date +%M%S`
762795

763796
if test ! -f "$pid_file" # This is removed if normal shutdown

0 commit comments

Comments
 (0)