summaryrefslogtreecommitdiff
path: root/client/mysqltest.c
diff options
context:
space:
mode:
authorunknown <msvensson@shellback.(none)>2007-08-08 16:45:18 +0200
committerunknown <msvensson@shellback.(none)>2007-08-08 16:45:18 +0200
commitc48a3d7943edd420da6314c389e9501a85331d49 (patch)
tree9ee32597b56dccac98892143997d0056301e0a70 /client/mysqltest.c
parent5501f528f5a6f41f8e38cabbbd2d52fcb29993a6 (diff)
downloadmariadb-git-c48a3d7943edd420da6314c389e9501a85331d49.tar.gz
Use "create_temp_file" to create a temporary file name for the perl script
Diffstat (limited to 'client/mysqltest.c')
-rw-r--r--client/mysqltest.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c
index 541c0cb4394..543dabf52f0 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -2970,8 +2970,10 @@ void do_send_quit(struct st_command *command)
void do_perl(struct st_command *command)
{
int error;
- char buf[FN_REFLEN];
+ File fd;
FILE *res_file;
+ char buf[FN_REFLEN];
+ char temp_file_path[FN_REFLEN];
static DYNAMIC_STRING ds_script;
static DYNAMIC_STRING ds_delimiter;
const struct command_arg perl_args[] = {
@@ -2994,14 +2996,17 @@ void do_perl(struct st_command *command)
DBUG_PRINT("info", ("Executing perl: %s", ds_script.str));
- /* Format a name for a tmp .pl file that is unique for this process */
- my_snprintf(buf, sizeof(buf), "%s/tmp/tmp_%d.pl",
- getenv("MYSQLTEST_VARDIR"), getpid());
- str_to_file(buf, ds_script.str, ds_script.length);
+ /* Create temporary file name */
+ if ((fd= create_temp_file(temp_file_path, getenv("MYSQLTEST_VARDIR"),
+ "tmp", O_CREAT | O_SHARE | O_RDWR,
+ MYF(MY_WME))) < 0)
+ die("Failed to create temporary file for perl command");
+ my_close(fd, MYF(0));
+
+ str_to_file(temp_file_path, ds_script.str, ds_script.length);
- /* Format the perl <filename> command */
- my_snprintf(buf, sizeof(buf), "perl %s/tmp/tmp_%d.pl",
- getenv("MYSQLTEST_VARDIR"), getpid());
+ /* Format the "perl <filename>" command */
+ my_snprintf(buf, sizeof(buf), "perl %s", temp_file_path);
if (!(res_file= popen(buf, "r")) && command->abort_on_error)
die("popen(\"%s\", \"r\") failed", buf);
@@ -3019,6 +3024,10 @@ void do_perl(struct st_command *command)
}
}
error= pclose(res_file);
+
+ /* Remove the temporary file */
+ my_delete(temp_file_path, MYF(0));
+
handle_command_error(command, WEXITSTATUS(error));
dynstr_free(&ds_script);
dynstr_free(&ds_delimiter);