diff options
| author | Eli Zaretskii | 2013-02-27 20:37:31 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2013-02-27 20:37:31 +0200 |
| commit | 531e70eca4c3bcd44942a67f5ea1a8bb1cb41dad (patch) | |
| tree | 96029f04b4bb10fb348e94d7707edb61e1017d50 /src/filelock.c | |
| parent | f2c884009053be5a380a55cf2dec226fc686286c (diff) | |
| download | emacs-531e70eca4c3bcd44942a67f5ea1a8bb1cb41dad.tar.gz emacs-531e70eca4c3bcd44942a67f5ea1a8bb1cb41dad.zip | |
Fix race conditions with MS-Windows lock files by using _sopen.
src/filelock.c (create_lock_file) [WINDOWSNT]: Use _sopen with
_SH_DENYRW flag, instead of emacs_open, to deny any other process
access to the lock file until it is written and closed.
Fixes: debbugs:13807
Diffstat (limited to 'src/filelock.c')
| -rw-r--r-- | src/filelock.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/filelock.c b/src/filelock.c index 4d556de2454..78cd60a12e1 100644 --- a/src/filelock.c +++ b/src/filelock.c | |||
| @@ -44,6 +44,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 44 | #include "coding.h" | 44 | #include "coding.h" |
| 45 | #include "systime.h" | 45 | #include "systime.h" |
| 46 | #ifdef WINDOWSNT | 46 | #ifdef WINDOWSNT |
| 47 | #include <share.h> | ||
| 47 | #include "w32.h" /* for dostounix_filename */ | 48 | #include "w32.h" /* for dostounix_filename */ |
| 48 | #endif | 49 | #endif |
| 49 | 50 | ||
| @@ -353,12 +354,17 @@ create_lock_file (char *lfname, char *lock_info_str, bool force) | |||
| 353 | create a regular file with the lock info written as its | 354 | create a regular file with the lock info written as its |
| 354 | contents. */ | 355 | contents. */ |
| 355 | { | 356 | { |
| 356 | int fd = emacs_open (lfname, O_WRONLY | O_BINARY | O_CREAT | O_EXCL, | 357 | /* Deny everybody else any kind of access to the file until we are |
| 357 | S_IREAD | S_IWRITE); | 358 | done writing it and close the handle. This makes the entire |
| 359 | open/write/close operation atomic, as far as other processes | ||
| 360 | are concerned. */ | ||
| 361 | int fd = _sopen (lfname, | ||
| 362 | _O_WRONLY | _O_BINARY | _O_CREAT | _O_EXCL | _O_NOINHERIT, | ||
| 363 | _SH_DENYRW, S_IREAD | S_IWRITE); | ||
| 358 | 364 | ||
| 359 | if (fd < 0 && errno == EEXIST && force) | 365 | if (fd < 0 && errno == EEXIST && force) |
| 360 | fd = emacs_open (lfname, O_WRONLY | O_BINARY | O_TRUNC, | 366 | fd = _sopen (lfname, _O_WRONLY | _O_BINARY | _O_TRUNC |_O_NOINHERIT, |
| 361 | S_IREAD | S_IWRITE); | 367 | _SH_DENYRW, S_IREAD | S_IWRITE); |
| 362 | if (fd >= 0) | 368 | if (fd >= 0) |
| 363 | { | 369 | { |
| 364 | ssize_t lock_info_len = strlen (lock_info_str); | 370 | ssize_t lock_info_len = strlen (lock_info_str); |