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 () {
153166eval_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 
622682fi 
623683
624684USER_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
645700fi 
646701
647702safe_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
649704mysql_unix_port_dir=` dirname $safe_mysql_unix_port ` 
650705if  [ !  -d  $mysql_unix_port_dir  ]
651706then 
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
657709fi 
658710
659711#  If the user doesn't specify a binary, we assume name "mysqld"
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