diff options
author | Sergei Golubchik <sergii@pisem.net> | 2012-03-21 18:30:34 +0100 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2012-03-21 18:30:34 +0100 |
commit | c88e2679c60f56719b6d347c30374e69ffd3d5c4 (patch) | |
tree | 93dfaefc07a8589710c137c01c3e2ea1af9024e5 | |
parent | e638e605895fb572047ec8027e91c5438d77cbf4 (diff) | |
parent | d1f311799988266159310afce3cf19eaf58a1fa5 (diff) | |
download | mariadb-git-c88e2679c60f56719b6d347c30374e69ffd3d5c4.tar.gz |
merge
-rw-r--r-- | include/my_global.h | 4 | ||||
-rw-r--r-- | include/my_stacktrace.h | 44 | ||||
-rw-r--r-- | mysys/stacktrace.c | 194 | ||||
-rw-r--r-- | sql/signal_handler.cc | 2 | ||||
-rw-r--r-- | sql/sql_show.cc | 2 | ||||
-rw-r--r-- | storage/innobase/os/os0file.c | 2 | ||||
-rw-r--r-- | storage/xtradb/os/os0file.c | 2 |
7 files changed, 17 insertions, 233 deletions
diff --git a/include/my_global.h b/include/my_global.h index 58147f85ee3..105a346a69f 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -569,6 +569,10 @@ int __void__; #endif #endif /* DONT_DEFINE_VOID */ +#ifndef STDERR_FILENO +#define STDERR_FILENO 2 +#endif + /* Deprecated workaround for false-positive uninitialized variables warnings. Those should be silenced using tool-specific heuristics. diff --git a/include/my_stacktrace.h b/include/my_stacktrace.h index a2fd89852fc..7585f00da90 100644 --- a/include/my_stacktrace.h +++ b/include/my_stacktrace.h @@ -61,50 +61,6 @@ void my_set_exception_pointers(EXCEPTION_POINTERS *ep); void my_write_core(int sig); #endif - - -/** - Async-signal-safe utility functions used by signal handler routines. - Declared here in order to unit-test them. - These are not general-purpose, but tailored to the signal handling routines. -*/ -/** - Converts a longlong value to string. - @param base 10 for decimal, 16 for hex values (0..9a..f) - @param val The value to convert - @param buf Assumed to point to the *end* of the buffer. - @returns Pointer to the first character of the converted string. - Negative values: - for base-10 the return string will be prepended with '-' - for base-16 the return string will contain 16 characters - Implemented with simplicity, and async-signal-safety in mind. -*/ -char *my_safe_itoa(int base, longlong val, char *buf); - -/** - Converts a ulonglong value to string. - @param base 10 for decimal, 16 for hex values (0..9a..f) - @param val The value to convert - @param buf Assumed to point to the *end* of the buffer. - @returns Pointer to the first character of the converted string. - Implemented with simplicity, and async-signal-safety in mind. -*/ -char *my_safe_utoa(int base, ulonglong val, char *buf); - -/** - A (very) limited version of snprintf. - @param to Destination buffer. - @param n Size of destination buffer. - @param fmt printf() style format string. - @returns Number of bytes written, including terminating '\0' - Supports 'd' 'i' 'u' 'x' 'p' 's' conversion. - Supports 'l' and 'll' modifiers for integral types. - Does not support any width/precision. - Implemented with simplicity, and async-signal-safety in mind. -*/ -size_t my_safe_snprintf(char* to, size_t n, const char* fmt, ...) - ATTRIBUTE_FORMAT(printf, 3, 4); - /** A (very) limited version of snprintf, which writes the result to STDERR. @sa my_safe_snprintf diff --git a/mysys/stacktrace.c b/mysys/stacktrace.c index c59be6b1f48..2ec526f2535 100644 --- a/mysys/stacktrace.c +++ b/mysys/stacktrace.c @@ -685,7 +685,7 @@ void my_print_stacktrace(uchar* unused1, ulong unused2) &(package.sym)); have_source= pSymGetLineFromAddr64(hProcess, addr, &line_offset, &line); - fprintf(stderr,"%p ", addr); + my_safe_printf_stderr("%p ", addr); if(have_module) { char *base_image_name= strrchr(module.ImageName, '\\'); @@ -693,12 +693,13 @@ void my_print_stacktrace(uchar* unused1, ulong unused2) base_image_name++; else base_image_name= module.ImageName; - fprintf(stderr,"%s!", base_image_name); + my_safe_printf_stderr("%s!", base_image_name); } if(have_symbol) - fprintf(stderr, "%s()", package.sym.Name); + my_safe_printf_stderr("%s()", package.sym.Name); + else if(have_module) - fprintf(stderr,"%s", "???"); + my_safe_printf_stderr("%s", "???"); if(have_source) { @@ -707,10 +708,10 @@ void my_print_stacktrace(uchar* unused1, ulong unused2) base_file_name++; else base_file_name= line.FileName; - fprintf(stderr, "[%s:%u]", + my_safe_printf_stderr("[%s:%u]", base_file_name, line.LineNumber); } - fprintf(stderr,"%s", "\n"); + my_safe_printf_stderr("%s", "\n"); } } @@ -781,189 +782,10 @@ void my_safe_print_str(const char *val, int len) #endif /*__WIN__*/ -#ifdef __WIN__ -size_t my_write_stderr(const void *buf, size_t count) -{ - return fwrite(buf, 1, count, stderr); -} -#else size_t my_write_stderr(const void *buf, size_t count) { return (size_t) write(STDERR_FILENO, buf, count); } -#endif - - -static const char digits[]= "0123456789abcdef"; - -char *my_safe_utoa(int base, ulonglong val, char *buf) -{ - *buf--= 0; - do { - *buf--= digits[val % base]; - } while ((val /= base) != 0); - return buf + 1; -} - - -char *my_safe_itoa(int base, longlong val, char *buf) -{ - char *orig_buf= buf; - const my_bool is_neg= (val < 0); - *buf--= 0; - - if (is_neg) - val= -val; - if (is_neg && base == 16) - { - int ix; - val-= 1; - for (ix= 0; ix < 16; ++ix) - buf[-ix]= '0'; - } - - do { - *buf--= digits[val % base]; - } while ((val /= base) != 0); - - if (is_neg && base == 10) - *buf--= '-'; - - if (is_neg && base == 16) - { - int ix; - buf= orig_buf - 1; - for (ix= 0; ix < 16; ++ix, --buf) - { - switch (*buf) - { - case '0': *buf= 'f'; break; - case '1': *buf= 'e'; break; - case '2': *buf= 'd'; break; - case '3': *buf= 'c'; break; - case '4': *buf= 'b'; break; - case '5': *buf= 'a'; break; - case '6': *buf= '9'; break; - case '7': *buf= '8'; break; - case '8': *buf= '7'; break; - case '9': *buf= '6'; break; - case 'a': *buf= '5'; break; - case 'b': *buf= '4'; break; - case 'c': *buf= '3'; break; - case 'd': *buf= '2'; break; - case 'e': *buf= '1'; break; - case 'f': *buf= '0'; break; - } - } - } - return buf+1; -} - - -static const char *check_longlong(const char *fmt, my_bool *have_longlong) -{ - *have_longlong= FALSE; - if (*fmt == 'l') - { - fmt++; - if (*fmt != 'l') - *have_longlong= (sizeof(long) == sizeof(longlong)); - else - { - fmt++; - *have_longlong= TRUE; - } - } - return fmt; -} - -static size_t my_safe_vsnprintf(char *to, size_t size, - const char* format, va_list ap) -{ - char *start= to; - char *end= start + size - 1; - for (; *format; ++format) - { - my_bool have_longlong = FALSE; - if (*format != '%') - { - if (to == end) /* end of buffer */ - break; - *to++= *format; /* copy ordinary char */ - continue; - } - ++format; /* skip '%' */ - - format= check_longlong(format, &have_longlong); - - switch (*format) - { - case 'd': - case 'i': - case 'u': - case 'x': - case 'p': - { - longlong ival= 0; - ulonglong uval = 0; - if (*format == 'p') - have_longlong= (sizeof(void *) == sizeof(longlong)); - if (have_longlong) - { - if (*format == 'u') - uval= va_arg(ap, ulonglong); - else - ival= va_arg(ap, longlong); - } - else - { - if (*format == 'u') - uval= va_arg(ap, unsigned int); - else - ival= va_arg(ap, int); - } - - { - char buff[22]; - const int base= (*format == 'x' || *format == 'p') ? 16 : 10; - char *val_as_str= (*format == 'u') ? - my_safe_utoa(base, uval, &buff[sizeof(buff)-1]) : - my_safe_itoa(base, ival, &buff[sizeof(buff)-1]); - - /* Strip off "ffffffff" if we have 'x' format without 'll' */ - if (*format == 'x' && !have_longlong && ival < 0) - val_as_str+= 8; - - while (*val_as_str && to < end) - *to++= *val_as_str++; - continue; - } - } - case 's': - { - const char *val= va_arg(ap, char*); - if (!val) - val= "(null)"; - while (*val && to < end) - *to++= *val++; - continue; - } - } - } - *to= 0; - return to - start; -} - - -size_t my_safe_snprintf(char* to, size_t n, const char* fmt, ...) -{ - size_t result; - va_list args; - va_start(args,fmt); - result= my_safe_vsnprintf(to, n, fmt, args); - va_end(args); - return result; -} size_t my_safe_printf_stderr(const char* fmt, ...) @@ -972,7 +794,7 @@ size_t my_safe_printf_stderr(const char* fmt, ...) size_t result; va_list args; va_start(args,fmt); - result= my_safe_vsnprintf(to, sizeof(to), fmt, args); + result= vsnprintf(to, sizeof(to), fmt, args); va_end(args); my_write_stderr(to, result); return result; diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc index 3847b7a5f6d..8128dddc7ee 100644 --- a/sql/signal_handler.cc +++ b/sql/signal_handler.cc @@ -72,7 +72,7 @@ extern "C" sig_handler handle_fatal_signal(int sig) curr_time= my_time(0); localtime_r(&curr_time, &tm); - fprintf(stderr, "%02d%02d%02d %2d:%02d:%02d ", + my_safe_printf_stderr("%02d%02d%02d %2d:%02d:%02d ", tm.tm_year % 100, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); if (opt_expect_abort diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 5bbc337c761..6811af83d49 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -6741,6 +6741,8 @@ bool get_schema_tables_result(JOIN *join, join->error= 1; tab->read_record.file= table_list->table->file; table_list->schema_table_state= executed_place; + if (!thd->is_error()) + my_error(ER_UNKNOWN_ERROR, MYF(0)); break; } tab->read_record.file= table_list->table->file; diff --git a/storage/innobase/os/os0file.c b/storage/innobase/os/os0file.c index 566c50381e7..4913f23ef67 100644 --- a/storage/innobase/os/os0file.c +++ b/storage/innobase/os/os0file.c @@ -2556,7 +2556,7 @@ retry: "InnoDB: Check also that the disk is not full" " or a disk quota exceeded.\n", name, (ulong) offset_high, (ulong) offset, - (ulong) n, (ulong) len, (ulong) err); + (ulong) n, ret ? len : 0, (ulong) err); if (strerror((int)err) != NULL) { fprintf(stderr, diff --git a/storage/xtradb/os/os0file.c b/storage/xtradb/os/os0file.c index 1e863109bed..b502be1eb00 100644 --- a/storage/xtradb/os/os0file.c +++ b/storage/xtradb/os/os0file.c @@ -2785,7 +2785,7 @@ retry: "InnoDB: Check also that the disk is not full" " or a disk quota exceeded.\n", name, (ulong) offset_high, (ulong) offset, - (ulong) n, (ulong) len, (ulong) err); + (ulong) n, ret ? len : 0, (ulong) err); if (strerror((int)err) != NULL) { fprintf(stderr, |