From 6a387c7cdf57dfe7f9a136e31ffe463d5cd28efc Mon Sep 17 00:00:00 2001 From: "monty@hundin.mysql.fi" <> Date: Thu, 31 May 2001 12:18:53 +0300 Subject: [PATCH] Added functions for symbolic link handling to make it possible to backport things from 4.0. This is safe as the functions are not used! Fixed bug in new mutex handling in InnoDB Make allow_break() and dont_break() defines. --- BitKeeper/etc/logging_ok | 7 +- Docs/manual.texi | 14 +-- configure.in | 7 +- include/my_sys.h | 14 +++ include/mysys_err.h | 5 +- innobase/include/sync0sync.ic | 3 +- mysys/Makefile.am | 1 + mysys/errors.c | 8 +- mysys/mf_brkhant.c | 6 +- mysys/my_symlink.c | 171 ++++++++++++++++++++++++++++++++++ sql/sql_select.h | 7 +- 11 files changed, 220 insertions(+), 23 deletions(-) create mode 100644 mysys/my_symlink.c diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index f517c9a46c..e8deba03c8 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -1,6 +1 @@ -mwagner@evoq.mwagner.org -sasha@mysql.sashanet.com -heikki@donna.mysql.fi -miguel@linux.local -monty@tik.mysql.fi -monty@donna.mysql.fi +monty@hundin.mysql.fi diff --git a/Docs/manual.texi b/Docs/manual.texi index 5437b29fb5..3e564e6694 100644 --- a/Docs/manual.texi +++ b/Docs/manual.texi @@ -8472,7 +8472,7 @@ The following @code{configure} command should work: @example shell> CFLAGS="-D_XOPEN_XPG4" CXX=gcc CXXFLAGS="-D_XOPEN_XPG4" \ ./configure \ - --with-debug --prefix=/usr/local/mysql \ + --prefix=/usr/local/mysql \ --with-named-thread-libs="-lgthreads -lsocket -lgen -lgthreads" \ --with-named-curses-libs="-lcurses" @end example @@ -9509,19 +9509,19 @@ and are configured with the following compilers and options: @code{CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors" ./configure --prefix=/usr/local/mysql --disable-shared --with-extra-charsets=complex --enable-assembler} @item SunOS 5.5.1 sun4u with @code{egcs} 1.0.3a -@code{CC=gcc CFLAGS="-O3 -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-low-memory --with-extra-charsets=complex} +@code{CC=gcc CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-low-memory --with-extra-charsets=complex} @item SunOS 5.6 sun4u with @code{egcs} 2.90.27 -@code{CC=gcc CFLAGS="-O3 -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-low-memory --with-extra-charsets=complex} +@code{CC=gcc CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-low-memory --with-extra-charsets=complex} @item SunOS 5.6 i86pc with @code{gcc} 2.8.1 @code{CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql --with-low-memory --with-extra-charsets=complex} @item Linux 2.0.33 i386 with @code{pgcc} 2.90.29 (@code{egcs} 1.0.3a) -@code{CFLAGS="-O3 -mpentium -mstack-align-double -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O3 -mpentium -mstack-align-double -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static --with-extra-charsets=complex} +@code{CFLAGS="-O3 -mpentium -mstack-align-double" CXX=gcc CXXFLAGS="-O3 -mpentium -mstack-align-double -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static --with-extra-charsets=complex} @item Linux 2.2.x with x686 with @code{gcc} 2.95.2 -@code{CFLAGS="-O3 -mpentiumpro -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O3 -mpentiumpro -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared --with-extra-charset=complex} +@code{CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared --with-extra-charset=complex} @item SCO 3.2v5.0.4 i386 with @code{gcc} 2.7-95q4 @code{CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql --with-extra-charsets=complex} @@ -10724,8 +10724,8 @@ the old @code{ISAM} type. You don't have to convert your old tables to use these with Version 3.23. By default, all new tables will be created with type @code{MyISAM} (unless you start @code{mysqld} with the @code{--default-table-type=isam} option). You can change an @code{ISAM} -table to a @code{MyISAM} table with @code{ALTER TABLE} or the Perl script -@code{mysql_convert_table_format}. +table to a @code{MyISAM} table with @code{ALTER TABLE table_name TYPE=MyISAM} +or the Perl script @code{mysql_convert_table_format}. Version 3.22 and 3.21 clients will work without any problems with a Version 3.23 server. diff --git a/configure.in b/configure.in index 4e73bb901f..088b041772 100644 --- a/configure.in +++ b/configure.in @@ -755,6 +755,11 @@ case $SYSTEM_TYPE in echo "Enabling snprintf workaround for hpux 10.20" CFLAGS="$CFLAGS -DHAVE_BROKEN_SNPRINTF -DSIGNALS_DONT_BREAK_READ" CXXFLAGS="$CXXFLAGS -DHAVE_BROKEN_SNPRINTF -D_INCLUDE_LONGLONG -DSIGNALS_DONT_BREAK_READ" + if test "$with_named_thread" = "no" + then + echo "Using --with-named-thread=-lpthread" + with_named_thread="-lcma" + fi ;; *hpux11.*) echo "Enabling pread/pwrite workaround for hpux 11" @@ -1051,7 +1056,7 @@ fi AC_MSG_CHECKING("named thread libs:") if test "$with_named_thread" != "no" then - LIBS="$LIBS $with_named_thread" + LIBS="$with_named_thread $LIBS $with_named_thread" with_posix_threads="yes" with_mit_threads="no" AC_MSG_RESULT("$with_named_thread") diff --git a/include/my_sys.h b/include/my_sys.h index 44faddad40..e2eb7ac30d 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -62,6 +62,8 @@ extern int NEAR my_errno; /* Last error in mysys */ #define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */ #define MY_LINK_WARNING 32 /* my_redel() gives warning if links */ #define MY_COPYTIME 64 /* my_redel() copys time */ +#define MY_DELETE_OLD 256 /* my_create_with_symlink() */ +#define MY_RESOLVE_LINK 128 /* my_realpath(); Only resolve links */ #define MY_HOLD_ORIGINAL_MODES 128 /* my_copy() holds to file modes */ #define MY_REDEL_MAKE_BACKUP 256 #define MY_SEEK_NOT_DONE 32 /* my_lock may have to do a seek */ @@ -378,6 +380,12 @@ extern File my_create(const char *FileName,int CreateFlags, int AccsesFlags, myf MyFlags); extern int my_close(File Filedes,myf MyFlags); extern int my_mkdir(const char *dir, int Flags, myf MyFlags); +extern int my_readlink(char *to, const char *filename, myf MyFlags); +extern int my_realpath(char *to, const char *filename, myf MyFlags); +extern File my_create_with_symlink(const char *linkname, const char *filename, + int createflags, int access_flags, + myf MyFlags); +extern int my_symlink(const char *content, const char *linkname, myf MyFlags); extern uint my_read(File Filedes,byte *Buffer,uint Count,myf MyFlags); extern uint my_pread(File Filedes,byte *Buffer,uint Count,my_off_t offset, myf MyFlags); @@ -428,8 +436,14 @@ extern int my_redel(const char *from, const char *to, int MyFlags); extern int my_copystat(const char *from, const char *to, int MyFlags); extern my_string my_filename(File fd); +#ifndef THREAD extern void dont_break(void); extern void allow_break(void); +#else +#define dont_break() +#define allow_break() +#endif + extern void my_remember_signal(int signal_number,sig_handler (*func)(int)); extern void caseup(my_string str,uint length); extern void casedn(my_string str,uint length); diff --git a/include/mysys_err.h b/include/mysys_err.h index b379f5bcbc..2d23ead36b 100644 --- a/include/mysys_err.h +++ b/include/mysys_err.h @@ -22,7 +22,7 @@ extern "C" { #endif #define GLOB 0 /* Error maps */ -#define GLOBERRS 24 /* Max number of error messages in map's */ +#define GLOBERRS 27 /* Max number of error messages in map's */ #define EE(X) globerrs[ X ] /* Defines to add error to right map */ extern const char * NEAR globerrs[]; /* my_error_messages is here */ @@ -51,6 +51,9 @@ extern const char * NEAR globerrs[]; /* my_error_messages is here */ #define EE_CANT_MKDIR 21 #define EE_UNKNOWN_CHARSET 22 #define EE_OUT_OF_FILERESOURCES 23 +#define EE_CANT_READLINK 24 +#define EE_CANT_SYMLINK 25 +#define EE_REALPATH 26 #ifdef __cplusplus } diff --git a/innobase/include/sync0sync.ic b/innobase/include/sync0sync.ic index e23e2b68e1..5a872c6b09 100644 --- a/innobase/include/sync0sync.ic +++ b/innobase/include/sync0sync.ic @@ -134,9 +134,10 @@ mutex_reset_lock_word( __asm XCHG EDX, DWORD PTR [ECX] #else mutex->lock_word = 0; - +#if !(defined(__GNUC__) && defined(UNIV_INTEL_X86)) os_fast_mutex_unlock(&(mutex->os_fast_mutex)); #endif +#endif } /********************************************************************** diff --git a/mysys/Makefile.am b/mysys/Makefile.am index 5a7293bc68..827367ac75 100644 --- a/mysys/Makefile.am +++ b/mysys/Makefile.am @@ -33,6 +33,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c\ my_alloc.c safemalloc.c my_fopen.c my_fstream.c \ my_error.c errors.c my_div.c my_messnc.c \ mf_format.c mf_same.c mf_dirname.c mf_fn_ext.c \ + my_symlink.c \ mf_pack.c mf_pack2.c mf_unixpath.c mf_stripp.c \ mf_casecnv.c mf_soundex.c mf_wcomp.c mf_wfile.c \ mf_qsort.c mf_qsort2.c mf_sort.c \ diff --git a/mysys/errors.c b/mysys/errors.c index 6e9f1fabab..77e52c2f0b 100644 --- a/mysys/errors.c +++ b/mysys/errors.c @@ -46,6 +46,9 @@ const char * NEAR globerrs[GLOBERRS]= "Can't create directory '%s' (Errcode: %d)", "Character set '%s' is not a compiled character set and is not specified in the '%s' file", "Out of resources when opening file '%s' (Errcode: %d)", + "Can't read value for symlink '%s' (Error %d)", + "Can't create symlink '%s' pointing at '%s' (Error %d)", + "Error on realpath() on '%s' (Error %d)", }; void init_glob_errs(void) @@ -81,6 +84,9 @@ void init_glob_errs() EE(EE_DISK_FULL) = "Disk is full writing '%s'. Waiting for someone to free space..."; EE(EE_CANT_MKDIR) ="Can't create directory '%s' (Errcode: %d)"; EE(EE_UNKNOWN_CHARSET)= "Character set is not a compiled character set and is not specified in the %s file"; - EE(EE_OUT_OF_FILERESOURCES)="Out of resources when opening file '%s' (Errcode: %d)", + EE(EE_OUT_OF_FILERESOURCES)="Out of resources when opening file '%s' (Errcode: %d)"; + EE(EE_CANT_READLINK)="Can't read value for symlink '%s' (Error %d)"; + EE(EE_CANT_SYMLINK)="Can't create symlink '%s' pointing at '%s' (Error %d)"; + EE(EE_REALPATH)="Error on realpath() on '%s' (Error %d)"; } #endif diff --git a/mysys/mf_brkhant.c b/mysys/mf_brkhant.c index 4e4bc2410f..debf5d9a71 100644 --- a/mysys/mf_brkhant.c +++ b/mysys/mf_brkhant.c @@ -24,17 +24,15 @@ /* Set variable that we can't break */ +#if !defined(THREAD) void dont_break(void) { -#if !defined(THREAD) my_dont_interrupt=1; -#endif return; } /* dont_break */ void allow_break(void) { -#if !defined(THREAD) { reg1 int index; @@ -54,8 +52,8 @@ void allow_break(void) _my_signals=0; } } -#endif } /* dont_break */ +#endif /* Set old status */ diff --git a/mysys/my_symlink.c b/mysys/my_symlink.c new file mode 100644 index 0000000000..e195adcd4c --- /dev/null +++ b/mysys/my_symlink.c @@ -0,0 +1,171 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +#include "mysys_priv.h" +#include "mysys_err.h" +#include <m_string.h> +#ifdef HAVE_REALPATH +#include <sys/param.h> +#include <sys/stat.h> +#endif + +/* + Reads the content of a symbolic link + If the file is not a symbolic link, return the original file name in to. +*/ + +int my_readlink(char *to, const char *filename, myf MyFlags) +{ +#ifndef HAVE_READLINK + strmov(to,filename); + return 0; +#else + int result=0; + int length; + DBUG_ENTER("my_readlink"); + + if ((length=readlink(filename, to, FN_REFLEN-1)) < 0) + { + /* Don't give an error if this wasn't a symlink */ + if ((my_errno=errno) == EINVAL) + { + strmov(to,filename); + } + else + { + if (MyFlags & MY_WME) + my_error(EE_CANT_READLINK, MYF(0), filename, errno); + result= -1; + } + } + else + to[length]=0; + DBUG_RETURN(result); +#endif /* HAVE_READLINK */ +} + + +/* Create a symbolic link */ + +int my_symlink(const char *content, const char *linkname, myf MyFlags) +{ +#ifndef HAVE_READLINK + return 0; +#else + int result; + DBUG_ENTER("my_symlink"); + + result= 0; + if (symlink(content, linkname)) + { + result= -1; + my_errno=errno; + if (MyFlags & MY_WME) + my_error(EE_CANT_SYMLINK, MYF(0), linkname, content, errno); + } + DBUG_RETURN(result); +#endif /* HAVE_READLINK */ +} + + +/* + Create a file and a symbolic link that points to this file + If linkname is a null pointer or equal to filename, we don't + create a link. + */ + + +File my_create_with_symlink(const char *linkname, const char *filename, + int createflags, int access_flags, myf MyFlags) +{ + File file; + int tmp_errno; + DBUG_ENTER("my_create_with_symlink"); + if ((file=my_create(filename, createflags, access_flags, MyFlags)) >= 0) + { + /* Test if we should create a link */ + if (linkname && strcmp(linkname,filename)) + { + /* Delete old link/file */ + if (MyFlags & MY_DELETE_OLD) + my_delete(linkname, MYF(0)); + /* Create link */ + if (my_symlink(filename, linkname, MyFlags)) + { + /* Fail, remove everything we have done */ + tmp_errno=my_errno; + my_close(file,MYF(0)); + my_delete(filename, MYF(0)); + file= -1; + my_errno=tmp_errno; + } + } + } + DBUG_RETURN(file); +} + + +/* + Resolve all symbolic links in path + 'to' may be equal to 'filename' + + Because purify gives a lot of UMR errors when using realpath(), + this code is disabled when using purify. + + If MY_RESOLVE_LINK is given, only do realpath if the file is a link. +*/ + +#if defined(SCO) +#define BUFF_LEN 4097 +#elif defined(MAXPATHLEN) +#define BUFF_LEN MAXPATHLEN +#else +#define BUFF_LEN FN_LEN +#endif + +int my_realpath(char *to, const char *filename, myf MyFlags) +{ +#if defined(HAVE_REALPATH) && !defined(HAVE_purify) && !defined(HAVE_BROKEN_REALPATH) + int result=0; + char buff[BUFF_LEN]; + struct stat stat_buff; + DBUG_ENTER("my_realpath"); + + if (!(MyFlags & MY_RESOLVE_LINK) || + (!lstat(filename,&stat_buff) && S_ISLNK(stat_buff.st_mode))) + { + char *ptr; + if ((ptr=realpath(filename,buff))) + strmake(to,ptr,FN_REFLEN-1); + else + { + /* Realpath didn't work; Use original name */ + my_errno=errno; + if (MyFlags & MY_WME) + my_error(EE_REALPATH, MYF(0), filename, my_errno); + if (to != filename) + strmov(to,filename); + result= -1; + } + } + return result; +#else + if (to != filename) + strmov(to,filename); + return 0; +#endif +} diff --git a/sql/sql_select.h b/sql/sql_select.h index bb97a10128..1bf7d7863e 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -138,8 +138,11 @@ class TMP_TABLE_PARAM { } inline void cleanup(void) { - delete [] copy_field; - copy_field=0; + if (copy_field) /* Fix for Intel compiler */ + { + delete [] copy_field; + copy_field=0; + } } }; -- 2.30.9