diff options
Diffstat (limited to 'src/filelock.c')
| -rw-r--r-- | src/filelock.c | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/src/filelock.c b/src/filelock.c index b9c991e4baf..df72eff5950 100644 --- a/src/filelock.c +++ b/src/filelock.c | |||
| @@ -181,7 +181,7 @@ get_boot_time (void) | |||
| 181 | since utmp is typically much smaller than wtmp. | 181 | since utmp is typically much smaller than wtmp. |
| 182 | Passing a null pointer causes get_boot_time_1 | 182 | Passing a null pointer causes get_boot_time_1 |
| 183 | to inspect the default file, namely utmp. */ | 183 | to inspect the default file, namely utmp. */ |
| 184 | get_boot_time_1 ((char *) 0, 0); | 184 | get_boot_time_1 (0, 0); |
| 185 | if (boot_time) | 185 | if (boot_time) |
| 186 | return boot_time; | 186 | return boot_time; |
| 187 | 187 | ||
| @@ -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 |
| @@ -759,16 +745,15 @@ unlock_file (Lisp_Object fn) | |||
| 759 | void | 745 | void |
| 760 | unlock_all_files (void) | 746 | unlock_all_files (void) |
| 761 | { | 747 | { |
| 762 | register Lisp_Object tail; | 748 | register Lisp_Object tail, buf; |
| 763 | register struct buffer *b; | 749 | register struct buffer *b; |
| 764 | 750 | ||
| 765 | for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) | 751 | FOR_EACH_LIVE_BUFFER (tail, buf) |
| 766 | { | 752 | { |
| 767 | b = XBUFFER (XCDR (XCAR (tail))); | 753 | b = XBUFFER (buf); |
| 768 | if (STRINGP (BVAR (b, file_truename)) && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)) | 754 | if (STRINGP (BVAR (b, file_truename)) |
| 769 | { | 755 | && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)) |
| 770 | unlock_file (BVAR (b, file_truename)); | 756 | unlock_file (BVAR (b, file_truename)); |
| 771 | } | ||
| 772 | } | 757 | } |
| 773 | } | 758 | } |
| 774 | 759 | ||