From 4a311f0a50a7e8a18a046def80cae1928164dc19 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Mar 2006 22:05:39 +0100 Subject: Win fixes - Use tmp sh file both in system and popen client/mysqltest.c: Introduce common functions to handle unix emulation on windows using a temporary sh file. Use it both in my_popen and my_system. mysql-test/r/mysqltest.result: Update test result mysql-test/t/mysqltest.test: Fix "windows paths" in three places that doesn't automatically get fixed Uset the output file mysqltest.sql instead of con.sql as con is not an allowed filename on Windows Use system for util functions --- client/mysqltest.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'client/mysqltest.c') diff --git a/client/mysqltest.c b/client/mysqltest.c index 5836a109b6e..2486aab4c65 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -455,6 +455,7 @@ static void do_eval(DYNAMIC_STRING *query_eval, const char *query, static void str_to_file(const char *fname, char *str, int size); #ifdef __WIN__ +static void free_tmp_sh_file(); static void free_win_path_patterns(); #endif @@ -604,6 +605,7 @@ static void free_used_memory() mysql_server_end(); free_re(); #ifdef __WIN__ + free_tmp_sh_file(); free_win_path_patterns(); #endif DBUG_VOID_RETURN; @@ -1046,6 +1048,35 @@ int do_source(struct st_query *query) return open_file(name); } +//#ifdef __WIN__ +/* Variables used for temuprary sh files used for emulating Unix on Windows */ +char tmp_sh_name[64], tmp_sh_cmd[70]; + +static void init_tmp_sh_file() +{ + /* Format a name for the tmp sh file that is unique for this process */ + my_snprintf(tmp_sh_name, sizeof(tmp_sh_name), "tmp_%d.sh", getpid()); + /* Format the command to execute in order to run the script */ + my_snprintf(tmp_sh_cmd, sizeof(tmp_sh_cmd), "sh %s", tmp_sh_name); +} + +static void free_tmp_sh_file() +{ + my_delete(tmp_sh_name, MYF(0)); +} + + +FILE* my_popen(DYNAMIC_STRING* ds_cmd, const char* mode) +{ +#ifdef __WIN__ + /* Dump the command into a sh script file and execute with popen */ + str_to_file(tmp_sh_name, ds_cmd->str, ds_cmd->length); + return popen(tmp_sh_cmd, mode); +#else + return popen(ds_cmd->str, mode); +#endif +} + /* Execute given command. @@ -1092,7 +1123,7 @@ static void do_exec(struct st_query *query) DBUG_PRINT("info", ("Executing '%s' as '%s'", query->first_argument, cmd)); - if (!(res_file= popen(cmd, "r")) && query->abort_on_error) + if (!(res_file= my_popen(&ds_cmd, "r")) && query->abort_on_error) die("popen(\"%s\", \"r\") failed", query->first_argument); while (fgets(buf, sizeof(buf), res_file)) @@ -1365,15 +1396,9 @@ int do_modify_var(struct st_query *query, const char *name, int my_system(DYNAMIC_STRING* ds_cmd) { #ifdef __WIN__ - /* Dump the command into a sh script file and execute with "sh" */ - int err; - char tmp_sh_name[64], tmp_sh_cmd[70]; - my_snprintf(tmp_sh_name, sizeof(tmp_sh_name), "tmp_%d.sh", getpid()); - my_snprintf(tmp_sh_cmd, sizeof(tmp_sh_cmd), "sh %s", tmp_sh_name); + /* Dump the command into a sh script file and execute with system */ str_to_file(tmp_sh_name, ds_cmd->str, ds_cmd->length); - err= system(tmp_sh_cmd); - my_delete(tmp_sh_name, MYF(0)); - return err; + return system(tmp_sh_cmd); #else return system(ds_cmd->str); #endif -- cgit v1.2.1 From 187f89a443d25312d8d83c719dfbe9612827abf6 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Mar 2006 22:08:34 +0100 Subject: Remove unused var Reduce code client/mysqltest.c: Remove the "cmd" variable in do_sleep, left unintentionaly after merge Implement the same elegeant solution to fund the command name in do_modify_ar --- client/mysqltest.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'client/mysqltest.c') diff --git a/client/mysqltest.c b/client/mysqltest.c index 2486aab4c65..d37f60959d0 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1346,7 +1346,6 @@ enum enum_operator SYNOPSIS do_modify_var() query called command - name human readable name of operator operator operation to perform on the var DESCRIPTION @@ -1355,15 +1354,16 @@ enum enum_operator */ -int do_modify_var(struct st_query *query, const char *name, +int do_modify_var(struct st_query *query, enum enum_operator operator) { const char *p= query->first_argument; VAR* v; if (!*p) - die("Missing arguments to %s", name); + die("Missing argument to %.*s", query->first_word_len, query->query); if (*p != '$') - die("First argument to %s must be a variable (start with $)", name); + die("First argument to %.*s must be a variable (start with $)", + query->first_word_len, query->query); v= var_get(p, &p, 1, 0); switch (operator) { case DO_DEC: @@ -1697,7 +1697,6 @@ int do_sleep(struct st_query *query, my_bool real_sleep) char *p= query->first_argument; char *sleep_start, *sleep_end= query->end; double sleep_val; - const char *cmd = (real_sleep ? "real_sleep" : "sleep"); while (my_isspace(charset_info, *p)) p++; @@ -4617,8 +4616,8 @@ int main(int argc, char **argv) case Q_SERVER_START: do_server_start(q); break; case Q_SERVER_STOP: do_server_stop(q); break; #endif - case Q_INC: do_modify_var(q, "inc", DO_INC); break; - case Q_DEC: do_modify_var(q, "dec", DO_DEC); break; + case Q_INC: do_modify_var(q, DO_INC); break; + case Q_DEC: do_modify_var(q, DO_DEC); break; case Q_ECHO: do_echo(q); query_executed= 1; break; case Q_SYSTEM: do_system(q); break; case Q_DELIMITER: -- cgit v1.2.1 From 01a35c19cb81aa31934af62d4217bfcfe2bb6dd1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Mar 2006 22:18:04 +0100 Subject: Fix typo client/mysqltest.c: Fix typo, add extra "s" --- client/mysqltest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'client/mysqltest.c') diff --git a/client/mysqltest.c b/client/mysqltest.c index d37f60959d0..09072d430f9 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1360,7 +1360,7 @@ int do_modify_var(struct st_query *query, const char *p= query->first_argument; VAR* v; if (!*p) - die("Missing argument to %.*s", query->first_word_len, query->query); + die("Missing arguments to %.*s", query->first_word_len, query->query); if (*p != '$') die("First argument to %.*s must be a variable (start with $)", query->first_word_len, query->query); -- cgit v1.2.1 From 60ee2bbecb795abba4e19aca3908a3ea01932025 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Mar 2006 07:50:04 +0100 Subject: Improve error message for faulty usage of "inc" and "dec" client/mysqltest.c: Improve error messages for "inc" and "dec" mysql-test/r/mysqltest.result: Update test result --- client/mysqltest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'client/mysqltest.c') diff --git a/client/mysqltest.c b/client/mysqltest.c index 09072d430f9..05304c1dd6d 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1360,9 +1360,9 @@ int do_modify_var(struct st_query *query, const char *p= query->first_argument; VAR* v; if (!*p) - die("Missing arguments to %.*s", query->first_word_len, query->query); + die("Missing argument to %.*s", query->first_word_len, query->query); if (*p != '$') - die("First argument to %.*s must be a variable (start with $)", + die("The argument to %.*s must be a variable (start with $)", query->first_word_len, query->query); v= var_get(p, &p, 1, 0); switch (operator) { @@ -1373,7 +1373,7 @@ int do_modify_var(struct st_query *query, v->int_val++; break; default: - die("Invalid operator to do_operator"); + die("Invalid operator to do_modify_var"); break; } v->int_dirty= 1; -- cgit v1.2.1 From 07d36fb99a4b9419f60d4c09efc7e6c3fde0051c Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Mar 2006 08:57:57 +0100 Subject: Enable ifdef for windows specific functions --- client/mysqltest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'client/mysqltest.c') diff --git a/client/mysqltest.c b/client/mysqltest.c index 05304c1dd6d..770ca7e2d2a 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1048,7 +1048,7 @@ int do_source(struct st_query *query) return open_file(name); } -//#ifdef __WIN__ +#ifdef __WIN__ /* Variables used for temuprary sh files used for emulating Unix on Windows */ char tmp_sh_name[64], tmp_sh_cmd[70]; @@ -1064,7 +1064,7 @@ static void free_tmp_sh_file() { my_delete(tmp_sh_name, MYF(0)); } - +#endif FILE* my_popen(DYNAMIC_STRING* ds_cmd, const char* mode) { -- cgit v1.2.1 From f4c81a219a8842f9bb46fa79e5e5ff652b244850 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Mar 2006 14:34:20 +0100 Subject: Fix missing call to init_tmp_sh_file client/mysqltest.c: Add call to init_tmp_sh_file --- client/mysqltest.c | 1 + 1 file changed, 1 insertion(+) (limited to 'client/mysqltest.c') diff --git a/client/mysqltest.c b/client/mysqltest.c index 770ca7e2d2a..468b75c927f 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -4563,6 +4563,7 @@ int main(int argc, char **argv) init_var_hash(&cur_con->mysql); #ifdef __WIN__ + init_tmp_sh_file(); init_win_path_patterns(); #endif -- cgit v1.2.1