summaryrefslogtreecommitdiff
path: root/mysys/my_error.c
diff options
context:
space:
mode:
authorunknown <ingo@mysql.com>2004-12-23 20:11:38 +0100
committerunknown <ingo@mysql.com>2004-12-23 20:11:38 +0100
commitbec3feaa0bdf4d89bc3c3f1255ebf70a624f4850 (patch)
tree50e9e32282ae9dd90825e12f5be6e80b9e77f31f /mysys/my_error.c
parent1a1974544d0be772edc20806ec881b2c5df61a6d (diff)
downloadmariadb-git-bec3feaa0bdf4d89bc3c3f1255ebf70a624f4850.tar.gz
WL#1895 - Print message to error log in case of detected MyISAM corruption
Changed my_error() to print error messages, which come from arbitrary registered ranges of error messages. Messages can be unregistered (and should be at end of the program). Added registration of handler error messages. Added a new mi_print_error() macro and a new mi_report_error() function, which supply error messages with a table name. Added calls to mi_print_error() or mi_report_error() at all places in MyISAM, where table corruption is detected. extra/comp_err.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added prints for ER_ERROR_FIRST and ER_ERROR_LAST. Removed print for ER_ERROR_MESSAGES. include/errmsg.h: WL#1895 - Print message to error log in case of detected MyISAM corruption Added declaration for a new function. Added first and last error number defines. include/my_base.h: WL#1895 - Print message to error log in case of detected MyISAM corruption Added first and last error number defines. include/my_sys.h: WL#1895 - Print message to error log in case of detected MyISAM corruption Removed obsolete defines. Removed a global variable, which held pointers to the error message arrays. Added declarations for new functions. include/mysys_err.h: WL#1895 - Print message to error log in case of detected MyISAM corruption Removed an obsolete define. Changed two defines to use the new defines. Added first and last error number defines. libmysql/errmsg.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Replaced global array initialization by proper registration and unregistration of client error messages. libmysql/libmysql.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added a call for unregistration of client error messages. myisam/mi_delete.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added calls to the new error logging function at all places, where corruption is detected. Added a debugging call to pretend MyISAM corruption in case a special debug string is set. Added a debugging call to test undefined error numbers in case a special debug string is set. myisam/mi_extra.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added calls to the new error logging function at all places, where corruption is detected. myisam/mi_info.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added the error logging function. myisam/mi_key.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added calls to the new error logging function at all places, where corruption is detected. myisam/mi_keycache.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added calls to the new error logging function at all places, where corruption is detected. myisam/mi_locking.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added calls to the new error logging function at all places, where corruption is detected. myisam/mi_open.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added calls to the new error logging function at all places, where corruption is detected. Added a debugging call to pretend MyISAM corruption in case a special debug string is set. myisam/mi_page.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added calls to the new error logging function at all places, where corruption is detected. myisam/mi_range.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added calls to the new error logging function at all places, where corruption is detected. myisam/mi_rkey.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added calls to the new error logging function at all places, where corruption is detected. myisam/mi_search.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added calls to the new error logging function at all places, where corruption is detected. myisam/mi_update.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added calls to the new error logging function at all places, where corruption is detected. Added a debugging call to pretend MyISAM corruption in case a special debug string is set. myisam/mi_write.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Added calls to the new error logging function at all places, where corruption is detected. Added a debugging call to pretend MyISAM corruption in case a special debug string is set. myisam/myisamdef.h: WL#1895 - Print message to error log in case of detected MyISAM corruption Added the declaration of the new error logging function and a new macro. mysql-test/r/merge.result: WL#1895 - Print message to error log in case of detected MyISAM corruption Changed test results. These come from the changed error reporting in openfrm(). mysql-test/r/repair.result: WL#1895 - Print message to error log in case of detected MyISAM corruption Changed test results. These come from the changed error reporting in openfrm(). mysql-test/t/merge.test: WL#1895 - Print message to error log in case of detected MyISAM corruption Changederror numbers. These come from the changed error reporting in openfrm(). mysys/errors.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Dropped the assignment of the global errors to the dropped global pointer array. mysys/my_error.c: WL#1895 - Print message to error log in case of detected MyISAM corruption Changed my_error() from using a static array of pointers to error message arrays to using a linked list of structures with pointers to array message arrays. Added functions for registering and unregistering error message arrays to the chain. sql/derror.cc: WL#1895 - Print message to error log in case of detected MyISAM corruption Changed reading of mysqld error messages to using the new registering and unregistering functions. sql/handler.cc: WL#1895 - Print message to error log in case of detected MyISAM corruption Added initialization and deinitialization of handler error messages. Included more handler error messages in the mapping to mysqld error messages. sql/mysqld.cc: WL#1895 - Print message to error log in case of detected MyISAM corruption Changed deinitialization of error messages to proper unregistration. sql/table.cc: WL#1895 - Print message to error log in case of detected MyISAM corruption Changed error reporting in openfrm() so that error messages from handler::ha_open() are reported by handler::print_error(). This changed messages from "Can't open 't1.MYI' (errno: 130)" to "Incorrect file format 't1'" for example. sql/unireg.h: WL#1895 - Print message to error log in case of detected MyISAM corruption Changed two defines to use the new defines.
Diffstat (limited to 'mysys/my_error.c')
-rw-r--r--mysys/my_error.c163
1 files changed, 151 insertions, 12 deletions
diff --git a/mysys/my_error.c b/mysys/my_error.c
index 175f8cf516b..0c18bbf6e8b 100644
--- a/mysys/my_error.c
+++ b/mysys/my_error.c
@@ -31,10 +31,31 @@
my_printf_error(ER_CODE, format, MYF(N), ...)
*/
-const char ** NEAR my_errmsg[MAXMAPS]={0,0,0,0};
char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
/*
+ Message texts are registered into a linked list of 'my_err_head' structs.
+ Each struct contains (1.) an array of pointers to C character strings with
+ '\0' termination, (2.) the error number for the first message in the array
+ (array index 0) and (3.) the error number for the last message in the array
+ (array index (last - first)).
+ The array may contain gaps with NULL pointers and pointers to empty strings.
+ Both kinds of gaps will be translated to "Unknown error %d.", if my_error()
+ is called with a respective error number.
+ The list of header structs is sorted in increasing order of error numbers.
+ Negative error numbers are allowed. Overlap of error numbers is not allowed.
+ Not registered error numbers will be translated to "Unknown error %d.".
+*/
+static struct my_err_head
+{
+ struct my_err_head *meh_next; /* chain link */
+ const char **meh_errmsgs; /* error messages array */
+ int meh_first; /* error number matching array slot 0 */
+ int meh_last; /* error number matching last slot */
+} my_errmsgs_globerrs = {NULL, globerrs, EE_ERROR_FIRST, EE_ERROR_LAST};
+static struct my_err_head *my_errmsgs_list= &my_errmsgs_globerrs;
+
+/*
Error message to user
SYNOPSIS
@@ -42,30 +63,42 @@ char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
nr Errno
MyFlags Flags
... variable list
- NOTE
- The following subset of printf format is supported:
- "%[0-9.-]*l?[sdu]", where all length flags are parsed but ignored.
- Additionally "%.*s" is supported and "%.*[ud]" is correctly parsed but
- the length value is ignored.
+ RETURN
+ What (*error_handler_hook)() returns:
+ 0 OK
*/
int my_error(int nr, myf MyFlags, ...)
{
const char *format;
+ struct my_err_head *meh_p;
va_list args;
char ebuff[ERRMSGSIZE + 20];
DBUG_ENTER("my_error");
DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d", nr, MyFlags, errno));
- if (nr / ERRMOD == GLOB && my_errmsg[GLOB] == 0)
- init_glob_errs();
- format= my_errmsg[nr / ERRMOD][nr % ERRMOD];
+ /* Search for the error messages array, which could contain the message. */
+ for (meh_p= my_errmsgs_list; meh_p; meh_p= meh_p->meh_next)
+ if (nr <= meh_p->meh_last)
+ break;
- va_start(args,MyFlags);
- (void) my_vsnprintf (ebuff, sizeof(ebuff), format, args);
- va_end(args);
+#ifdef SHARED_LIBRARY
+ if ((meh_p == &my_errmsgs_globerrs) && ! globerrs[0])
+ init_glob_errs();
+#endif
+
+ /* get the error message string. Default, if NULL or empty string (""). */
+ if (! (format= (meh_p && (nr >= meh_p->meh_first)) ?
+ meh_p->meh_errmsgs[nr - meh_p->meh_first] : NULL) || ! *format)
+ (void) my_snprintf (ebuff, sizeof(ebuff), "Unknown error %d", nr);
+ else
+ {
+ va_start(args,MyFlags);
+ (void) my_vsnprintf (ebuff, sizeof(ebuff), format, args);
+ va_end(args);
+ }
DBUG_RETURN((*error_handler_hook)(nr, ebuff, MyFlags));
}
@@ -108,3 +141,109 @@ int my_message(uint error, const char *str, register myf MyFlags)
{
return (*error_handler_hook)(error, str, MyFlags);
}
+
+
+/*
+ Register error messages for use with my_error().
+
+ SYNOPSIS
+ my_error_register()
+ errmsgs array of pointers to error messages
+ first error number of first message in the array
+ last error number of last message in the array
+
+ DESCRIPTION
+ The pointer array is expected to contain addresses to NUL-terminated
+ C character strings. The array contains (last - first + 1) pointers.
+ NULL pointers and empty strings ("") are allowed. These will be mapped to
+ "Unknown error" when my_error() is called with a matching error number.
+ This function registers the error numbers 'first' to 'last'.
+ No overlapping with previously registered error numbers is allowed.
+
+ RETURN
+ 0 OK
+ != 0 Error
+*/
+
+int my_error_register(const char **errmsgs, int first, int last)
+{
+ struct my_err_head *meh_p;
+ struct my_err_head **search_meh_pp;
+
+ /* Allocate a new header structure. */
+ if (! (meh_p= (struct my_err_head*) my_malloc(sizeof(struct my_err_head),
+ MYF(MY_WME))))
+ return 1;
+ meh_p->meh_errmsgs= errmsgs;
+ meh_p->meh_first= first;
+ meh_p->meh_last= last;
+
+ /* Search for the right position in the list. */
+ for (search_meh_pp= &my_errmsgs_list;
+ *search_meh_pp;
+ search_meh_pp= &(*search_meh_pp)->meh_next)
+ {
+ if ((*search_meh_pp)->meh_last > first)
+ break;
+ }
+
+ /* Error numbers must be unique. No overlapping is allowed. */
+ if (*search_meh_pp && ((*search_meh_pp)->meh_first <= last))
+ return 1;
+
+ /* Insert header into the chain. */
+ meh_p->meh_next= *search_meh_pp;
+ *search_meh_pp= meh_p;
+ return 0;
+}
+
+
+/*
+ Unregister formerly registered error messages.
+
+ SYNOPSIS
+ my_error_unregister()
+ first error number of first message
+ last error number of last message
+
+ DESCRIPTION
+ This function unregisters the error numbers 'first' to 'last'.
+ These must have been previously registered by my_error_register().
+ 'first' and 'last' must exactly match the registration.
+ If a matching registration is present, the header is removed from the
+ list and the pointer to the error messages pointers array is returned.
+ Otherwise, NULL is returned.
+
+ RETURN
+ non-NULL OK, returns address of error messages pointers array.
+ NULL Error, no such number range registered.
+*/
+
+const char **my_error_unregister(int first, int last)
+{
+ struct my_err_head *meh_p;
+ struct my_err_head **search_meh_pp;
+ const char **errmsgs;
+
+ /* Search for the registration in the list. */
+ for (search_meh_pp= &my_errmsgs_list;
+ *search_meh_pp;
+ search_meh_pp= &(*search_meh_pp)->meh_next)
+ {
+ if (((*search_meh_pp)->meh_first == first) &&
+ ((*search_meh_pp)->meh_last == last))
+ break;
+ }
+ if (! *search_meh_pp)
+ return NULL;
+
+ /* Remove header from the chain. */
+ meh_p= *search_meh_pp;
+ *search_meh_pp= meh_p->meh_next;
+
+ /* Save the return value and free the header. */
+ errmsgs= meh_p->meh_errmsgs;
+ my_free((gptr) meh_p, MYF(0));
+
+ return errmsgs;
+}