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# 
@@ -126,7 +126,13 @@ log_generic () {
126126  echo  " $msg " 
127127  case  $logging  in 
128128    init) ;;  #  Just echo the message, don't save it anywhere
129-     file) echo  " $msg "   >>  " $err_log "   ;;
129+     file)
130+       if  [ -w  / -o  " $USER "   =  " root"   ];  then 
131+         true 
132+       else 
133+         echo  " $msg "   >>  " $err_log " 
134+       fi 
135+       ;;
130136    syslog) logger -t " $syslog_tag_mysqld_safe "   -p " $priority "   " $* "   ;;
131137    * )
132138      echo  " Internal program error (non-fatal):"   \
@@ -146,7 +152,13 @@ log_notice () {
146152eval_log_error  () {
147153  cmd=" $1 " 
148154  case  $logging  in 
149-     file) cmd=" $cmd  >> " ` shell_quote_string " $err_log " ` "  2>&1"   ;;
155+     file)
156+       if  [ -w  / -o  " $USER "   =  " root"   ];  then 
157+         cmd=" $cmd  > /dev/null 2>&1" 
158+       else 
159+         cmd=" $cmd  >> " ` shell_quote_string " $err_log " ` "  2>&1" 
160+       fi 
161+       ;;
150162    syslog)
151163      #  mysqld often prefixes its messages with a timestamp, which is
152164      #  redundant when logging to syslog (which adds its own timestamp)
@@ -571,14 +583,7 @@ then
571583  fi 
572584
573585  #  Log to err_log file
574-   log_notice " Logging to '$err_log '." 
575586  logging=file
576- 
577-   if  [ !  -f  " $err_log "   -a  !  -h  " $err_log "   ];  then  #  if error log already exists,
578-     touch " $err_log "                              #  we just append. otherwise,
579-     chmod " $fmode "   " $err_log "                     #  fix the permissions here!
580-   fi 
581- 
582587else 
583588  if  [ -n  " $syslog_tag "   ]
584589  then 
@@ -591,18 +596,55 @@ else
591596  logging=syslog
592597fi 
593598
599+ logdir=` dirname " $err_log " ` 
600+ #  Change the err log to the right user, if possible and it is in use
601+ if  [ $logging  =  " file"   -o  $logging  =  " both"   ];  then 
602+   if  [ !  -f  " $err_log "   -a  !  -h  " $err_log "   ];  then 
603+     if  test  -w / -o " $USER "   = " root" ;  then 
604+       case  $logdir  in 
605+         /var/log)
606+           (
607+             umask  0137
608+             set  -o noclobber
609+             >  " $err_log "   &&  chown $user  " $err_log " 
610+           ) ;;
611+         * ) ;;
612+       esac 
613+     else 
614+       (
615+         umask  0137
616+         set  -o noclobber
617+         >  " $err_log " 
618+       )
619+     fi 
620+   fi 
621+ 
622+   if  [ -f  " $err_log "   ];  then         #  Log to err_log file
623+     log_notice " Logging to '$err_log '." 
624+   elif  [ " x$user "   =  " xroot"   ];  then  #  running as root, mysqld can create log file; continue
625+     echo  " Logging to '$err_log '."   >&2 
626+   else 
627+     case  $logdir  in 
628+       #  We can't create $err_log, however mysqld can; continue
629+       /tmp|/var/tmp|/var/log/mysql|$DATADIR )
630+         echo  " Logging to '$err_log '."   >&2 
631+         ;;
632+       #  We can't create $err_log and don't know if mysqld can; error out
633+       * )
634+         log_error " error: log-error set to '$err_log ', however file don't exists. Create writable for user '$user '." 
635+         exit  1
636+         ;;
637+     esac 
638+   fi 
639+ fi 
640+ 
594641USER_OPTION=" " 
595642if  test  -w / -o " $USER "   = " root" 
596643then 
597644  if  test  " $user "   ! = " root"   -o $SET_USER  = 1
598645  then 
599646    USER_OPTION=" --user=$user " 
600647  fi 
601-   #  Change the err log to the right user, if it is in use
602-   if  [ $want_syslog  -eq  0 -a  !  -h  " $err_log "   ];  then 
603-     touch " $err_log " 
604-     chown $user  " $err_log " 
605-   fi 
606648  if  test  -n " $open_files " 
607649  then 
608650    ulimit  -n $open_files 
@@ -615,15 +657,12 @@ then
615657fi 
616658
617659safe_mysql_unix_port=${mysql_unix_port:- ${MYSQL_UNIX_PORT:-@ MYSQL_UNIX_ADDR@ } } 
618- #  Make sure  that directory for $safe_mysql_unix_port exists
660+ #  Check  that directory for $safe_mysql_unix_port exists
619661mysql_unix_port_dir=` dirname $safe_mysql_unix_port ` 
620662if  [ !  -d  $mysql_unix_port_dir  ]
621663then 
622-   if  [ !  -h  $mysql_unix_port_dir  ];  then 
623-     mkdir $mysql_unix_port_dir 
624-     chown $user  $mysql_unix_port_dir 
625-     chmod 755 $mysql_unix_port_dir 
626-   fi 
664+   log_error " Directory '$mysql_unix_port_dir ' for UNIX socket file don't exists." 
665+   exit  1
627666fi 
628667
629668#  If the user doesn't specify a binary, we assume name "mysqld"
800839
801840  eval_log_error " $cmd " 
802841
842+   #  hypothetical: log was renamed but not
843+   #  flushed yet. we'd recreate it with
844+   #  wrong owner next time we log, so set
845+   #  it up correctly while we can!
846+ 
803847  if  [ $want_syslog  -eq  0 -a  !  -f  " $err_log "   -a  !  -h  " $err_log "   ];  then 
804-     touch " $err_log "                      #  hypothetical: log was renamed but not
805-     chown $user  " $err_log "                #  flushed yet. we'd recreate it with
806-     chmod " $fmode "   " $err_log "             #  wrong owner next time we log, so set
807-   fi                                     #  it up correctly while we can!
848+     if  test  -w / -o " $USER "   = " root" ;  then 
849+       logdir=` dirname " $err_log " ` 
850+       case  $logdir  in 
851+         /var/log)
852+           (
853+             umask  0137
854+             set  -o noclobber
855+             >  " $err_log "   &&  chown $user  " $err_log " 
856+           ) ;;
857+         * ) ;;
858+       esac 
859+     else 
860+       (
861+         umask  0137
862+         set  -o noclobber
863+         >  " $err_log " 
864+       )
865+     fi 
866+   fi 
808867
809868  end_time=` date +%M%S` 
810869
0 commit comments