summaryrefslogtreecommitdiffstats
path: root/tempfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'tempfile.c')
-rw-r--r--tempfile.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/tempfile.c b/tempfile.c
index 0af7ebf01..2990c9242 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -120,7 +120,12 @@ int create_tempfile(struct tempfile *tempfile, const char *path)
prepare_tempfile_object(tempfile);
strbuf_add_absolute_path(&tempfile->filename, path);
- tempfile->fd = open(tempfile->filename.buf, O_RDWR | O_CREAT | O_EXCL, 0666);
+ tempfile->fd = open(tempfile->filename.buf,
+ O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, 0666);
+ if (O_CLOEXEC && tempfile->fd < 0 && errno == EINVAL)
+ /* Try again w/o O_CLOEXEC: the kernel might not support it */
+ tempfile->fd = open(tempfile->filename.buf,
+ O_RDWR | O_CREAT | O_EXCL, 0666);
if (tempfile->fd < 0) {
strbuf_reset(&tempfile->filename);
return -1;