aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert2011-06-10 11:19:35 -0700
committerPaul Eggert2011-06-10 11:19:35 -0700
commite41e9a0e24877b0bc81e08df396f59115f8636da (patch)
treec0cf7e2838761b2c26047aeeac6415bb542bf5a0 /lib-src
parent6a54b501af0633c909c96de867c805222fde970c (diff)
parent529a133c390049085db38e7c8f745d650a2626ee (diff)
downloademacs-e41e9a0e24877b0bc81e08df396f59115f8636da.tar.gz
emacs-e41e9a0e24877b0bc81e08df396f59115f8636da.zip
Merge from trunk.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog10
-rw-r--r--lib-src/movemail.c35
2 files changed, 34 insertions, 11 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index ff0d3da0a80..ec123e85036 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,13 @@
12011-06-10 Paul Eggert <eggert@cs.ucla.edu>
2
3 * movemail.c: Fix race condition and related bugs (Bug#8836).
4 (main) [!MAIL_USE_SYSTEM_LOCK]: Prefer mkstemp to mktemp, as this
5 fixes some race conditions. Report mkstemp/mktemp errno rather
6 than a possibly-garbage errno. Reinitialize the template each
7 time through the loop, as earlier mkstemp/mktemp calls could have
8 trashed it. Pass 0600 (not 0666) to mktemp, for consistency
9 with mkstemp; the permissions don't matter anyway.
10
12011-06-01 Dan Nicolaescu <dann@ics.uci.edu> 112011-06-01 Dan Nicolaescu <dann@ics.uci.edu>
2 12
3 * emacsclient.c (socket_status): Use constant pointer. 13 * emacsclient.c (socket_status): Use constant pointer.
diff --git a/lib-src/movemail.c b/lib-src/movemail.c
index 4cf97cbac18..e8c09f090f3 100644
--- a/lib-src/movemail.c
+++ b/lib-src/movemail.c
@@ -168,8 +168,9 @@ main (int argc, char **argv)
168#ifndef MAIL_USE_SYSTEM_LOCK 168#ifndef MAIL_USE_SYSTEM_LOCK
169 struct stat st; 169 struct stat st;
170 int tem; 170 int tem;
171 char *lockname, *p; 171 char *lockname;
172 char *tempname; 172 char *tempname;
173 size_t inname_dirlen;
173 int desc; 174 int desc;
174#endif /* not MAIL_USE_SYSTEM_LOCK */ 175#endif /* not MAIL_USE_SYSTEM_LOCK */
175 176
@@ -298,26 +299,38 @@ main (int argc, char **argv)
298 to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */ 299 to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */
299 300
300 lockname = concat (inname, ".lock", ""); 301 lockname = concat (inname, ".lock", "");
301 tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1); 302 for (inname_dirlen = strlen (inname);
302 strcpy (tempname, inname); 303 inname_dirlen && !IS_DIRECTORY_SEP (inname[inname_dirlen - 1]);
303 p = tempname + strlen (tempname); 304 inname_dirlen--)
304 while (p != tempname && !IS_DIRECTORY_SEP (p[-1])) 305 continue;
305 p--; 306 tempname = (char *) xmalloc (inname_dirlen + sizeof "EXXXXXX");
306 *p = 0;
307 strcpy (p, "EXXXXXX");
308 mktemp (tempname);
309 unlink (tempname);
310 307
311 while (1) 308 while (1)
312 { 309 {
313 /* Create the lock file, but not under the lock file name. */ 310 /* Create the lock file, but not under the lock file name. */
314 /* Give up if cannot do that. */ 311 /* Give up if cannot do that. */
315 desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0666); 312
313 memcpy (tempname, inname, inname_dirlen);
314 strcpy (tempname + inname_dirlen, "EXXXXXX");
315#ifdef HAVE_MKSTEMP
316 desc = mkstemp (tempname);
317#else
318 mktemp (tempname);
319 if (!*tempname)
320 desc = -1;
321 else
322 {
323 unlink (tempname);
324 desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0600);
325 }
326#endif
316 if (desc < 0) 327 if (desc < 0)
317 { 328 {
329 int mkstemp_errno = errno;
318 char *message = (char *) xmalloc (strlen (tempname) + 50); 330 char *message = (char *) xmalloc (strlen (tempname) + 50);
319 sprintf (message, "creating %s, which would become the lock file", 331 sprintf (message, "creating %s, which would become the lock file",
320 tempname); 332 tempname);
333 errno = mkstemp_errno;
321 pfatal_with_name (message); 334 pfatal_with_name (message);
322 } 335 }
323 close (desc); 336 close (desc);