summaryrefslogtreecommitdiff
path: root/innobase
diff options
context:
space:
mode:
authormarko@hundin.mysql.fi <>2004-08-10 14:17:32 +0300
committermarko@hundin.mysql.fi <>2004-08-10 14:17:32 +0300
commitcd6292d21952e7087b2271801a5207dc63d20e9a (patch)
tree2aad048f3c55d299ccdafd72ffe71c2cf00dbb53 /innobase
parent3cb09c98176c794328e209996a26f13f6bc2010e (diff)
downloadmariadb-git-cd6292d21952e7087b2271801a5207dc63d20e9a.tar.gz
InnoDB: Use create_temp_file() when available
Diffstat (limited to 'innobase')
-rw-r--r--innobase/include/os0file.h4
-rw-r--r--innobase/os/os0file.c72
2 files changed, 54 insertions, 22 deletions
diff --git a/innobase/include/os0file.h b/innobase/include/os0file.h
index 4a8b9623eeb..9727c2b8243 100644
--- a/innobase/include/os0file.h
+++ b/innobase/include/os0file.h
@@ -134,12 +134,12 @@ void
os_io_init_simple(void);
/*===================*/
/***************************************************************************
-Creates a temporary file. In case of error, causes abnormal termination. */
+Creates a temporary file. */
FILE*
os_file_create_tmpfile(void);
/*========================*/
- /* out: temporary file handle, or NULL */
+ /* out: temporary file handle, or NULL on error */
/********************************************************************
A simple function to open or create a file. */
diff --git a/innobase/os/os0file.c b/innobase/os/os0file.c
index c33066b1476..63a86d8ab68 100644
--- a/innobase/os/os0file.c
+++ b/innobase/os/os0file.c
@@ -371,39 +371,71 @@ os_io_init_simple(void)
}
}
+#ifndef UNIV_HOTBACKUP
+/*************************************************************************
+Creates a temporary file. This function is defined in ha_innodb.cc. */
+
+int
+innobase_mysql_tmpfile(void);
+/*========================*/
+ /* out: temporary file descriptor, or < 0 on error */
+#endif /* !UNIV_HOTBACKUP */
+
/***************************************************************************
-Creates a temporary file. In case of error, causes abnormal termination. */
+Creates a temporary file. */
FILE*
os_file_create_tmpfile(void)
/*========================*/
- /* out: temporary file handle, or NULL */
+ /* out: temporary file handle, or NULL on error */
{
- FILE* file;
-#ifdef __WIN__
+ FILE* file = NULL;
int fd = -1;
- char* name;
- file = NULL;
- if (NULL == (name = tempnam(fil_path_to_mysql_datadir, "ib"))
- || -1 == (fd = _open(name, _O_CREAT | _O_EXCL | _O_RDWR
- | _O_SEQUENTIAL | _O_SHORT_LIVED | _O_TEMPORARY))
- || NULL == (file = fdopen(fd, "w+b"))) {
- ut_print_timestamp(stderr);
- fprintf(stderr, " InnoDB: Error: unable to create"
- " temporary file %s\n", name ? name : "name");
- if (fd != -1) {
- _close(fd);
+#ifdef UNIV_HOTBACKUP
+ int tries;
+ for (tries = 10; tries--; ) {
+ char* name = tempnam(fil_path_to_mysql_datadir, "ib");
+ if (!name) {
+ break;
+ }
+
+ fd = open(name,
+# ifdef __WIN__
+ O_SEQUENTIAL | O_SHORT_LIVED | O_TEMPORARY |
+# endif /* __WIN__ */
+ O_CREAT | O_EXCL | O_RDWR,
+ S_IREAD | S_IWRITE);
+ if (fd >= 0) {
+# ifndef __WIN__
+ unlink(name);
+# endif /* !__WIN__ */
+ free(name);
+ break;
}
+
+ ut_print_timestamp(stderr);
+ fprintf(stderr, " InnoDB: Warning: "
+ "unable to create temporary file %s, retrying\n",
+ name);
+ free(name);
}
- free(name);
-#else /* __WIN__ */
- file = tmpfile();
- if (file == NULL) {
+#else /* UNIV_HOTBACKUP */
+ fd = innobase_mysql_tmpfile();
+#endif /* UNIV_HOTBACKUP */
+
+ if (fd >= 0) {
+ file = fdopen(fd, "w+b");
+ }
+
+ if (!file) {
ut_print_timestamp(stderr);
fputs(" InnoDB: Error: unable to create temporary file\n",
stderr);
+ if (fd >= 0) {
+ close(fd);
+ }
}
-#endif /* __WIN__ */
+
return(file);
}