all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 15015-done@debbugs.gnu.org
Subject: bug#15015: Fix some minor races in hosts lacking mkostemp
Date: Sun, 04 Aug 2013 10:01:42 -0700	[thread overview]
Message-ID: <51FE88F6.6000604@cs.ucla.edu> (raw)
In-Reply-To: <837gg1xxyf.fsf@gnu.org>

On 08/04/2013 08:44 AM, Eli Zaretskii wrote:
> So I went ahead and implemented mkostemp for MS-Windows (trunk
> revision 113687).  I also removed sys_mktemp, as it is no longer
> needed.

Thanks, that should do it on the Microsoft side.  I installed
the patch and am marking this done.  The patch I installed
also included the following additional simplification:

=== modified file 'ChangeLog'
--- ChangeLog	2013-08-04 01:23:59 +0000
+++ ChangeLog	2013-08-04 16:52:55 +0000
@@ -2,6 +2,9 @@
 
 	Fix some minor races in hosts lacking mkostemp (Bug#15015).
 	Gnulib's emulation of mkostemp doesn't have races that Emacs's does.
+	* configure.ac (mkostemp): Remove check for this function;
+	gnulib does the check now.
+	(mkstemp): Remove check for this no-longer-used function.
 	* lib/mkostemp.c, lib/secure_getenv.c, lib/tempname.c, lib/tempname.h:
 	* m4/mkostemp.m4, m4/secure_getenv.m4, m4/tempname.m4:
 	New files, copied from Gnulib.

=== modified file 'configure.ac'
--- configure.ac	2013-07-27 01:18:21 +0000
+++ configure.ac	2013-08-04 16:52:25 +0000
@@ -3277,7 +3277,7 @@
 getrlimit setrlimit shutdown getaddrinfo \
 strsignal setitimer \
 sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \
-gai_strerror mkostemp mkstemp getline getdelim sync \
+gai_strerror getline getdelim sync \
 difftime posix_memalign \
 getpwent endpwent getgrent endgrent \
 touchlock \

=== modified file 'lib-src/ChangeLog'
--- lib-src/ChangeLog	2013-07-10 23:23:57 +0000
+++ lib-src/ChangeLog	2013-08-04 16:48:02 +0000
@@ -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.

=== modified file 'lib-src/movemail.c'
--- lib-src/movemail.c	2013-03-13 18:42:22 +0000
+++ lib-src/movemail.c	2013-08-04 16:35:45 +0000
@@ -304,24 +304,13 @@
 
 	  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);

=== modified file 'lib-src/update-game-score.c'
--- lib-src/update-game-score.c	2013-03-30 17:00:51 +0000
+++ lib-src/update-game-score.c	2013-08-04 16:28:47 +0000
@@ -383,6 +383,7 @@
 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 @@
     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,







      reply	other threads:[~2013-08-04 17:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-03  7:40 bug#15015: Fix some minor races in hosts lacking mkostemp Paul Eggert
2013-08-03  8:38 ` Eli Zaretskii
2013-08-03  9:02   ` Eli Zaretskii
2013-08-03 14:40     ` Paul Eggert
2013-08-03 14:55       ` Eli Zaretskii
2013-08-03 21:26         ` Paul Eggert
2013-08-04 15:44           ` Eli Zaretskii
2013-08-04 17:01             ` Paul Eggert [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51FE88F6.6000604@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=15015-done@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.