summaryrefslogtreecommitdiff
path: root/mysys/mf_tempfile.c
diff options
context:
space:
mode:
authorDaniel Black <daniel@linux.ibm.com>2018-05-21 09:51:45 +1000
committerSergei Golubchik <serg@mariadb.org>2018-06-04 12:32:23 +0200
commit3edac3f18d2d74f68e6f9f9b41e5d05a5c8ca9c5 (patch)
treee8981d0eba8aacecd684f6715a147a22a97c233b /mysys/mf_tempfile.c
parentced66387734325304e0a3dc932ad709c125ccb50 (diff)
downloadmariadb-git-3edac3f18d2d74f68e6f9f9b41e5d05a5c8ca9c5.tar.gz
MDEV-15584 Linux use O_TMPFILE
O_TMPFILE creates a tempfile not attached to a filename. This is what we want for MY_TEMPORARY. We preserve a state O_TMPFILE_works, because kernel version or filesystem could cause failure. Closes #662
Diffstat (limited to 'mysys/mf_tempfile.c')
-rw-r--r--mysys/mf_tempfile.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/mysys/mf_tempfile.c b/mysys/mf_tempfile.c
index e6c19a25789..54b0d85b552 100644
--- a/mysys/mf_tempfile.c
+++ b/mysys/mf_tempfile.c
@@ -110,6 +110,33 @@ File create_temp_file(char *to, const char *dir, const char *prefix,
}
}
#elif defined(HAVE_MKSTEMP)
+#ifdef O_TMPFILE
+ {
+ static int O_TMPFILE_works= 1;
+
+ if ((MyFlags & MY_TEMPORARY) && O_TMPFILE_works)
+ {
+ /* explictly don't use O_EXCL here has it has a different
+ meaning with O_TMPFILE
+ */
+ if ((file= open(dir, mode | O_TMPFILE | O_CLOEXEC,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)) >= 0)
+ {
+ my_snprintf(to, FN_REFLEN, "%s/#sql/fd=%d", dir, file);
+ file=my_register_filename(file, to, FILE_BY_O_TMPFILE,
+ EE_CANTCREATEFILE, MyFlags);
+ }
+ else if (errno == EOPNOTSUPP || errno == EINVAL)
+ {
+ my_printf_error(EE_CANTCREATEFILE, "O_TMPFILE is not supported on %s "
+ "(disabling future attempts)",
+ MYF(ME_NOTE | ME_ERROR_LOG_ONLY), dir);
+ O_TMPFILE_works= 0;
+ }
+ }
+ }
+ if (file == -1)
+#endif /* O_TMPFILE */
{
char prefix_buff[30];
uint pfx_len;