aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog7
-rw-r--r--src/callproc.c14
-rw-r--r--src/filelock.c18
3 files changed, 10 insertions, 29 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index c29c4c8da59..f8f2fa47089 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
12013-08-04 Paul Eggert <eggert@cs.ucla.edu>
2
3 Fix some minor races in hosts lacking mkostemp (Bug#15015).
4 * callproc.c (create_temp_file):
5 * filelock.c (create_lock_file):
6 Assume mkostemp, since it's now provided by Gnulib.
7
12013-08-04 Eli Zaretskii <eliz@gnu.org> 82013-08-04 Eli Zaretskii <eliz@gnu.org>
2 9
3 * w32.c (mkostemp): New function. 10 * w32.c (mkostemp): New function.
diff --git a/src/callproc.c b/src/callproc.c
index 450fc57f929..54bc5cd9dc0 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1009,23 +1009,11 @@ create_temp_file (ptrdiff_t nargs, Lisp_Object *args)
1009 tempfile = SSDATA (filename_string); 1009 tempfile = SSDATA (filename_string);
1010 1010
1011 { 1011 {
1012 int fd; 1012 int fd = mkostemp (tempfile, O_CLOEXEC);
1013
1014#ifdef HAVE_MKOSTEMP
1015 fd = mkostemp (tempfile, O_CLOEXEC);
1016#elif defined HAVE_MKSTEMP
1017 fd = mkstemp (tempfile);
1018#else
1019 errno = EEXIST;
1020 mktemp (tempfile);
1021 fd = *tempfile ? 0 : -1;
1022#endif
1023 if (fd < 0) 1013 if (fd < 0)
1024 report_file_error ("Failed to open temporary file using pattern", 1014 report_file_error ("Failed to open temporary file using pattern",
1025 pattern); 1015 pattern);
1026#if defined HAVE_MKOSTEMP || defined HAVE_MKSTEMP
1027 emacs_close (fd); 1016 emacs_close (fd);
1028#endif
1029 } 1017 }
1030 1018
1031 record_unwind_protect (delete_temp_file, filename_string); 1019 record_unwind_protect (delete_temp_file, filename_string);
diff --git a/src/filelock.c b/src/filelock.c
index b9c991e4baf..0f31b7d4deb 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -411,28 +411,14 @@ create_lock_file (char *lfname, char *lock_info_str, bool force)
411 memcpy (nonce, lfname, lfdirlen); 411 memcpy (nonce, lfname, lfdirlen);
412 strcpy (nonce + lfdirlen, nonce_base); 412 strcpy (nonce + lfdirlen, nonce_base);
413 413
414#if HAVE_MKOSTEMP
415 /* Prefer mkostemp to mkstemp, as it avoids a window where FD is
416 temporarily open without close-on-exec. */
417 fd = mkostemp (nonce, O_BINARY | O_CLOEXEC); 414 fd = mkostemp (nonce, O_BINARY | O_CLOEXEC);
418#elif HAVE_MKSTEMP
419 /* Prefer mkstemp to mktemp, as it avoids a race between
420 mktemp and emacs_open. */
421 fd = mkstemp (nonce);
422#else
423 mktemp (nonce);
424 fd = emacs_open (nonce, O_WRONLY | O_CREAT | O_EXCL | O_BINARY,
425 S_IRUSR | S_IWUSR);
426#endif
427
428 if (fd < 0) 415 if (fd < 0)
429 err = errno; 416 err = errno;
430 else 417 else
431 { 418 {
432 ptrdiff_t lock_info_len; 419 ptrdiff_t lock_info_len;
433#if ! (HAVE_MKOSTEMP && O_CLOEXEC) 420 if (! O_CLOEXEC)
434 fcntl (fd, F_SETFD, FD_CLOEXEC); 421 fcntl (fd, F_SETFD, FD_CLOEXEC);
435#endif
436 lock_info_len = strlen (lock_info_str); 422 lock_info_len = strlen (lock_info_str);
437 err = 0; 423 err = 0;
438 /* Use 'write', not 'emacs_write', as garbage collection 424 /* Use 'write', not 'emacs_write', as garbage collection