--- mysql-dfsg-4.0.20.orig/scripts/mysqld_safe.sh
+++ mysql-dfsg-4.0.20/scripts/mysqld_safe.sh
@@ -10,12 +10,15 @@
 # mysql.server works by first doing a cd to the base directory and from there
 # executing mysqld_safe
 
-KILL_MYSQLD=1;
-
 trap '' 1 2 3 15			# we shouldn't let anyone kill us
 
 umask 007
 
+KILL_MYSQLD=1;
+
+# This command can be used as pipe to syslog. With "-s" it also logs to stderr.
+ERR_LOGGER="logger -p daemon.err -t mysqld_safe -i"
+
 defaults=
 case "$1" in
     --no-defaults|--defaults-file=*|--defaults-extra-file=*)
@@ -58,9 +61,6 @@
 
       # mysqld_safe-specific options - must be set in my.cnf ([mysqld_safe])!
       --ledir=*)   ledir=`echo "$arg" | sed -e "s;--ledir=;;"` ;;
-      # err-log should be removed in 5.0
-      --err-log=*) err_log=`echo "$arg" | sed -e "s;--err-log=;;"` ;;
-      --log-error=*) err_log=`echo "$arg" | sed -e "s;--log-error=;;"` ;;
       # QQ The --open-files should be removed in 5.0
       --open-files=*) open_files=`echo "$arg" | sed -e "s;--open-files=;;"` ;;
       --open-files-limit=*) open_files=`echo "$arg" | sed -e "s;--open-files-limit=;;"` ;;
@@ -128,7 +128,6 @@
 
 # these rely on $DATADIR by default, so we'll set them later on
 pid_file=
-err_log=
 
 # Get first arguments from the my.cnf file, groups [mysqld] and [mysqld_safe]
 # and then merge with the command line arguments
@@ -176,7 +175,6 @@
     * )  pid_file="$DATADIR/$pid_file" ;;
   esac
 fi
-test -z "$err_log"  && err_log=$DATADIR/`@HOSTNAME@`.err
 
 if test -n "$mysql_unix_port"
 then
@@ -246,8 +244,6 @@
   then
     USER_OPTION="--user=$user"
   fi
-  # If we are root, change the err log to the right user.
-  touch $err_log; chown $user $err_log
   if test -n "$open_files"
   then
     ulimit -n $open_files
@@ -269,18 +265,16 @@
   then
     if @FIND_PROC@
     then    # The pid contains a mysqld process
-      echo "A mysqld process already exists"
-      echo "A mysqld process already exists at " `date` >> $err_log
+      echo "A mysqld process already exists" | $ERR_LOGGER -s
       exit 1
     fi
   fi
   rm -f $pid_file
   if test -f $pid_file
   then
-    echo "Fatal error: Can't remove the pid file: $pid_file"
-    echo "Fatal error: Can't remove the pid file: $pid_file at " `date` >> $err_log
-    echo "Please remove it manually and start $0 again"
-    echo "mysqld daemon not started"
+    echo "Fatal error: Can't remove the pid file: $pid_file" | $ERR_LOGGER -s
+    echo "Please remove it manually and start $0 again" | $ERR_LOGGER -s
+    echo "mysqld daemon not started" | $ERR_LOGGER -s
     exit 1
   fi
 fi
@@ -305,15 +299,15 @@
 #  ulimit -n 256 > /dev/null 2>&1		# Fix for BSD and FreeBSD systems
 #fi
 
-echo "`date +'%y%m%d %H:%M:%S  mysqld started'`" >> $err_log
+echo "started" | $ERR_LOGGER -s
 while true
 do
   rm -f $safe_mysql_unix_port $pid_file	# Some extra safety
   if test -z "$args"
   then
-    $NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file @MYSQLD_DEFAULT_SWITCHES@ >> $err_log 2>&1
+    $NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file @MYSQLD_DEFAULT_SWITCHES@ 2>&1 | $ERR_LOGGER -t mysqld
   else
-    eval "$NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file @MYSQLD_DEFAULT_SWITCHES@ $args >> $err_log 2>&1"
+    eval "$NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file @MYSQLD_DEFAULT_SWITCHES@ $args 2>&1 | $ERR_LOGGER -t mysqld"
   fi
   if test ! -f $pid_file		# This is removed if normal shutdown
   then
@@ -328,7 +322,7 @@
     # The only thing is ps x => redhat 5 gives warnings when using ps -x.
     # kill -9 is used or the process won't react on the kill.
     numofproces=`ps xa | grep -v "grep" | grep -c $ledir/$MYSQLD`
-    echo -e "\nNumber of processes running now: $numofproces" | tee -a $err_log
+    echo "Number of processes running now: $numofproces" | $ERR_LOGGER -s
     I=1
     while test "$I" -le "$numofproces"
     do 
@@ -340,15 +334,14 @@
 	#    echo "TEST $I - $T **"
 	if kill -9 $T
 	then
-	  echo "$MYSQLD process hanging, pid $T - killed" | tee -a $err_log
+	  echo "$MYSQLD process hanging, pid $T - killed" | $ERR_LOGGER -s
 	else 
 	  break
 	fi
 	I=`expr $I + 1`
     done
   fi
-  echo "`date +'%y%m%d %H:%M:%S'`  mysqld restarted" | tee -a $err_log
+  echo "restarted" | $ERR_LOGGER -s
 done
 
-echo "`date +'%y%m%d %H:%M:%S'`  mysqld ended" | tee -a $err_log
-echo "" | tee -a $err_log
+echo "ended" | $ERR_LOGGER -s
