From f05a1c83940557721a42c758e26f2adace291d0a Mon Sep 17 00:00:00 2001
From: "monty@narttu.mysql.fi" <>
Date: Tue, 23 Sep 2003 13:36:01 +0300
Subject: [PATCH] Block SIGPIPE also for not threaded client programs. Added
 --include and --libs_r options to mysql_config. Added
 mysql_get_client_version() to client library Fixed some minor benchmark
 issues

---
 acinclude.m4                  |  3 ++-
 configure.in                  |  2 +-
 extra/comp_err.c              |  2 +-
 include/mysql.h               |  9 +++++----
 libmysql/libmysql.c           | 13 +++++++------
 libmysql/libmysql.def         |  1 +
 scripts/Makefile.am           |  1 +
 scripts/mysql_config.sh       | 22 ++++++++++++++++++----
 scripts/mysql_install_db.sh   |  8 ++++----
 sql-bench/bench-init.pl.sh    |  2 +-
 sql-bench/server-cfg.sh       |  1 -
 sql-bench/test-alter-table.sh |  2 +-
 sql-bench/test-select.sh      |  5 +++--
 tests/mail_to_db.pl           |  4 ++--
 14 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index f6bd1d9e83..f7833bdce4 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -839,9 +839,10 @@ AC_MSG_CHECKING(for OpenSSL)
       echo "You can't use the --all-static link option when using openssl."
       exit 1
     fi
+    NON_THREADED_CLIENT_LIBS="$NON_THREADED_CLIENT_LIBS $openssl_libs"
+  else
     AC_MSG_RESULT(no)
   fi
-  NON_THREADED_CLIENT_LIBS="$NON_THREADED_CLIENT_LIBS $openssl_libs"
   AC_SUBST(openssl_libs)
   AC_SUBST(openssl_includes)
 ])
diff --git a/configure.in b/configure.in
index 8ec42366ed..168ac91667 100644
--- a/configure.in
+++ b/configure.in
@@ -2256,7 +2256,7 @@ do
   done
   if test $charset_okay = 0;
   then
