diff options
| author | Paul Eggert | 2013-07-14 16:12:42 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-07-14 16:12:42 -0700 |
| commit | 5c97beae62104207d0c9099919c7955c8e6f57fd (patch) | |
| tree | dcbd4cc2889125cc2b9889bb3cbfd86abe532e61 /src | |
| parent | f6dd8b3647e7c0d32fc142a77cc6ad4c18deb916 (diff) | |
| download | emacs-5c97beae62104207d0c9099919c7955c8e6f57fd.tar.gz emacs-5c97beae62104207d0c9099919c7955c8e6f57fd.zip | |
* 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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 4 | ||||
| -rw-r--r-- | src/filelock.c | 9 |
2 files changed, 6 insertions, 7 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 6ee0cacb520..329fa6ba670 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | 2013-07-14 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2013-07-14 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * filelock.c (create_lock_file) [!HAVE_MKOSTEMP && !HAVE_MKSTEMP]: | ||
| 4 | Simplify by making this case like the other two. This is a bit | ||
| 5 | slower on obsolete hosts, but the extra complexity isn't worth it. | ||
| 6 | |||
| 3 | * callproc.c (child_setup, relocate_fd) [!DOS_NT]: | 7 | * callproc.c (child_setup, relocate_fd) [!DOS_NT]: |
| 4 | * process.c (create_process) [!DOS_NT]: | 8 | * process.c (create_process) [!DOS_NT]: |
| 5 | Remove now-unnecessary calls to emacs_close. | 9 | Remove now-unnecessary calls to emacs_close. |
diff --git a/src/filelock.c b/src/filelock.c index 244663ad20a..4982dd3de13 100644 --- a/src/filelock.c +++ b/src/filelock.c | |||
| @@ -412,8 +412,6 @@ create_lock_file (char *lfname, char *lock_info_str, bool force) | |||
| 412 | USE_SAFE_ALLOCA; | 412 | USE_SAFE_ALLOCA; |
| 413 | char *nonce = SAFE_ALLOCA (lfdirlen + sizeof nonce_base); | 413 | char *nonce = SAFE_ALLOCA (lfdirlen + sizeof nonce_base); |
| 414 | int fd; | 414 | int fd; |
| 415 | bool need_fchmod; | ||
| 416 | mode_t world_readable = S_IRUSR | S_IRGRP | S_IROTH; | ||
| 417 | memcpy (nonce, lfname, lfdirlen); | 415 | memcpy (nonce, lfname, lfdirlen); |
| 418 | strcpy (nonce + lfdirlen, nonce_base); | 416 | strcpy (nonce + lfdirlen, nonce_base); |
| 419 | 417 | ||
| @@ -421,17 +419,14 @@ create_lock_file (char *lfname, char *lock_info_str, bool force) | |||
| 421 | /* Prefer mkostemp to mkstemp, as it avoids a window where FD is | 419 | /* Prefer mkostemp to mkstemp, as it avoids a window where FD is |
| 422 | temporarily open without close-on-exec. */ | 420 | temporarily open without close-on-exec. */ |
| 423 | fd = mkostemp (nonce, O_BINARY | O_CLOEXEC); | 421 | fd = mkostemp (nonce, O_BINARY | O_CLOEXEC); |
| 424 | need_fchmod = 1; | ||
| 425 | #elif HAVE_MKSTEMP | 422 | #elif HAVE_MKSTEMP |
| 426 | /* Prefer mkstemp to mktemp, as it avoids a race between | 423 | /* Prefer mkstemp to mktemp, as it avoids a race between |
| 427 | mktemp and emacs_open. */ | 424 | mktemp and emacs_open. */ |
| 428 | fd = mkstemp (nonce); | 425 | fd = mkstemp (nonce); |
| 429 | need_fchmod = 1; | ||
| 430 | #else | 426 | #else |
| 431 | mktemp (nonce); | 427 | mktemp (nonce); |
| 432 | fd = emacs_open (nonce, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, | 428 | fd = emacs_open (nonce, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, |
| 433 | world_readable); | 429 | S_IRUSR | S_IWUSR); |
| 434 | need_fchmod = 0; | ||
| 435 | #endif | 430 | #endif |
| 436 | 431 | ||
| 437 | if (fd < 0) | 432 | if (fd < 0) |
| @@ -445,7 +440,7 @@ create_lock_file (char *lfname, char *lock_info_str, bool force) | |||
| 445 | lock_info_len = strlen (lock_info_str); | 440 | lock_info_len = strlen (lock_info_str); |
| 446 | err = 0; | 441 | err = 0; |
| 447 | if (emacs_write (fd, lock_info_str, lock_info_len) != lock_info_len | 442 | if (emacs_write (fd, lock_info_str, lock_info_len) != lock_info_len |
| 448 | || (need_fchmod && fchmod (fd, world_readable) != 0)) | 443 | || fchmod (fd, S_IRUSR | S_IRGRP | S_IROTH) != 0) |
| 449 | err = errno; | 444 | err = errno; |
| 450 | /* There is no need to call fsync here, as the contents of | 445 | /* There is no need to call fsync here, as the contents of |
| 451 | the lock file need not survive system crashes. */ | 446 | the lock file need not survive system crashes. */ |