From 3d2a975f11b6937095efab28a5c7f5a895572499 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 3 Oct 2021 12:51:37 +0200 Subject: [PATCH] Fix issue with tempfile() returning EOPNOTSUPP on Azure Turns out O_TMPFILE can fail in interesting ways when the underlying filesystem doesn't support unnamed inodes, e.g. Azure used by GitHub Actions. Here's the exact qoute from open(2): "O_TMPFILE requires support by the underlying filesystem; only a subset of Linux filesystems provide that support. In the initial implementation, support was provided in the ext2, ext3, ext4, UDF, Minix, and shmem filesystems. Support for other filesystems has subsequently been added as follows: XFS (Linux 3.15); Btrfs (Linux 3.16); F2FS (Linux 3.16); and ubifs (Linux 4.9)" This patch adds a silent fallback to tmpfile() in these cases. Signed-off-by: Joachim Wiberg --- ChangeLog.md | 8 ++++++++ src/tempfile.c | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 515ed88..94e0e7c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,6 +4,14 @@ Change Log All notable changes to the project are documented in this file. +[v2.4.1][UNRELEASED] +----------------------- + +### Changes +### Fixes +- Fix issue with `tempfile()` returning EOPNOTSUPP on Azure + + [v2.4.0][] - 2021-03-27 ----------------------- diff --git a/src/tempfile.c b/src/tempfile.c index 422d542..4099cdf 100644 --- a/src/tempfile.c +++ b/src/tempfile.c @@ -15,6 +15,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #include #include /* O_TMPFILE requires -D_GNU_SOURCE */ #include /* fdopen() */ @@ -42,8 +43,12 @@ FILE *tempfile(void) oldmask = umask(0077); fd = open(_PATH_TMP, O_TMPFILE | O_RDWR | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR); umask(oldmask); - if (-1 == fd) + if (-1 == fd) { + if (errno == EOPNOTSUPP) + return tmpfile(); + return NULL; + } return fdopen(fd, "w+"); #else