-    AC_MSG_ERROR([Charset $cs not available. (Available $CHARSETS_AVAILABLE).
+    AC_MSG_ERROR([Charset '$cs' not available. (Available $CHARSETS_AVAILABLE).
     See the Installation chapter in the Reference Manual.]);
   fi
 done
diff --git a/extra/comp_err.c b/extra/comp_err.c
index 806fb5052b..8e9c6fc0f0 100644
--- a/extra/comp_err.c
+++ b/extra/comp_err.c
@@ -60,7 +60,7 @@ int main(int argc,char *argv[])
       return(1);
     }
 
-    VOID(count_rows(from,'"','}'));	/* Calculate start-info */
+    VOID(count_rows(from,'"','{'));	/* Calculate start-info */
     if (remember_rows(from,'}') < 0)	/* Remember rows */
     {
       fprintf(stderr,"Can't find textrows in '%s'\n",*argv);
diff --git a/include/mysql.h b/include/mysql.h
index b27d98e7e5..1db322d530 100644
--- a/include/mysql.h
+++ b/include/mysql.h
@@ -349,10 +349,11 @@ int		STDCALL mysql_refresh(MYSQL *mysql,
 				     unsigned int refresh_options);
 int		STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
 int		STDCALL mysql_ping(MYSQL *mysql);
-const char *		STDCALL mysql_stat(MYSQL *mysql);
-const char *		STDCALL mysql_get_server_info(MYSQL *mysql);
-const char *		STDCALL mysql_get_client_info(void);
-const char *		STDCALL mysql_get_host_info(MYSQL *mysql);
+const char *	STDCALL mysql_stat(MYSQL *mysql);
+const char *	STDCALL mysql_get_server_info(MYSQL *mysql);
+const char *	STDCALL mysql_get_client_info(void);
+ulong		STDCALL mysql_get_client_version(void);
+const char *	STDCALL mysql_get_host_info(MYSQL *mysql);
 unsigned int	STDCALL mysql_get_proto_info(MYSQL *mysql);
 MYSQL_RES *	STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
 MYSQL_RES *	STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c
index 9e32e60f7d..cd4e8c77f2 100644
--- a/libmysql/libmysql.c
+++ b/libmysql/libmysql.c
@@ -1452,10 +1452,6 @@ mysql_init(MYSQL *mysql)
     after we return if this is not the case.
   */
   mysql->rpl_pivot = 1; 
-#if defined(SIGPIPE) && defined(THREAD) && !defined(__WIN__)
-  if (!((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE))
-    (void) signal(SIGPIPE,pipe_sig_handler);
-#endif
 
 /*
   Only enable LOAD DATA INFILE by default if configured with
@@ -1515,8 +1511,8 @@ void mysql_once_init(void)
 	mysql_unix_port = env;
     }
     mysql_debug(NullS);
-#if defined(SIGPIPE) && !defined(THREAD) && !defined(__WIN__)
-    (void) signal(SIGPIPE,SIG_IGN);
+#if defined(SIGPIPE) && !defined(__WIN__)
+    (void) signal(SIGPIPE, SIG_IGN);
 #endif
   }
 #ifdef THREAD
@@ -2911,6 +2907,11 @@ mysql_get_client_info(void)
   return (char*) MYSQL_SERVER_VERSION;
 }
 
+ulong STDCALL mysql_get_client_version(void)
+{
+  return MYSQL_VERSION_ID;
+}
+
 
 int STDCALL
 mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg)
diff --git a/libmysql/libmysql.def b/libmysql/libmysql.def
index baa8643b92..542ab890e9 100644
--- a/libmysql/libmysql.def
+++ b/libmysql/libmysql.def
@@ -24,6 +24,7 @@ EXPORTS
 	mysql_get_host_info
 	mysql_get_proto_info
 	mysql_get_server_info
+	mysql_get_client_version
 	mysql_info
 	mysql_init
 	mysql_insert_id
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 72fc73ef28..c83b0d0b04 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -113,6 +113,7 @@ SUFFIXES = .sh
 	  -e 's!@''CLIENT_LIBS''@!@CLIENT_LIBS@!' \
 	  -e 's!@''LIBS''@!@LIBS@!' \
 	  -e 's!@''innodb_system_libs''@!@innodb_system_libs@!' \
+	  -e 's!@''openssl_libs''@!@openssl_libs@!' \
 	  -e 's!@''VERSION''@!@VERSION@!' \
 	  -e 's!@''MYSQL_SERVER_SUFFIX''@!@MYSQL_SERVER_SUFFIX@!' \
 	  -e 's!@''COMPILATION_COMMENT''@!@COMPILATION_COMMENT@!' \
diff --git a/scripts/mysql_config.sh b/scripts/mysql_config.sh
index 3cc5b3a501..5228410463 100644
--- a/scripts/mysql_config.sh
+++ b/scripts/mysql_config.sh
@@ -84,17 +84,29 @@ port='@MYSQL_TCP_PORT@'
 ldflags='@LDFLAGS@'
 client_libs='@CLIENT_LIBS@'
 
-libs="$ldflags -L'$pkglibdir' -lmysqlclient $client_libs"
-libs=`echo $libs | sed -e 's; +;;'`
-cflags="-I'$pkgincludedir'"
-embedded_libs="$ldflags -L'$pkglibdir' -lmysqld @LIBS@ @innodb_system_libs@"
+# Create options, without end space
+
+libs="$ldflags -L$pkglibdir -lmysqlclient $client_libs"
+libs=`echo "$libs" | sed -e 's;  \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'`
+libs_r="$ldflags -L$pkglibdir -lmysqlclient_r @LIBS@ @openssl_libs@"
+libs_r=`echo "$libs_r" | sed -e 's;  \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'`
+cflags="-I$pkgincludedir @CFLAGS@"
+include="-I$pkgincludedir"
+embedded_libs="$ldflags -L$pkglibdir -lmysqld @LIBS@ @innodb_system_libs@"
+embedded_libs=`echo "$embedded_libs" | sed -e 's;  \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'`
+
+# Remove some options that a client doesn't have to care about
+
+cflags=`echo "$cflags " | sed -e 's;\(-DDBUG_OFF\|-DSAFEMALLOC\|-USAFEMALLOC\|-DSAFE_MUTEX\|-DPEDANTIC_SAFEMALLOC\|-DUNIV_MUST_NOT_INLINE\|-DFORCE_INIT_OF_VARS\|-DEXTRA_DEBUG\|-DHAVE_purify\|-O[0-9]\|-W[-A-Za-z]*\) *;;g' | sed -e 's; *\$;;'` 
 
 usage () {
         cat <<EOF
 Usage: $0 [OPTIONS]
 Options:
         --cflags         [$cflags]
+	--include	 [$include]
         --libs           [$libs]
+        --libs_r         [$libs_r]
         --socket         [$socket]
         --port           [$port]
         --version        [$version]
@@ -108,7 +120,9 @@ if test $# -le 0; then usage; fi
 while test $# -gt 0; do
         case $1 in
         --cflags)  echo "$cflags" ;;
+	--include) echo "$include" ;;
         --libs)    echo "$libs" ;;
+        --libs_r)  echo "$libs_r" ;;
         --socket)  echo "$socket" ;;
         --port)    echo "$port" ;;
         --version) echo "$version" ;;
diff --git a/scripts/mysql_install_db.sh b/scripts/mysql_install_db.sh
index 0e685ba38e..5b8fa4d411 100644
--- a/scripts/mysql_install_db.sh
+++ b/scripts/mysql_install_db.sh
@@ -97,7 +97,7 @@ mdata=$ldata/mysql
 
 if test ! -x $execdir/mysqld
 then
-  if test "$IN_RPM" -eq 1
+  if test "$IN_RPM" = "1"
   then
     echo "FATAL ERROR $execdir/mysqld not found!"
     exit 1
@@ -112,7 +112,7 @@ fi
 hostname=`@HOSTNAME@`
 
 # Check if hostname is valid
-if test "$IN_RPM" -eq 0 -a $force -eq 0
+if test "$IN_RPM" = "0" -a $force = "0"
 then
   resolved=`$bindir/resolveip $hostname 2>&1`
   if [ $? -ne 0 ]
@@ -333,7 +333,7 @@ $c_c
 END_OF_DATA
 then
   echo ""
-  if test "$IN_RPM" -eq 0
+  if test "$IN_RPM" = "0"
   then
     echo "To start mysqld at boot time you have to copy support-files/mysql.server"
     echo "to the right place for your system"
@@ -354,7 +354,7 @@ then
     echo "able to use the new GRANT command!"
   fi
   echo
-  if test "$IN_RPM" -eq 0
+  if test "$IN_RPM" = "0"
   then
     echo "You can start the MySQL daemon with:"
     echo "cd @prefix@ ; $bindir/mysqld_safe &"
diff --git a/sql-bench/bench-init.pl.sh b/sql-bench/bench-init.pl.sh
index b7d2b962e1..b02f503463 100644
--- a/sql-bench/bench-init.pl.sh
+++ b/sql-bench/bench-init.pl.sh
@@ -31,7 +31,7 @@
 # $server	Object for current server
 # $limits	Hash reference to limits for benchmark
 
-$benchmark_version="2.14";
+$benchmark_version="2.15";
 use Getopt::Long;
 
 require "$pwd/server-cfg" || die "Can't read Configuration file: $!\n";
diff --git a/sql-bench/server-cfg.sh b/sql-bench/server-cfg.sh
index 5537143115..905e7ee65b 100644
--- a/sql-bench/server-cfg.sh
+++ b/sql-bench/server-cfg.sh
@@ -2862,7 +2862,6 @@ sub new
   $limits{'working_blobs'}	= 1; # If big varchar/blobs works
   $limits{'order_by_unused'}	= 0;
   $limits{'working_all_fields'} = 1;
-  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 
 
   return $self;
 }
diff --git a/sql-bench/test-alter-table.sh b/sql-bench/test-alter-table.sh
index f338792e9e..93a9c1b444 100644
--- a/sql-bench/test-alter-table.sh
+++ b/sql-bench/test-alter-table.sh
@@ -24,7 +24,7 @@ use DBI;
 use Benchmark;
 
 $opt_start_field_count=8;	# start with this many fields
-$opt_loop_count=20;		# How many tests to do
+$opt_loop_count=100;		# How many tests to do
 $opt_row_count=1000; 		# Rows in the table
 $opt_field_count=1000;		# Add until this many fields.
 $opt_time_limit=10*60;		# Don't wait more than 10 min for some tests
diff --git a/sql-bench/test-select.sh b/sql-bench/test-select.sh
index a5de042cab..8981fa49cf 100644
--- a/sql-bench/test-select.sh
+++ b/sql-bench/test-select.sh
@@ -356,7 +356,8 @@ if ($limits->{'group_distinct_functions'})
     timestr(timediff($end_time, $loop_time),"all") . "\n";
 
 #  Workaround mimer's behavior
-  if (limits->{'multi_distinct'} == 1 ) {
+  if ($limits->{'multi_distinct'})
+  {
     $loop_time=new Benchmark;
     $rows=$estimated=$count=0;
     for ($i=0 ; $i < $opt_medium_loop_count ; $i++)
@@ -370,7 +371,7 @@ if ($limits->{'group_distinct_functions'})
     print_time($estimated);
     print " for count_distinct_2 ($count:$rows): " .
       timestr(timediff($end_time, $loop_time),"all") . "\n";
-  }    
+  }
 
   $loop_time=new Benchmark;
   $rows=$estimated=$count=0;
diff --git a/tests/mail_to_db.pl b/tests/mail_to_db.pl
index 671e8b2359..dc40fb3ede 100755
--- a/tests/mail_to_db.pl
+++ b/tests/mail_to_db.pl
@@ -25,8 +25,8 @@ $opt_debug         = 0;
 $opt_host          = undef();
 $opt_port          = undef();
 $opt_socket        = undef();
-$opt_db            = undef();
-$opt_table         = undef();
+$opt_db            = "mail";
+$opt_table         = "mails";
 $opt_user          = undef();
 $opt_password      = undef();
 $opt_max_mail_size = 65536;
-- 
2.30.9