Skip to content

Commit

Permalink
um: Use race-free temporary file creation
Browse files Browse the repository at this point in the history
Open the memory mapped file with the O_TMPFILE flag when available.

Signed-off-by: Mickaël Salaün <mic@digikod.net>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Acked-by: Tristan Schmelcher <tschmelcher@google.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
  • Loading branch information
Mickaël Salaün authored and Richard Weinberger committed Jan 10, 2016
1 parent 571d2f0 commit 3e46b25
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions arch/um/os-Linux/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ static int __init make_tempfile(const char *template)
}
}

#ifdef O_TMPFILE
fd = open(tempdir, O_CLOEXEC | O_RDWR | O_EXCL | O_TMPFILE, 0700);
/*
* If the running system does not support O_TMPFILE flag then retry
* without it.
*/
if (fd != -1 || (errno != EINVAL && errno != EISDIR &&
errno != EOPNOTSUPP))
return fd;
#endif

tempname = malloc(strlen(tempdir) + strlen(template) + 1);
if (tempname == NULL)
return -1;
Expand Down

0 comments on commit 3e46b25

Please sign in to comment.