diff options
author | Vladislav Vaintroub <wlad@mariadb.com> | 2016-10-26 21:38:58 +0000 |
---|---|---|
committer | Vladislav Vaintroub <wlad@mariadb.com> | 2016-10-27 19:45:44 +0000 |
commit | aec43216c834c2156e9aca7b7dc182fbdd1916de (patch) | |
tree | 88f187e926ba560e82ecdb7e03d0c1a7a7f167ed | |
parent | 6e257274d98843b228e5bd08da74031f6f3a202d (diff) | |
download | mariadb-git-aec43216c834c2156e9aca7b7dc182fbdd1916de.tar.gz |
MDEV-9409 Windows - workaround VS2015 CRT bug that makes
mysqldump/mysql_install_db.exe fail
The bug is described in
https://connect.microsoft.com/VisualStudio/Feedback/Details/1902345
When reading from a pipe in text mode, using CRT function such as fread(),
some newlines may be lost. Workaround is to use binary mode on reading side
and if necessary, replace \r\n with \n.
-rw-r--r-- | client/mysqltest.cc | 28 | ||||
-rw-r--r-- | sql/mysqld.cc | 6 |
2 files changed, 28 insertions, 6 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc index acb9e8b1e0c..5daa0e72270 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -1705,11 +1705,11 @@ int cat_file(DYNAMIC_STRING* ds, const char* filename) while((len= my_read(fd, (uchar*)&buff, sizeof(buff)-1, MYF(0))) > 0) { - char *p= buff, *start= buff; - while (p < buff+len) + char *p= buff, *start= buff,*end=buff+len; + while (p < end) { /* Convert cr/lf to lf */ - if (*p == '\r' && *(p+1) && *(p+1)== '\n') + if (*p == '\r' && p+1 < end && *(p+1)== '\n') { /* Add fake newline instead of cr and output the line */ *p= '\n'; @@ -3367,16 +3367,32 @@ void do_exec(struct st_command *command) ds_result= &ds_sorted; } +#ifdef _WIN32 + /* Workaround for CRT bug, MDEV-9409 */ + _setmode(fileno(res_file), O_BINARY); +#endif + while (fgets(buf, sizeof(buf), res_file)) { + int len = (int)strlen(buf); +#ifdef _WIN32 + /* Strip '\r' off newlines. */ + if (len > 1 && buf[len-2] == '\r' && buf[len-1] == '\n') + { + buf[len-2] = '\n'; + buf[len-1] = 0; + len--; + } +#endif if (disable_result_log) { - buf[strlen(buf)-1]=0; + if (len) + buf[len-1] = 0; DBUG_PRINT("exec_result",("%s", buf)); } else { - replace_dynstr_append(ds_result, buf); + replace_dynstr_append_mem(ds_result, buf, len); } } error= pclose(res_file); @@ -5200,7 +5216,7 @@ typedef struct static st_error global_error_names[] = { - { "<No error>", -1U, "" }, + { "<No error>", ~0U, "" }, #include <mysqld_ername.h> { 0, 0, 0 } }; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index be9e21d6746..8eb92cafc03 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4949,6 +4949,12 @@ int mysqld_main(int argc, char **argv) setbuf(stderr, NULL); FreeConsole(); // Remove window } + + if (fileno(stdin) >= 0) + { + /* Disable CRLF translation (MDEV-9409). */ + _setmode(fileno(stdin), O_BINARY); + } #endif /* |