summaryrefslogtreecommitdiff
path: root/lib-src
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog9
-rw-r--r--lib-src/movemail.c17
-rw-r--r--lib-src/update-game-score.c12
3 files changed, 18 insertions, 20 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index f41c23df5d2..2cfe46f5352 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,12 @@
+2013-08-04 Paul Eggert <eggert@cs.ucla.edu>
+
+ Fix some minor races in hosts lacking mkostemp (Bug#15015).
+ * movemail.c (main):
+ * update-game-score.c (write_scores):
+ Use mkostemp (which now works on all platforms, due to changes
+ in the portability layer) rather than mktemp (which has a race)
+ or mkstemp (which we no longer bother with).
+
2013-07-10 Paul Eggert <eggert@cs.ucla.edu>
Port to C89.
diff --git a/lib-src/movemail.c b/lib-src/movemail.c
index 81ac8aa187c..9434782cb17 100644
--- a/lib-src/movemail.c
+++ b/lib-src/movemail.c
@@ -304,24 +304,13 @@ main (int argc, char **argv)
memcpy (tempname, inname, inname_dirlen);
strcpy (tempname + inname_dirlen, "EXXXXXX");
-#ifdef HAVE_MKSTEMP
- desc = mkstemp (tempname);
-#else
- mktemp (tempname);
- if (!*tempname)
- desc = -1;
- else
- {
- unlink (tempname);
- desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0600);
- }
-#endif
+ desc = mkostemp (tempname, 0);
if (desc < 0)
{
- int mkstemp_errno = errno;
+ int mkostemp_errno = errno;
error ("error while creating what would become the lock file",
0, 0);
- errno = mkstemp_errno;
+ errno = mkostemp_errno;
pfatal_with_name (tempname);
}
close (desc);
diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c
index ec8b4317770..1699e305c8d 100644
--- a/lib-src/update-game-score.c
+++ b/lib-src/update-game-score.c
@@ -383,6 +383,7 @@ sort_scores (struct score_entry *scores, int count, int reverse)
static int
write_scores (const char *filename, const struct score_entry *scores, int count)
{
+ int fd;
FILE *f;
int i;
char *tempfile = malloc (strlen (filename) + strlen (".tempXXXXXX") + 1);
@@ -390,12 +391,11 @@ write_scores (const char *filename, const struct score_entry *scores, int count)
return -1;
strcpy (tempfile, filename);
strcat (tempfile, ".tempXXXXXX");
-#ifdef HAVE_MKSTEMP
- if (mkstemp (tempfile) < 0
-#else
- if (mktemp (tempfile) != tempfile
-#endif
- || !(f = fopen (tempfile, "w")))
+ fd = mkostemp (tempfile, 0);
+ if (fd < 0)
+ return -1;
+ f = fdopen (fd, "w");
+ if (! f)
return -1;
for (i = 0; i < count; i++)
if (fprintf (f, "%ld %s %s\n", scores[i].score, scores[i].username,