$NetBSD: patch-am,v 1.3 2003/01/21 06:02:42 lukem Exp $

--- scripts/safe_mysqld.sh.orig	Tue Jan 21 16:11:16 2003
+++ scripts/safe_mysqld.sh
@@ -184,6 +184,14 @@ then
   fi
 fi
 
+datemsg()
+{
+	echo -n $(date +'%y%M%d %H:%M:%S')"  "
+	echo "$*"
+}
+
+exec >>$err_log 2>&1
+
 #
 # If there exists an old pid file, check if the daemon is already running
 # Note: The switches to 'ps' may depend on your operating system
@@ -194,18 +202,16 @@ then
   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
+      datemsg "A mysqld process already exists"
       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"
+    datemsg "Fatal error: Can't remove the pid file: $pid_file"
+    datemsg "Please remove it manually and start $0 again"
+    datemsg "mysqld daemon not started"
     exit 1
   fi
 fi
@@ -214,11 +220,11 @@ fi
 # Uncomment the following lines if you want all tables to be automaticly
 # checked and repaired at start
 #
-# echo "Checking tables in $DATADIR"
+# datemsg "Checking tables in $DATADIR"
 # $MY_BASEDIR_VERSION/bin/myisamchk --silent --force --fast --medium-check -O key_buffer=64M -O sort_buffer=64M $DATADIR/*/*.MYI
 # $MY_BASEDIR_VERSION/bin/isamchk --silent --force -O sort_buffer=64M $DATADIR/*/*.ISM
 
-echo "Starting $MYSQLD daemon with databases from $DATADIR"
+datemsg "Starting $MYSQLD daemon with databases from $DATADIR"
 
 # Does this work on all systems?
 #if type ulimit | grep "shell builtin" > /dev/null
@@ -226,7 +232,7 @@ echo "Starting $MYSQLD daemon with datab
 #  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
+datemsg "mysqld started"
 while true
 do
   rm -f $MYSQL_UNIX_PORT $pid_file	# Some extra safety
@@ -249,7 +255,7 @@ do
     # 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
+    datemsg "Number of processes running now: $numofproces"
     I=1
     while test "$I" -le "$numofproces"
     do 
@@ -261,7 +267,7 @@ do
 	#    echo "TEST $I - $T **"
 	if kill -9 $T
 	then
-	  echo "$MYSQLD process hanging, pid $T - killed" | tee -a $err_log
+	  datemsg "$MYSQLD process hanging, pid $T - killed"
 	else 
 	  break
 	fi
@@ -269,8 +275,7 @@ do
     done
   fi
 
-  echo "`date +'%y%m%d %H:%M:%S  mysqld restarted'`" | tee -a $err_log
+  datemsg "mysqld restarted"
 done
 
-echo "`date +'%y%m%d %H:%M:%S  mysqld ended'`" | tee -a $err_log
-echo "" | tee -a $err_log
+datemsg "mysqld ended"
