Skip to content

Commit

Permalink
Do not unlink temporary file in the mkstemp test
Browse files Browse the repository at this point in the history
Do not unlink the file and then write to it in the mkstemp
replacement test suite, since this fails on some file systems. This
is not ideal since the calling program may be relying on traditional
UNIX file semantics, but it can be addressed by moving temporary
files to another file system and doesn't indicate a bug in the
replacement function. Thanks to Julien ÉLIE for the report.
  • Loading branch information
rra committed Feb 17, 2024
1 parent 9672b41 commit 8590568
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.d/20240217_092424_eagle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Bug fixes

- Do not unlink the file and then write to it in the mkstemp replacement test suite, since this fails on some file systems. This is not ideal since the calling program may be relying on traditional UNIX file semantics, but it can be addressed by moving temporary files to another file system and doesn't indicate a bug in the replacement function. Thanks to Julien ÉLIE for the report.
15 changes: 14 additions & 1 deletion tests/portable/mkstemp-t.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
* Copyright 2024 Russ Allbery <eagle@eyrie.org>
* Copyright 2009, 2011
* The Board of Trustees of the Leland Stanford Junior University
*
Expand Down Expand Up @@ -66,7 +67,18 @@ main(void)
ok(stat(template, &st1) == 0, "...and stat of template works");
ok(fstat(fd, &st2) == 0, "...and stat of open file descriptor works");
ok(st1.st_ino == st2.st_ino, "...and they're the same file");
unlink(template);

/*
* It should be possible to unlink the file at this point and continue to
* read and write to it as an unlinked file. However, this has been
* reported to fail on some systems with ESTALE, possibly because the home
* directory may have been mounted via NFS. (NFS normally deals with this
* by renaming the file, but that may have been disabled.) It's worrisome
* if one cannot continue to use a deleted file, but it's not testing
* anything in the mkstemp replacement, just UNIX open file semantics, so
* do not unlink the file early to avoid test failures that the user
* probably can't do anything about.
*/

/* Make sure the open mode is correct. */
length = strlen(template);
Expand All @@ -76,6 +88,7 @@ main(void)
buffer[length] = '\0';
is_string(template, buffer, "...and matches what we wrote");
close(fd);
unlink(template);

return 0;
}

0 comments on commit 8590568

Please sign in to comment.