cow, cache: Better mkostemp fallback
commit23d25996685ab71803dae02a8d3a98923486dfb5
authorEric Blake <eblake@redhat.com>
Wed, 31 Jul 2019 16:44:40 +0000 (31 11:44 -0500)
committerEric Blake <eblake@redhat.com>
Fri, 2 Aug 2019 20:47:38 +0000 (2 15:47 -0500)
treee018251d0979ea300d34eea8eb52eb4a8a7d94c6
parentcb01b787778877b778d7396febbc73f84f5182f3
cow, cache: Better mkostemp fallback

In 2018, we added fallbacks for Haiku lacking mkostemp (one of the
atomic CLOEXEC interfaces proposed for future POSIX [1]); however,
that fallback has minor bugs: if mkstemp() fails, we blindly call
fcntl(-1) (which probably changes the errno later reported against
"mkostemp: %s: %m"); and although it is historically unlikely that any
other bits will be set, F_SETFD should be used in a read-modify-write
pattern rather than a blind overwrite pattern.

[1] http://austingroupbugs.net/view.php?id=411

Update these fallbacks to use our newly-added set_cloexec utility
function; neither place needs atomicity because they occur during
.load (where we are still more-or-less single-threaded), rather than
while another thread may be actively inside a plugin (such as sh)
using fork().

Fixes: 60076fbcfd
Fixes: b962272a56
Signed-off-by: Eric Blake <eblake@redhat.com>
common/utils/utils.c
filters/cache/blk.c
filters/cow/blk.c