Commit 5c97beae authored by Paul Eggert's avatar Paul Eggert
Browse files

* filelock.c (create_lock_file) [!HAVE_MKOSTEMP && !HAVE_MKSTEMP]:

Simplify by making this case like the other two.  This is a bit
slower on obsolete hosts, but the extra complexity isn't worth it.
parent f6dd8b36
2013-07-14 Paul Eggert <eggert@cs.ucla.edu> 2013-07-14 Paul Eggert <eggert@cs.ucla.edu>
* filelock.c (create_lock_file) [!HAVE_MKOSTEMP && !HAVE_MKSTEMP]:
Simplify by making this case like the other two. This is a bit
slower on obsolete hosts, but the extra complexity isn't worth it.
* callproc.c (child_setup, relocate_fd) [!DOS_NT]: * callproc.c (child_setup, relocate_fd) [!DOS_NT]:
* process.c (create_process) [!DOS_NT]: * process.c (create_process) [!DOS_NT]:
Remove now-unnecessary calls to emacs_close. Remove now-unnecessary calls to emacs_close.
......
...@@ -412,8 +412,6 @@ create_lock_file (char *lfname, char *lock_info_str, bool force) ...@@ -412,8 +412,6 @@ create_lock_file (char *lfname, char *lock_info_str, bool force)
USE_SAFE_ALLOCA; USE_SAFE_ALLOCA;
char *nonce = SAFE_ALLOCA (lfdirlen + sizeof nonce_base); char *nonce = SAFE_ALLOCA (lfdirlen + sizeof nonce_base);
int fd; int fd;
bool need_fchmod;
mode_t world_readable = S_IRUSR | S_IRGRP | S_IROTH;
memcpy (nonce, lfname, lfdirlen); memcpy (nonce, lfname, lfdirlen);
strcpy (nonce + lfdirlen, nonce_base); strcpy (nonce + lfdirlen, nonce_base);
...@@ -421,17 +419,14 @@ create_lock_file (char *lfname, char *lock_info_str, bool force) ...@@ -421,17 +419,14 @@ create_lock_file (char *lfname, char *lock_info_str, bool force)
/* Prefer mkostemp to mkstemp, as it avoids a window where FD is /* Prefer mkostemp to mkstemp, as it avoids a window where FD is
temporarily open without close-on-exec. */ temporarily open without close-on-exec. */
fd = mkostemp (nonce, O_BINARY | O_CLOEXEC); fd = mkostemp (nonce, O_BINARY | O_CLOEXEC);
need_fchmod = 1;
#elif HAVE_MKSTEMP #elif HAVE_MKSTEMP
/* Prefer mkstemp to mktemp, as it avoids a race between /* Prefer mkstemp to mktemp, as it avoids a race between
mktemp and emacs_open. */ mktemp and emacs_open. */
fd = mkstemp (nonce); fd = mkstemp (nonce);
need_fchmod = 1;
#else #else
mktemp (nonce); mktemp (nonce);
fd = emacs_open (nonce, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, fd = emacs_open (nonce, O_WRONLY | O_CREAT | O_EXCL | O_BINARY,
world_readable); S_IRUSR | S_IWUSR);
need_fchmod = 0;
#endif #endif
if (fd < 0) if (fd < 0)
...@@ -445,7 +440,7 @@ create_lock_file (char *lfname, char *lock_info_str, bool force) ...@@ -445,7 +440,7 @@ create_lock_file (char *lfname, char *lock_info_str, bool force)
lock_info_len = strlen (lock_info_str); lock_info_len = strlen (lock_info_str);
err = 0; err = 0;
if (emacs_write (fd, lock_info_str, lock_info_len) != lock_info_len if (emacs_write (fd, lock_info_str, lock_info_len) != lock_info_len
|| (need_fchmod && fchmod (fd, world_readable) != 0)) || fchmod (fd, S_IRUSR | S_IRGRP | S_IROTH) != 0)
err = errno; err = errno;
/* There is no need to call fsync here, as the contents of /* There is no need to call fsync here, as the contents of
the lock file need not survive system crashes. */ the lock file need not survive system crashes. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment