19 #define PERROR_VERSION "2.11"
21 #include <my_global.h>
25 #include <my_getopt.h>
26 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
27 #include "../storage/ndb/src/ndbapi/ndberror.c"
28 #include "../storage/ndb/src/kernel/error/ndbd_exit_codes.c"
29 #include "../storage/ndb/include/mgmapi/mgmapi_error.h"
31 #include <welcome_copyright_notice.h>
33 static my_bool verbose;
35 #include "../include/my_base.h"
36 #include "../mysys/my_handler_errors.h"
38 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
39 static my_bool ndb_code;
40 static char ndb_string[1024];
41 int mgmapi_error_string(
int err_no,
char *str,
int size)
44 for (i= 0; i < ndb_mgm_noOfErrorMsgs; i++)
46 if ((
int)ndb_mgm_error_msgs[i].
code == err_no)
48 my_snprintf(str, size-1,
"%s", ndb_mgm_error_msgs[i].
msg);
57 static struct my_option my_long_options[] =
59 {
"help",
'?',
"Displays this help and exits.", 0, 0, 0, GET_NO_ARG,
60 NO_ARG, 0, 0, 0, 0, 0, 0},
61 {
"info",
'I',
"Synonym for --help.", 0, 0, 0, GET_NO_ARG,
62 NO_ARG, 0, 0, 0, 0, 0, 0},
63 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
64 {
"ndb", 257,
"Ndbcluster storage engine specific error codes.", &ndb_code,
65 &ndb_code, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
67 {
"silent",
's',
"Only print the error message.", 0, 0, 0, GET_NO_ARG, NO_ARG,
69 {
"verbose",
'v',
"Print error code and message (default).", &verbose,
70 &verbose, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
71 {
"version",
'V',
"Displays version information and exits.",
72 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
73 {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
77 static void print_version(
void)
79 printf(
"%s Ver %s, for %s (%s)\n",my_progname,PERROR_VERSION,
80 SYSTEM_TYPE,MACHINE_TYPE);
84 static void usage(
void)
87 puts(ORACLE_WELCOME_COPYRIGHT_NOTICE(
"2000"));
88 printf(
"Print a description for a system error code or a MySQL error code.\n");
89 printf(
"If you want to get the error for a negative error code, you should use\n-- before the first error code to tell perror that there was no more options.\n\n");
90 printf(
"Usage: %s [OPTIONS] [ERRORCODE [ERRORCODE...]]\n",my_progname);
91 my_print_help(my_long_options);
92 my_print_variables(my_long_options);
97 get_one_option(
int optid,
const struct my_option *opt __attribute__((unused)),
98 char *argument __attribute__((unused)))
118 static int get_options(
int *argc,
char ***argv)
122 if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
134 static const char *get_ha_error_msg(
int code)
142 compile_time_assert(HA_ERR_FIRST + array_elements(handler_error_messages) ==
144 if (code >= HA_ERR_FIRST && code <= HA_ERR_LAST)
145 return handler_error_messages[code - HA_ERR_FIRST];
157 static st_error global_error_names[] =
159 #include <mysqld_ername.h>
170 int get_ER_error_msg(uint code,
const char **name_ptr,
const char **msg_ptr)
174 tmp_error= & global_error_names[0];
176 while (tmp_error->name != NULL)
178 if (tmp_error->code == code)
180 *name_ptr= tmp_error->name;
181 *msg_ptr= tmp_error->text;
191 static my_bool print_win_error_msg(DWORD error, my_bool verbose)
194 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
195 FORMAT_MESSAGE_FROM_SYSTEM,
196 NULL, error, 0, (LPTSTR)&s, 0,
200 printf(
"Win32 error code %d: %s", error, s);
218 static const char **get_handler_error_messages()
220 return handler_error_messages;
223 void my_handler_error_register(
void)
231 compile_time_assert(HA_ERR_FIRST + array_elements(handler_error_messages) ==
233 my_error_register(get_handler_error_messages, HA_ERR_FIRST,
234 HA_ERR_FIRST+ array_elements(handler_error_messages)-1);
238 void my_handler_error_unregister(
void)
240 my_error_unregister(HA_ERR_FIRST,
241 HA_ERR_FIRST+ array_elements(handler_error_messages)-1);
244 int main(
int argc,
char *argv[])
246 int error,code,found;
249 char *unknown_error = 0;
251 my_bool skip_win_message= 0;
255 if (get_options(&argc,&argv))
258 my_handler_error_register();
269 if ((msg= strerror(10000)) == NULL)
270 msg=
"Unknown Error";
276 unknown_error= malloc(strlen(msg)+1);
277 strmov(unknown_error, msg);
279 for ( ; argc-- > 0 ; argv++)
284 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
287 if ((ndb_error_string(code, ndb_string,
sizeof(ndb_string)) < 0) &&
288 (ndbd_exit_string(code, ndb_string,
sizeof(ndb_string)) < 0) &&
289 (mgmapi_error_string(code, ndb_string,
sizeof(ndb_string)) < 0))
298 printf(
"NDB error code %3d: %s\n",code,msg);
304 fprintf(stderr,
"Illegal ndb error code: %d\n",code);
312 msg = strerror(code);
320 my_strnncoll(&my_charset_latin1, (
const uchar*) msg, 13,
321 (
const uchar*)
"Unknown Error", 13) &&
322 (!unknown_error || strcmp(msg, unknown_error)))
326 printf(
"OS error code %3d: %s\n", code, msg);
330 if ((msg= get_ha_error_msg(code)))
334 printf(
"MySQL error code %3d: %s\n", code, msg);
338 if (get_ER_error_msg(code, & name, & msg))
342 printf(
"MySQL error code %3d (%s): %s\n", code, name, msg);
349 if (!(skip_win_message= !print_win_error_msg((DWORD)code, verbose)))
352 fprintf(stderr,
"Illegal error code: %d\n",code);
359 if (!skip_win_message)
360 print_win_error_msg((DWORD)code, verbose);