2006-04-28 06:07:25 +02:00
|
|
|
/* Copyright (C) 2000 MySQL AB
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2006-04-28 06:07:25 +02:00
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
#include "client_priv.h"
|
2006-11-08 03:45:50 +01:00
|
|
|
#include <sslopt-vars.h>
|
2007-04-18 13:21:39 +02:00
|
|
|
#include "../scripts/mysql_fix_privilege_tables_sql.c"
|
2006-11-08 03:45:50 +01:00
|
|
|
|
2007-08-01 21:59:05 +02:00
|
|
|
#define VER "1.1"
|
|
|
|
|
2007-04-19 21:30:46 +02:00
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WEXITSTATUS
|
|
|
|
# ifdef __WIN__
|
|
|
|
# define WEXITSTATUS(stat_val) (stat_val)
|
|
|
|
# else
|
|
|
|
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
static char mysql_path[FN_REFLEN];
|
|
|
|
static char mysqlcheck_path[FN_REFLEN];
|
2006-11-08 03:45:50 +01:00
|
|
|
|
2007-08-01 21:59:05 +02:00
|
|
|
static my_bool opt_force, opt_verbose, debug_info_flag, debug_check_flag;
|
|
|
|
static uint my_end_arg= 0;
|
2007-04-18 13:21:39 +02:00
|
|
|
static char *opt_user= (char*)"root";
|
|
|
|
|
2007-04-19 21:30:46 +02:00
|
|
|
static DYNAMIC_STRING ds_args;
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
static char *opt_password= 0;
|
|
|
|
static my_bool tty_password= 0;
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2006-11-08 03:45:50 +01:00
|
|
|
#ifndef DBUG_OFF
|
|
|
|
static char *default_dbug_option= (char*) "d:t:O,/tmp/mysql_upgrade.trace";
|
|
|
|
#endif
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2007-02-28 21:05:39 +01:00
|
|
|
static char **defaults_argv;
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
static my_bool not_used; /* Can't use GET_BOOL without a value pointer */
|
|
|
|
|
|
|
|
#include <help_start.h>
|
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
static struct my_option my_long_options[]=
|
|
|
|
{
|
|
|
|
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
|
|
|
|
NO_ARG, 0, 0, 0, 0, 0, 0},
|
2007-04-18 13:21:39 +02:00
|
|
|
{"basedir", 'b', "Not used by mysql_upgrade. Only for backward compatibilty",
|
|
|
|
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2007-08-01 21:59:05 +02:00
|
|
|
{"character-sets-dir", OPT_CHARSETS_DIR,
|
|
|
|
"Directory where character sets are.", 0,
|
|
|
|
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
{"compress", OPT_COMPRESS, "Use compression in server/client protocol.",
|
|
|
|
(uchar**)¬_used, (uchar**)¬_used, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
2007-04-18 13:21:39 +02:00
|
|
|
{"datadir", 'd',
|
|
|
|
"Not used by mysql_upgrade. Only for backward compatibilty",
|
|
|
|
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2006-04-28 06:07:25 +02:00
|
|
|
#ifdef DBUG_OFF
|
|
|
|
{"debug", '#', "This is a non-debug version. Catch this and exit",
|
|
|
|
0, 0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
#else
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
{"debug", '#', "Output debug log", (uchar* *) & default_dbug_option,
|
|
|
|
(uchar* *) & default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
|
2006-04-28 06:07:25 +02:00
|
|
|
#endif
|
2007-08-01 21:59:05 +02:00
|
|
|
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit .",
|
|
|
|
(uchar**) &debug_check_flag, (uchar**) &debug_check_flag, 0,
|
|
|
|
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
{"debug-info", 'T', "Print some debug info at exit.", (uchar**) &debug_info_flag,
|
|
|
|
(uchar**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
2006-11-08 03:45:50 +01:00
|
|
|
{"default-character-set", OPT_DEFAULT_CHARSET,
|
2007-04-18 13:21:39 +02:00
|
|
|
"Set the default character set.", 0,
|
|
|
|
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
{"force", 'f', "Force execution of mysqlcheck even if mysql_upgrade "
|
|
|
|
"has already been executed for the current version of MySQL.",
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
(uchar**)&opt_force, (uchar**)&opt_force, 0,
|
2007-04-18 13:21:39 +02:00
|
|
|
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
{"host",'h', "Connect to host.", 0,
|
|
|
|
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2006-04-28 06:07:25 +02:00
|
|
|
{"password", 'p',
|
2006-11-08 03:45:50 +01:00
|
|
|
"Password to use when connecting to server. If password is not given"
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
" it's solicited on the tty.", (uchar**) &opt_password,(uchar**) &opt_password,
|
2007-04-18 13:21:39 +02:00
|
|
|
0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
|
2006-11-08 03:45:50 +01:00
|
|
|
#ifdef __WIN__
|
2007-04-18 13:21:39 +02:00
|
|
|
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0,
|
2006-11-08 03:45:50 +01:00
|
|
|
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
#endif
|
2007-04-18 13:21:39 +02:00
|
|
|
{"port", 'P', "Port number to use for connection.", 0,
|
|
|
|
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2006-04-28 06:07:25 +02:00
|
|
|
{"protocol", OPT_MYSQL_PROTOCOL,
|
|
|
|
"The protocol of connection (tcp,socket,pipe,memory).",
|
|
|
|
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2006-11-08 03:45:50 +01:00
|
|
|
#ifdef HAVE_SMEM
|
|
|
|
{"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
|
2007-04-18 13:21:39 +02:00
|
|
|
"Base name of shared memory.", 0,
|
|
|
|
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2006-11-08 03:45:50 +01:00
|
|
|
#endif
|
2006-04-28 06:07:25 +02:00
|
|
|
{"socket", 'S', "Socket file to use for connection.",
|
2007-04-18 13:21:39 +02:00
|
|
|
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
{"user", 'u', "User for login if not current user.", (uchar**) &opt_user,
|
|
|
|
(uchar**) &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2006-11-08 03:45:50 +01:00
|
|
|
#include <sslopt-longopts.h>
|
2007-04-18 13:21:39 +02:00
|
|
|
{"verbose", 'v', "Display more output about the process",
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
(uchar**) &opt_verbose, (uchar**) &opt_verbose, 0,
|
2007-04-18 13:21:39 +02:00
|
|
|
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
|
2006-04-28 06:07:25 +02:00
|
|
|
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
|
|
|
|
};
|
2006-11-08 03:45:50 +01:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
#include <help_end.h>
|
|
|
|
|
|
|
|
|
|
|
|
static void free_used_memory(void)
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/* Free memory allocated by 'load_defaults' */
|
|
|
|
free_defaults(defaults_argv);
|
|
|
|
|
2007-04-19 21:30:46 +02:00
|
|
|
dynstr_free(&ds_args);
|
2007-04-18 13:21:39 +02:00
|
|
|
}
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2006-11-08 03:45:50 +01:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
static void die(const char *fmt, ...)
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
va_list args;
|
|
|
|
DBUG_ENTER("die");
|
|
|
|
|
|
|
|
/* Print the error message */
|
|
|
|
va_start(args, fmt);
|
|
|
|
if (fmt)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "FATAL ERROR: ");
|
|
|
|
vfprintf(stderr, fmt, args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
free_used_memory();
|
2007-08-01 21:59:05 +02:00
|
|
|
my_end(my_end_arg);
|
2007-04-18 13:21:39 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void verbose(const char *fmt, ...)
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (!opt_verbose)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Print the verbose message */
|
|
|
|
va_start(args, fmt);
|
|
|
|
if (fmt)
|
|
|
|
{
|
|
|
|
vfprintf(stdout, fmt, args);
|
|
|
|
fprintf(stdout, "\n");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Add one option - passed to mysql_upgrade on command line
|
2007-04-19 21:30:46 +02:00
|
|
|
or by defaults file(my.cnf) - to a dynamic string, in
|
|
|
|
this way we pass the same arguments on to mysql and mysql_check
|
2007-04-18 13:21:39 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
static void add_one_option(DYNAMIC_STRING* ds,
|
|
|
|
const struct my_option *opt,
|
|
|
|
const char* argument)
|
2006-11-08 03:45:50 +01:00
|
|
|
|
2007-04-19 21:30:46 +02:00
|
|
|
{
|
|
|
|
const char* eq= NullS;
|
|
|
|
const char* arg= NullS;
|
2007-04-18 13:21:39 +02:00
|
|
|
if (opt->arg_type != NO_ARG)
|
|
|
|
{
|
2007-04-19 21:30:46 +02:00
|
|
|
eq= "=";
|
2007-04-18 13:21:39 +02:00
|
|
|
switch (opt->var_type & GET_TYPE_MASK) {
|
|
|
|
case GET_STR:
|
2007-04-19 21:30:46 +02:00
|
|
|
arg= argument;
|
2007-04-18 13:21:39 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
die("internal error at %s: %d",__FILE__, __LINE__);
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
|
|
|
}
|
2007-04-19 21:30:46 +02:00
|
|
|
dynstr_append_os_quoted(ds, "--", opt->name, eq, arg, NullS);
|
|
|
|
dynstr_append(&ds_args, " ");
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
static my_bool
|
2007-04-18 13:21:39 +02:00
|
|
|
get_one_option(int optid, const struct my_option *opt,
|
2006-04-28 06:07:25 +02:00
|
|
|
char *argument)
|
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
my_bool add_option= TRUE;
|
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
switch (optid) {
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
case '?':
|
2007-08-01 21:59:05 +02:00
|
|
|
printf("%s Ver %s Distrib %s, for %s (%s)\n",
|
|
|
|
my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
|
|
|
|
puts("MySQL utility for upgrading databases to new MySQL versions\n");
|
2006-04-28 06:07:25 +02:00
|
|
|
my_print_help(my_long_options);
|
|
|
|
exit(0);
|
2007-04-18 13:21:39 +02:00
|
|
|
break;
|
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
case '#':
|
|
|
|
DBUG_PUSH(argument ? argument : default_dbug_option);
|
2007-04-18 13:21:39 +02:00
|
|
|
add_option= FALSE;
|
2007-08-02 06:49:29 +02:00
|
|
|
debug_check_flag= 1;
|
2006-04-28 06:07:25 +02:00
|
|
|
break;
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
case 'p':
|
|
|
|
tty_password= 1;
|
2007-04-18 13:21:39 +02:00
|
|
|
add_option= FALSE;
|
2006-04-28 06:07:25 +02:00
|
|
|
if (argument)
|
|
|
|
{
|
2007-04-19 21:30:46 +02:00
|
|
|
/* Add password to ds_args before overwriting the arg with x's */
|
|
|
|
add_one_option(&ds_args, opt, argument);
|
2006-04-28 06:07:25 +02:00
|
|
|
while (*argument)
|
|
|
|
*argument++= 'x'; /* Destroy argument */
|
|
|
|
tty_password= 0;
|
|
|
|
}
|
|
|
|
break;
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
case 'b': /* --basedir */
|
|
|
|
case 'v': /* --verbose */
|
|
|
|
case 'd': /* --datadir */
|
|
|
|
case 'f': /* --force */
|
|
|
|
add_option= FALSE;
|
2006-11-08 03:45:50 +01:00
|
|
|
break;
|
2007-04-18 13:21:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (add_option)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
This is an option that is accpted by mysql_upgrade just so
|
|
|
|
it can be passed on to "mysql" and "mysqlcheck"
|
2007-04-19 21:30:46 +02:00
|
|
|
Save it in the ds_args string
|
2007-04-18 13:21:39 +02:00
|
|
|
*/
|
2007-04-19 21:30:46 +02:00
|
|
|
add_one_option(&ds_args, opt, argument);
|
2007-04-18 13:21:39 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int run_command(char* cmd,
|
|
|
|
DYNAMIC_STRING *ds_res)
|
|
|
|
{
|
|
|
|
char buf[512]= {0};
|
|
|
|
FILE *res_file;
|
2007-04-23 13:27:55 +02:00
|
|
|
int error;
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
if (!(res_file= popen(cmd, "r")))
|
|
|
|
die("popen(\"%s\", \"r\") failed", cmd);
|
|
|
|
|
|
|
|
while (fgets(buf, sizeof(buf), res_file))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("buf: %s", buf));
|
|
|
|
if(ds_res)
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/* Save the output of this command in the supplied string */
|
|
|
|
dynstr_append(ds_res, buf);
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
else
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/* Print it directly on screen */
|
|
|
|
fprintf(stdout, "%s", buf);
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2007-04-23 13:27:55 +02:00
|
|
|
error= pclose(res_file);
|
|
|
|
return WEXITSTATUS(error);
|
2006-04-28 06:07:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
static int run_tool(char *tool_path, DYNAMIC_STRING *ds_res, ...)
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2006-11-08 03:45:50 +01:00
|
|
|
int ret;
|
2007-04-18 13:21:39 +02:00
|
|
|
const char* arg;
|
|
|
|
va_list args;
|
|
|
|
DYNAMIC_STRING ds_cmdline;
|
|
|
|
|
|
|
|
DBUG_ENTER("run_tool");
|
|
|
|
DBUG_PRINT("enter", ("tool_path: %s", tool_path));
|
|
|
|
|
|
|
|
if (init_dynamic_string(&ds_cmdline, IF_WIN("\"", ""), FN_REFLEN, FN_REFLEN))
|
|
|
|
die("Out of memory");
|
|
|
|
|
|
|
|
dynstr_append_os_quoted(&ds_cmdline, tool_path, NullS);
|
|
|
|
dynstr_append(&ds_cmdline, " ");
|
|
|
|
|
|
|
|
va_start(args, ds_res);
|
|
|
|
|
|
|
|
while ((arg= va_arg(args, char *)))
|
|
|
|
{
|
|
|
|
/* Options should be os quoted */
|
|
|
|
if (strncmp(arg, "--", 2) == 0)
|
|
|
|
dynstr_append_os_quoted(&ds_cmdline, arg, NullS);
|
|
|
|
else
|
|
|
|
dynstr_append(&ds_cmdline, arg);
|
|
|
|
dynstr_append(&ds_cmdline, " ");
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
|
2007-04-19 17:00:29 +02:00
|
|
|
#ifdef __WIN__
|
|
|
|
dynstr_append(&ds_cmdline, "\"");
|
|
|
|
#endif
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
DBUG_PRINT("info", ("Running: %s", ds_cmdline.str));
|
|
|
|
ret= run_command(ds_cmdline.str, ds_res);
|
|
|
|
DBUG_PRINT("exit", ("ret: %d", ret));
|
|
|
|
dynstr_free(&ds_cmdline);
|
|
|
|
DBUG_RETURN(ret);
|
2006-04-28 06:07:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Try to get the full path to this exceutable
|
|
|
|
|
|
|
|
Return 0 if path found
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static my_bool get_full_path_to_executable(char* path)
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
my_bool ret;
|
|
|
|
DBUG_ENTER("get_full_path_to_executable");
|
2007-04-19 17:00:29 +02:00
|
|
|
#ifdef __WIN__
|
|
|
|
ret= (GetModuleFileName(NULL, path, FN_REFLEN) == 0);
|
2007-04-18 13:21:39 +02:00
|
|
|
#else
|
|
|
|
/* my_readlink returns 0 if a symlink was read */
|
2007-04-19 17:00:29 +02:00
|
|
|
ret= (my_readlink(path, "/proc/self/exe", MYF(0)) != 0);
|
2007-04-18 13:21:39 +02:00
|
|
|
/* Might also want to try with /proc/$$/exe if the above fails */
|
|
|
|
#endif
|
|
|
|
DBUG_PRINT("exit", ("path: %s", path));
|
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
2006-11-08 03:45:50 +01:00
|
|
|
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Look for the tool in the same directory as mysql_upgrade.
|
2006-08-11 21:31:06 +02:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
When running in a not yet installed build the the program
|
|
|
|
will exist but it need to be invoked via it's libtool wrapper.
|
|
|
|
Check if the found tool can executed and if not look in the
|
|
|
|
directory one step higher up where the libtool wrapper normally
|
|
|
|
is found
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void find_tool(char *tool_path, const char *tool_name)
|
|
|
|
{
|
|
|
|
char path[FN_REFLEN];
|
|
|
|
DYNAMIC_STRING ds_tmp;
|
|
|
|
DBUG_ENTER("find_tool");
|
|
|
|
DBUG_PRINT("enter", ("progname: %s", my_progname));
|
|
|
|
|
|
|
|
if (init_dynamic_string(&ds_tmp, "", 32, 32))
|
|
|
|
die("Out of memory");
|
2007-02-28 21:05:39 +01:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/* Initialize path with the full path to this program */
|
|
|
|
if (get_full_path_to_executable(path))
|
2006-12-08 10:23:03 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Easy way to get full executable path failed, try
|
|
|
|
other methods
|
|
|
|
*/
|
|
|
|
if (my_progname[0] == FN_LIBCHAR)
|
2006-12-08 10:23:03 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/* 1. my_progname contains full path */
|
|
|
|
strmake(path, my_progname, FN_REFLEN);
|
2006-12-08 10:23:03 +01:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
else if (my_progname[0] == '.')
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/* 2. my_progname contains relative path, prepend wd */
|
|
|
|
char buf[FN_REFLEN];
|
|
|
|
my_getwd(buf, FN_REFLEN, MYF(0));
|
2007-04-18 18:40:22 +02:00
|
|
|
my_snprintf(path, FN_REFLEN, "%s%s", buf, my_progname);
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
else
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/* 3. Just go for it and hope tool is in path */
|
|
|
|
path[0]= 0;
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
do
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
size_t path_len;
|
2007-04-18 13:21:39 +02:00
|
|
|
DBUG_PRINT("enter", ("path: %s", path));
|
|
|
|
|
|
|
|
/* Chop off last char(since it might be a /) */
|
2007-04-19 17:00:29 +02:00
|
|
|
path[max((strlen(path)-1), 0)]= 0;
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
/* Chop off last dir part */
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
dirname_part(path, path, &path_len);
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
/* Format name of the tool to search for */
|
|
|
|
fn_format(tool_path, tool_name,
|
|
|
|
path, "", MYF(MY_REPLACE_DIR));
|
|
|
|
|
|
|
|
verbose("Looking for '%s' in: %s", tool_name, tool_path);
|
|
|
|
|
|
|
|
/* Make sure the tool exists */
|
|
|
|
if (my_access(tool_path, F_OK) != 0)
|
|
|
|
die("Can't find '%s'", tool_path);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Make sure it can be executed, otherwise try again
|
|
|
|
in higher level directory
|
|
|
|
*/
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
while(run_tool(tool_path,
|
|
|
|
&ds_tmp, /* Get output from command, discard*/
|
|
|
|
"--help",
|
|
|
|
"2>&1",
|
|
|
|
IF_WIN("> NUL", "> /dev/null"),
|
|
|
|
NULL));
|
|
|
|
|
|
|
|
dynstr_free(&ds_tmp);
|
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Run query using "mysql"
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int run_query(const char *query, DYNAMIC_STRING *ds_res,
|
|
|
|
my_bool force)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
File fd;
|
|
|
|
char query_file_path[FN_REFLEN];
|
|
|
|
DBUG_ENTER("run_query");
|
|
|
|
DBUG_PRINT("enter", ("query: %s", query));
|
|
|
|
if ((fd= create_temp_file(query_file_path, NULL,
|
2007-04-19 21:30:46 +02:00
|
|
|
"sql", O_CREAT | O_SHARE | O_RDWR,
|
2007-04-18 13:21:39 +02:00
|
|
|
MYF(MY_WME))) < 0)
|
|
|
|
die("Failed to create temporary file for defaults");
|
|
|
|
|
|
|
|
if (my_write(fd, query, strlen(query),
|
|
|
|
MYF(MY_FNABP | MY_WME)))
|
|
|
|
die("Failed to write to '%s'", query_file_path);
|
|
|
|
|
|
|
|
ret= run_tool(mysql_path,
|
|
|
|
ds_res,
|
2007-04-20 07:20:26 +02:00
|
|
|
ds_args.str,
|
2007-04-18 13:21:39 +02:00
|
|
|
"--database=mysql",
|
|
|
|
"--batch", /* Turns off pager etc. */
|
|
|
|
force ? "--force": "--skip-force",
|
|
|
|
ds_res ? "--silent": "",
|
|
|
|
"<",
|
|
|
|
query_file_path,
|
|
|
|
"2>&1",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
my_close(fd, MYF(0));
|
2007-08-03 12:54:06 +02:00
|
|
|
my_delete(query_file_path, MYF(0));
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2007-02-28 21:05:39 +01:00
|
|
|
DBUG_RETURN(ret);
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Extract the value returned from result of "show variable like ..."
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int extract_variable_from_show(DYNAMIC_STRING* ds, char* value)
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
char *value_start, *value_end;
|
|
|
|
/*
|
|
|
|
The query returns "datadir\t<datadir>\n", skip past
|
|
|
|
the tab
|
|
|
|
*/
|
|
|
|
if ((value_start= strchr(ds->str, '\t')) == NULL)
|
|
|
|
return 1; /* Unexpected result */
|
|
|
|
value_start++;
|
|
|
|
|
|
|
|
/* Don't copy the ending newline */
|
2007-04-18 19:00:42 +02:00
|
|
|
if ((value_end= strchr(value_start, '\n')) == NULL)
|
2007-04-18 13:21:39 +02:00
|
|
|
return 1; /* Unexpected result */
|
|
|
|
|
|
|
|
strncpy(value, value_start, min(FN_REFLEN, value_end-value_start));
|
|
|
|
return 0;
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
static int get_upgrade_info_file_name(char* name)
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
DYNAMIC_STRING ds_datadir;
|
|
|
|
DBUG_ENTER("get_upgrade_info_file_name");
|
|
|
|
|
|
|
|
if (init_dynamic_string(&ds_datadir, NULL, 32, 32))
|
|
|
|
die("Out of memory");
|
|
|
|
|
|
|
|
if (run_query("show variables like 'datadir'",
|
|
|
|
&ds_datadir, FALSE) ||
|
|
|
|
extract_variable_from_show(&ds_datadir, name))
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
dynstr_free(&ds_datadir);
|
|
|
|
DBUG_RETURN(1); /* Query failed */
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
dynstr_free(&ds_datadir);
|
|
|
|
|
|
|
|
fn_format(name, "mysql_upgrade_info", name, "", MYF(0));
|
|
|
|
DBUG_PRINT("exit", ("name: %s", name));
|
|
|
|
DBUG_RETURN(0);
|
2006-04-28 06:07:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Read the content of mysql_upgrade_info file and
|
|
|
|
compare the version number form file against
|
|
|
|
version number wich mysql_upgrade was compiled for
|
|
|
|
|
|
|
|
NOTE
|
|
|
|
This is an optimization to avoid running mysql_upgrade
|
|
|
|
when it's already been performed for the particular
|
|
|
|
version of MySQL.
|
|
|
|
|
|
|
|
In case the MySQL server can't return the upgrade info
|
|
|
|
file it's always better to report that the upgrade hasn't
|
|
|
|
been performed.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int upgrade_already_done(void)
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
FILE *in;
|
|
|
|
char upgrade_info_file[FN_REFLEN]= {0};
|
|
|
|
char buf[sizeof(MYSQL_SERVER_VERSION)+1];
|
2007-03-01 18:12:56 +01:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
if (get_upgrade_info_file_name(upgrade_info_file))
|
|
|
|
return 0; /* Could not get filename => not sure */
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
if (!(in= my_fopen(upgrade_info_file, O_RDONLY, MYF(0))))
|
|
|
|
return 0; /* Could not open file => not sure */
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Read from file, don't care if it fails since it
|
|
|
|
will be detected by the strncmp
|
|
|
|
*/
|
|
|
|
bzero(buf, sizeof(buf));
|
|
|
|
fgets(buf, sizeof(buf), in);
|
2007-02-28 21:23:35 +01:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
my_fclose(in, MYF(0));
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
return (strncmp(buf, MYSQL_SERVER_VERSION,
|
|
|
|
sizeof(MYSQL_SERVER_VERSION)-1)==0);
|
|
|
|
}
|
2006-04-28 06:07:25 +02:00
|
|
|
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Write mysql_upgrade_info file in servers data dir indicating that
|
|
|
|
upgrade has been done for this version
|
|
|
|
|
|
|
|
NOTE
|
|
|
|
This might very well fail but since it's just an optimization
|
|
|
|
to run mysql_upgrade only when necessary the error can be
|
|
|
|
ignored.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void create_mysql_upgrade_info_file(void)
|
|
|
|
{
|
|
|
|
FILE *out;
|
|
|
|
char upgrade_info_file[FN_REFLEN]= {0};
|
|
|
|
|
|
|
|
if (get_upgrade_info_file_name(upgrade_info_file))
|
|
|
|
return; /* Could not get filename => skip */
|
|
|
|
|
|
|
|
if (!(out= my_fopen(upgrade_info_file, O_TRUNC | O_WRONLY, MYF(0))))
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2006-11-21 00:46:13 +01:00
|
|
|
fprintf(stderr,
|
2007-04-18 13:21:39 +02:00
|
|
|
"Could not create the upgrade info file '%s' in "
|
|
|
|
"the MySQL Servers datadir, errno: %d\n",
|
|
|
|
upgrade_info_file, errno);
|
|
|
|
return;
|
2006-04-28 06:07:25 +02:00
|
|
|
}
|
|
|
|
|
2007-04-23 13:07:49 +02:00
|
|
|
/* Write new version to file */
|
|
|
|
fputs(MYSQL_SERVER_VERSION, out);
|
|
|
|
my_fclose(out, MYF(0));
|
|
|
|
|
|
|
|
/*
|
|
|
|
Check if the upgrad_info_file was properly created/updated
|
|
|
|
It's not a fatal error -> just print a message if it fails
|
|
|
|
*/
|
|
|
|
if (!upgrade_already_done())
|
2007-04-18 13:21:39 +02:00
|
|
|
fprintf(stderr,
|
|
|
|
"Could not write to the upgrade info file '%s' in "
|
|
|
|
"the MySQL Servers datadir, errno: %d\n",
|
|
|
|
upgrade_info_file, errno);
|
2007-04-23 13:07:49 +02:00
|
|
|
return;
|
2007-04-18 13:21:39 +02:00
|
|
|
}
|
2007-02-28 21:05:39 +01:00
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Check and upgrade(if neccessary) all tables
|
|
|
|
in the server using "mysqlcheck --check-upgrade .."
|
|
|
|
*/
|
2007-02-28 21:05:39 +01:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
static int run_mysqlcheck_upgrade(void)
|
|
|
|
{
|
|
|
|
verbose("Running 'mysqlcheck'...");
|
|
|
|
return run_tool(mysqlcheck_path,
|
|
|
|
NULL, /* Send output from mysqlcheck directly to screen */
|
2007-04-19 21:30:46 +02:00
|
|
|
ds_args.str,
|
2007-04-18 13:21:39 +02:00
|
|
|
"--check-upgrade",
|
|
|
|
"--all-databases",
|
|
|
|
"--auto-repair",
|
|
|
|
NULL);
|
|
|
|
}
|
2007-02-28 21:05:39 +01:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
static const char *expected_errors[]=
|
|
|
|
{
|
|
|
|
"ERROR 1060", /* Duplicate column name */
|
|
|
|
"ERROR 1061", /* Duplicate key name */
|
|
|
|
"ERROR 1054", /* Unknown column */
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static my_bool is_expected_error(const char* line)
|
|
|
|
{
|
|
|
|
const char** error= expected_errors;
|
|
|
|
while (*error)
|
2007-01-18 17:38:05 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Check if lines starting with ERROR
|
|
|
|
are in the list of expected errors
|
|
|
|
*/
|
|
|
|
if (strncmp(line, "ERROR", 5) != 0 ||
|
|
|
|
strncmp(line, *error, strlen(*error)) == 0)
|
|
|
|
return 1; /* Found expected error */
|
|
|
|
error++;
|
2007-01-18 17:38:05 +01:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
static char* get_line(char* line)
|
|
|
|
{
|
|
|
|
while (*line && *line != '\n')
|
|
|
|
line++;
|
|
|
|
if (*line)
|
|
|
|
line++;
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Print the current line to stderr */
|
|
|
|
static void print_line(char* line)
|
|
|
|
{
|
|
|
|
while (*line && *line != '\n')
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
fputc(*line, stderr);
|
|
|
|
line++;
|
2006-04-28 06:07:25 +02:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
fputc('\n', stderr);
|
|
|
|
}
|
2006-04-28 06:07:25 +02:00
|
|
|
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Update all system tables in MySQL Server to current
|
|
|
|
version using "mysql" to execute all the SQL commands
|
|
|
|
compiled into the mysql_fix_privilege_tables array
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int run_sql_fix_privilege_tables(void)
|
|
|
|
{
|
|
|
|
int found_real_errors= 0;
|
|
|
|
DYNAMIC_STRING ds_result;
|
|
|
|
DBUG_ENTER("run_sql_fix_privilege_tables");
|
|
|
|
|
|
|
|
if (init_dynamic_string(&ds_result, "", 512, 512))
|
|
|
|
die("Out of memory");
|
|
|
|
|
|
|
|
verbose("Running 'mysql_fix_privilege_tables'...");
|
|
|
|
run_query(mysql_fix_privilege_tables,
|
|
|
|
&ds_result, /* Collect result */
|
|
|
|
TRUE);
|
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Scan each line of the result for real errors
|
|
|
|
and ignore the expected one(s) like "Duplicate column name",
|
|
|
|
"Unknown column" and "Duplicate key name" since they just
|
|
|
|
indicate the system tables are already up to date
|
|
|
|
*/
|
|
|
|
char *line= ds_result.str;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!is_expected_error(line))
|
|
|
|
{
|
|
|
|
/* Something unexpected failed, dump error line to screen */
|
|
|
|
found_real_errors++;
|
|
|
|
print_line(line);
|
|
|
|
}
|
|
|
|
} while ((line= get_line(line)) && *line);
|
2006-04-28 06:07:25 +02:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
dynstr_free(&ds_result);
|
|
|
|
return found_real_errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char *load_default_groups[]=
|
|
|
|
{
|
|
|
|
"client", /* Read settings how to connect to server */
|
|
|
|
"mysql_upgrade", /* Read special settings for mysql_upgrade*/
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
MY_INIT(argv[0]);
|
|
|
|
#ifdef __NETWARE__
|
|
|
|
setscreenmode(SCR_AUTOCLOSE_ON_EXIT);
|
|
|
|
#endif
|
|
|
|
|
2007-04-19 21:30:46 +02:00
|
|
|
if (init_dynamic_string(&ds_args, "", 512, 256))
|
2007-04-18 13:21:39 +02:00
|
|
|
die("Out of memory");
|
|
|
|
|
|
|
|
load_defaults("my", load_default_groups, &argc, &argv);
|
|
|
|
defaults_argv= argv; /* Must be freed by 'free_defaults' */
|
|
|
|
|
|
|
|
if (handle_options(&argc, &argv, my_long_options, get_one_option))
|
|
|
|
die(NULL);
|
2007-08-01 21:59:05 +02:00
|
|
|
if (debug_info_flag)
|
|
|
|
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
|
|
|
|
if (debug_check_flag)
|
|
|
|
my_end_arg= MY_CHECK_ERROR;
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
if (tty_password)
|
2007-01-18 17:38:05 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
opt_password= get_tty_password(NullS);
|
|
|
|
/* add password to defaults file */
|
2007-04-19 21:30:46 +02:00
|
|
|
dynstr_append_os_quoted(&ds_args, "--password=", opt_password, NullS);
|
|
|
|
dynstr_append(&ds_args, " ");
|
2007-01-18 17:38:05 +01:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
/* add user to defaults file */
|
2007-04-19 21:30:46 +02:00
|
|
|
dynstr_append_os_quoted(&ds_args, "--user=", opt_user, NullS);
|
|
|
|
dynstr_append(&ds_args, " ");
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
/* Find mysql */
|
|
|
|
find_tool(mysql_path, IF_WIN("mysql.exe", "mysql"));
|
|
|
|
|
|
|
|
/* Find mysqlcheck */
|
|
|
|
find_tool(mysqlcheck_path, IF_WIN("mysqlcheck.exe", "mysqlcheck"));
|
2006-11-08 03:45:50 +01:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Read the mysql_upgrade_info file to check if mysql_upgrade
|
|
|
|
already has been run for this installation of MySQL
|
|
|
|
*/
|
|
|
|
if (!opt_force && upgrade_already_done())
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
printf("This installation of MySQL is already upgraded to %s, "
|
|
|
|
"use --force if you still need to run mysql_upgrade\n",
|
|
|
|
MYSQL_SERVER_VERSION);
|
|
|
|
die(NULL);
|
2006-04-28 06:07:25 +02:00
|
|
|
}
|
|
|
|
|
2007-02-28 21:05:39 +01:00
|
|
|
/*
|
2007-04-18 13:21:39 +02:00
|
|
|
Run "mysqlcheck" and "mysql_fix_privilege_tables.sql"
|
2007-02-28 21:05:39 +01:00
|
|
|
*/
|
2007-04-18 13:21:39 +02:00
|
|
|
if (run_mysqlcheck_upgrade() ||
|
|
|
|
run_sql_fix_privilege_tables())
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
The upgrade failed to complete in some way or another,
|
|
|
|
significant error message should have been printed to the screen
|
|
|
|
*/
|
|
|
|
die("Upgrade failed" );
|
|
|
|
}
|
|
|
|
verbose("OK");
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/* Create a file indicating upgrade has been performed */
|
|
|
|
create_mysql_upgrade_info_file();
|
2007-02-28 21:05:39 +01:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
free_used_memory();
|
2007-08-01 21:59:05 +02:00
|
|
|
my_end(my_end_arg);
|
2007-04-18 13:21:39 +02:00
|
|
|
exit(0);
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
|
|
|
|