aboutsummaryrefslogtreecommitdiffstats
path: root/src/filelock.c
diff options
context:
space:
mode:
authorJoakim Verona2013-07-14 11:04:49 +0200
committerJoakim Verona2013-07-14 11:04:49 +0200
commit0bb9bb0841d89fff09820a57369df4cb01b16b43 (patch)
tree832bf9fa8415eef0ce464d22b3ee1300cfa90bb1 /src/filelock.c
parent3718127221fbbc31f8ebd027ab7c95403dbe9118 (diff)
parent3af1c8684ed6e48fbc21481d129e9aa164752c6e (diff)
downloademacs-0bb9bb0841d89fff09820a57369df4cb01b16b43.tar.gz
emacs-0bb9bb0841d89fff09820a57369df4cb01b16b43.zip
Merge branch 'trunk' into xwidget
Conflicts: src/xdisp.c
Diffstat (limited to 'src/filelock.c')
-rw-r--r--src/filelock.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/filelock.c b/src/filelock.c
index de6aba8385c..244663ad20a 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -47,6 +47,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
47#include "systime.h" 47#include "systime.h"
48#ifdef WINDOWSNT 48#ifdef WINDOWSNT
49#include <share.h> 49#include <share.h>
50#include <sys/socket.h> /* for fcntl */
50#include "w32.h" /* for dostounix_filename */ 51#include "w32.h" /* for dostounix_filename */
51#endif 52#endif
52 53
@@ -380,9 +381,9 @@ rename_lock_file (char const *old, char const *new, bool force)
380#endif 381#endif
381} 382}
382 383
383/* Create the lock file FILE with contents CONTENTS. Return 0 if 384/* Create the lock file LFNAME with contents LOCK_INFO_STR. Return 0 if
384 successful, an errno value on failure. If FORCE, remove any 385 successful, an errno value on failure. If FORCE, remove any
385 existing FILE if necessary. */ 386 existing LFNAME if necessary. */
386 387
387static int 388static int
388create_lock_file (char *lfname, char *lock_info_str, bool force) 389create_lock_file (char *lfname, char *lock_info_str, bool force)
@@ -416,8 +417,13 @@ create_lock_file (char *lfname, char *lock_info_str, bool force)
416 memcpy (nonce, lfname, lfdirlen); 417 memcpy (nonce, lfname, lfdirlen);
417 strcpy (nonce + lfdirlen, nonce_base); 418 strcpy (nonce + lfdirlen, nonce_base);
418 419
419#if HAVE_MKSTEMP 420#if HAVE_MKOSTEMP
420 /* Prefer mkstemp if available, as it avoids a race between 421 /* Prefer mkostemp to mkstemp, as it avoids a window where FD is
422 temporarily open without close-on-exec. */
423 fd = mkostemp (nonce, O_BINARY | O_CLOEXEC);
424 need_fchmod = 1;
425#elif HAVE_MKSTEMP
426 /* Prefer mkstemp to mktemp, as it avoids a race between
421 mktemp and emacs_open. */ 427 mktemp and emacs_open. */
422 fd = mkstemp (nonce); 428 fd = mkstemp (nonce);
423 need_fchmod = 1; 429 need_fchmod = 1;
@@ -432,7 +438,11 @@ create_lock_file (char *lfname, char *lock_info_str, bool force)
432 err = errno; 438 err = errno;
433 else 439 else
434 { 440 {
435 ptrdiff_t lock_info_len = strlen (lock_info_str); 441 ptrdiff_t lock_info_len;
442#if ! HAVE_MKOSTEMP
443 fcntl (fd, F_SETFD, FD_CLOEXEC);
444#endif
445 lock_info_len = strlen (lock_info_str);
436 err = 0; 446 err = 0;
437 if (emacs_write (fd, lock_info_str, lock_info_len) != lock_info_len 447 if (emacs_write (fd, lock_info_str, lock_info_len) != lock_info_len
438 || (need_fchmod && fchmod (fd, world_readable) != 0)) 448 || (need_fchmod && fchmod (fd, world_readable) != 0))