diff --git a/Build-tools/Do-compile b/Build-tools/Do-compile
index 04e905cb834483a96c52286af354876bd1fe5523..a4156f6ac98fe809394ddd52ba3aaee69a0305c3 100755
--- a/Build-tools/Do-compile
+++ b/Build-tools/Do-compile
@@ -123,7 +123,7 @@ if ($opt_stage == 0 && ! $opt_use_old_distribution)
   system("touch timestamp");
   sleep(2);
   system("touch timestamp2");
-  system("find . -newer timestamp -print | xargs touch; rm -f timestamp");
+  system("find . -newer timestamp -print | xargs touch; rm -f timestamp timestamp2");
   sleep(2);
   # Ensure that files we don't want to rebuild are newer than other files
   safe_cd($ver);
diff --git a/Docs/manual.texi b/Docs/manual.texi
index 5075737240df2adca91d111eb34a08f5c6aeb2db..4ac8e8a22df576a44296976d6a85d1da1db147ee 100644
--- a/Docs/manual.texi
+++ b/Docs/manual.texi
@@ -50318,6 +50318,10 @@ each individual 4.0.x release.
 
 @itemize @bullet
 @item
+Fixed problem with @code{configure ... --localstatedir=...}.
+@item
+Cleaned up @code{mysql.server} script.
+@item
 Fixed a bug in @code{mysqladmin shutdown} when pid file was modified
 while @code{mysqladmin} was still waiting for the previous one to
 disappear. This could happen during a very quick restart and caused
diff --git a/client/mysqladmin.c b/client/mysqladmin.c
index 64b029bc406ee77ab9e072d0a06c2068de89cb28..4da995fa224a60c7d9a3e0e9ac195344556e8146 100644
--- a/client/mysqladmin.c
+++ b/client/mysqladmin.c
@@ -22,6 +22,7 @@
 #ifdef THREAD
 #include <my_pthread.h>				/* because of signal()	*/
 #endif
+#include <sys/stat.h>
 
 #define ADMIN_VERSION "8.37"
 #define MAX_MYSQL_VAR 128
diff --git a/scripts/make_binary_distribution.sh b/scripts/make_binary_distribution.sh
index 6e66a0b977c85a488b429ed6a3831697179589a5..2617a7971dca6c803cdd2a336b29be20089cc3f7 100644
--- a/scripts/make_binary_distribution.sh
+++ b/scripts/make_binary_distribution.sh
@@ -120,7 +120,7 @@ $CP scripts/* $BASE/bin
 rm -f $BASE/bin/Makefile* $BASE/bin/*.in $BASE/bin/*.sh $BASE/bin/mysql_install_db $BASE/bin/make_binary_distribution $BASE/bin/setsomevars $BASE/support-files/Makefile* $BASE/support-files/*.sh
 
 $BASE/bin/replace \@localstatedir\@ ./data \@bindir\@ ./bin \@scriptdir\@ ./bin \@libexecdir\@ ./bin \@sbindir\@ ./bin \@prefix\@ . \@HOSTNAME\@ @HOSTNAME@ < $SOURCE/scripts/mysql_install_db.sh > $BASE/scripts/mysql_install_db
-$BASE/bin/replace \@prefix\@ /usr/local/mysql \@bindir\@ ./bin \@MYSQLD_USER\@ root \@localstatedir\@ /usr/local/mysql/data < $SOURCE/support-files/mysql.server.sh > $BASE/support-files/mysql.server
+$BASE/bin/replace \@prefix\@ /usr/local/mysql \@bindir\@ ./bin \@MYSQLD_USER\@ root \@localstatedir\@ /usr/local/mysql/data \@HOSTNAME\@ @HOSTNAME@ < $SOURCE/support-files/mysql.server.sh > $BASE/support-files/mysql.server
 $BASE/bin/replace /my/gnu/bin/hostname /bin/hostname -- $BASE/bin/mysqld_safe
 
 # Make safe_mysqld a symlink to mysqld_safe for backwards portability
@@ -128,7 +128,7 @@ $BASE/bin/replace /my/gnu/bin/hostname /bin/hostname -- $BASE/bin/mysqld_safe
 (cd $BASE/bin ; ln -s mysqld_safe safe_mysqld )
 
 mv $BASE/support-files/binary-configure $BASE/configure
-chmod a+x $BASE/bin/* $BASE/scripts/* $BASE/support-files/mysql-* $BASE/configure
+chmod a+x $BASE/bin/* $BASE/scripts/* $BASE/support-files/mysql-* $BASE/support-files/mysql.server $BASE/configure
 $CP -r sql-bench/* $BASE/sql-bench
 rm -f $BASE/sql-bench/*.sh $BASE/sql-bench/Makefile* $BASE/lib/*.la
 
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index b0c50830e2f9ad59b020c844b4a01e5565fe6a60..aa6eeb33499ae29efde6889e1d7546e915768885 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -2036,6 +2036,7 @@ int main(int argc, char **argv)
   start_signal_handler();				// Creates pidfile
   if (acl_init(opt_noacl))
   {
+    abort_loop=1;
     select_thread_in_use=0;
     (void) pthread_kill(signal_thread,MYSQL_KILL_SIGNAL);
 #ifndef __WIN__
@@ -3893,7 +3894,7 @@ static void set_options(void)
   sys_charset.value= (char*) MYSQL_CHARSET;
   (void) strmake(language, LANGUAGE, sizeof(language)-1);
   (void) strmake(mysql_real_data_home, get_relative_path(DATADIR),
-		 sizeof(mysql_real_data_home-1));
+		 sizeof(mysql_real_data_home)-1);
 
   /* Set default values for some variables */
   global_system_variables.table_type=DB_TYPE_MYISAM;
diff --git a/support-files/mysql.server.sh b/support-files/mysql.server.sh
index 48bf004d75850cd9aa8ea5fa7cb414e1bfa6b886..7493fd298567e9c094a390570908bb889367b054 100644
--- a/support-files/mysql.server.sh
+++ b/support-files/mysql.server.sh
@@ -24,17 +24,27 @@
 # Description: MySQL is a very fast and reliable SQL database engine.
 ### END INIT INFO
  
-
-# The following variables are only set for letting mysql.server find things.
+# If you install MySQL on some other places than @prefix@, then you
+# have to do one of the following thing for this script to work:
+#
+# - Run this script from the MySQL installation directory
+# - Create a /etc/my.cnf file with the following information:
+#   [mysqld]
+#   basedir=path-to-mysql-installation-directory
+# - Add the above to any other configuration file (for example ~/.my.ini)
+#   and copy my_print_defaults to /usr/bin
+# - Add the path to the mysql-installation-directory to the basedir variable
+#   below.
+#
 # If you want to affect other MySQL variables, you should make your changes
-# in the /etc/my.cnf or other configuration files.
+# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
 
-PATH=/sbin:/usr/sbin:/bin:/usr/bin
-export PATH
+basedir=
+
+# The following variables are only set for letting mysql.server find things.
 
 # Set some defaults
 datadir=@localstatedir@
-basedir=
 pid_file=
 if test -z "$basedir"
 then
@@ -43,6 +53,10 @@ then
 else
   bindir="$basedir/bin"
 fi
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin
+export PATH
+
 if test -z "$pid_file"
 then
   pid_file=$datadir/`@HOSTNAME@`.pid
@@ -123,7 +137,7 @@ case "$mode" in
         touch /var/lock/subsys/mysql
       fi
     else
-      echo "Can't execute $bindir/mysqld_safe"
+      echo "Can't execute $bindir/mysqld_safe from dir $basedir"
     fi
     ;;