Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux use O_TMPFILE for create_temp_file #244

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/my_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ enum file_type {
STREAM_BY_FOPEN,
STREAM_BY_FDOPEN,
FILE_BY_MKSTEMP,
FILE_BY_O_TMPFILE,
FILE_BY_DUP
};

Expand Down
26 changes: 26 additions & 0 deletions mysys/mf_tempfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,32 @@ File create_temp_file(char *to, const char *dir, const char *prefix,
}

#else /* mkstemp() is available on all non-Windows supported platforms. */
#ifdef O_TMPFILE
{
static int O_TMPFILE_works = 1;

if (O_TMPFILE_works)
{
/* explictly don't use O_EXCL here has it has a different
meaning with O_TMPFILE
*/
if ((file = open(dir, O_RDWR | O_TMPFILE | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)) >= 0)
{
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(0), dir);
O_TMPFILE_works= 0;
}
}
}
if (file == -1)
#endif /* O_TMPFILE */
{
char prefix_buff[30];
uint pfx_len;
Expand Down