* src/posixos.c (os_anontmp): If O_TMPFILE fails try dup() method.

This commit is contained in:
Dmitry Goncharov 2022-10-23 15:45:42 -04:00 committed by Paul Smith
parent 6f8da5f4b8
commit 252c26bd20

View file

@ -839,17 +839,22 @@ fd_set_append (int fd)
int int
os_anontmp () os_anontmp ()
{ {
const char *tdir = get_tmpdir ();
int fd = -1; int fd = -1;
#ifdef O_TMPFILE #ifdef O_TMPFILE
EINTRLOOP (fd, open (get_tmpdir (), O_RDWR | O_TMPFILE | O_EXCL, 0600)); EINTRLOOP (fd, open (tdir, O_RDWR | O_TMPFILE | O_EXCL, 0600));
if (fd < 0) if (fd >= 0)
pfatal_with_name ("open(O_TMPFILE)"); return fd;
#elif HAVE_DUP
/* We don't have O_TMPFILE but we can dup: if we are creating temp files in DB (DB_BASIC, (_("Cannot open '%s' with O_TMPFILE: %s.\n"),
the default location then try tmpfile() + dup() + fclose() to avoid ever tdir, strerror (errno)));
having a name for a file. */ #endif
if (streq (get_tmpdir (), DEFAULT_TMPDIR))
#if HAVE_DUP
/* If we can dup and we are creating temp files in the default location then
try tmpfile() + dup() + fclose() to avoid ever having a named file. */
if (streq (tdir, DEFAULT_TMPDIR))
{ {
mode_t mask = umask (0077); mode_t mask = umask (0077);
FILE *tfile; FILE *tfile;