diff options
| author | Paul Eggert | 2013-08-04 09:56:56 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-08-04 09:56:56 -0700 |
| commit | e0fdb6943066032db294720915c3bd644bf2bcd1 (patch) | |
| tree | 0aa420b81dc0187e2efec3ff4fe3cf046ad1c598 /src/filelock.c | |
| parent | 484ab23924d39b3e26d54074fd659633e1660ef4 (diff) | |
| download | emacs-e0fdb6943066032db294720915c3bd644bf2bcd1.tar.gz emacs-e0fdb6943066032db294720915c3bd644bf2bcd1.zip | |
Fix some minor races in hosts lacking mkostemp.
Gnulib's emulation of mkostemp doesn't have races that Emacs's does.
* configure.ac (mkostemp): Remove check for this function;
gnulib does the check now.
(mkstemp): Remove check for this no-longer-used function.
* lib/mkostemp.c, lib/secure_getenv.c, lib/tempname.c, lib/tempname.h:
* m4/mkostemp.m4, m4/secure_getenv.m4, m4/tempname.m4:
New files, copied from Gnulib.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
* admin/merge-gnulib (GNULIB_MODULES): Add mkostemp.
* lib-src/movemail.c (main):
* lib-src/update-game-score.c (write_scores):
Use mkostemp (which now works on all platforms, due to changes
in the portability layer) rather than mktemp (which has a race)
or mkstemp (which we no longer bother with).
* src/callproc.c (create_temp_file):
* src/filelock.c (create_lock_file):
Assume mkostemp, since it's now provided by Gnulib.
Fixes: debbugs:15015
Diffstat (limited to 'src/filelock.c')
| -rw-r--r-- | src/filelock.c | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/src/filelock.c b/src/filelock.c index b9c991e4baf..0f31b7d4deb 100644 --- a/src/filelock.c +++ b/src/filelock.c | |||
| @@ -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 |