Skip to content

Commit a5fa073

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).
1 parent c55dd6b commit a5fa073

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
@@ -47,6 +47,28 @@ $homedir = $ENV{HOME};
4747
$my_progname = $0;
4848
$my_progname =~ s/.*[\/]//;
4949

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

5274
####

scripts/mysqld_safe.sh

+34-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,28 @@ syslog_tag_mysqld_safe=mysqld_safe
2727

2828
trap '' 1 2 3 15 # we shouldn't let anyone kill us
2929

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

3253
defaults=
3354
case "$1" in
@@ -371,6 +392,12 @@ then
371392
# Log to err_log file
372393
log_notice "Logging to '$err_log'."
373394
logging=file
395+
396+
if [ ! -e "$err_log" ]; then # if error log already exists,
397+
touch "$err_log" # we just append. otherwise,
398+
chmod "$fmode" "$err_log" # fix the permissions here!
399+
fi
400+
374401
else
375402
if [ -n "$syslog_tag" ]
376403
then
@@ -572,6 +599,12 @@ do
572599

573600
eval_log_error "$cmd"
574601

602+
if [ $want_syslog -eq 0 -a ! -e "$err_log" ]; then
603+
touch "$err_log" # hypothetical: log was renamed but not
604+
chown $user "$err_log" # flushed yet. we'd recreate it with
605+
chmod "$fmode" "$err_log" # wrong owner next time we log, so set
606+
fi # it up correctly while we can!
607+
575608
if test ! -f "$pid_file" # This is removed if normal shutdown
576609
then
577610
break

0 commit comments

Comments
 (0)