GNU bug report logs -
#13807
The lock for 'DIR/FILE' should always be 'DIR/.#FILE'.
Previous Next
Reported by: Paul Eggert <eggert <at> cs.ucla.edu>
Date: Sun, 24 Feb 2013 22:51:01 UTC
Severity: wishlist
Tags: patch
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
Full log
Message #38 received at 13807 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 03/04/13 08:50, Eli Zaretskii wrote:
> it's out there, and others might bump into it.
OK. Luckily, with the latest proposed patch, Emacs users will be less
likely to bump into the NFS problem, since Emacs won't attempt to create
lock files that exploit the issue.
> These issues are unrelated to whether Emacs on Windows does or doesn't
> lock files. They existed before, as did the issue with FAT32 volumes
> being used from Posix hosts.
Yes, quite right. Sorry I misunderstood you.
> I think you exaggerate the probability of having Emacs running on
> Windows to access via NFS files shared with Posix systems.
Possibly. It depends on local practice. Many locations don't use NFS
at all. Around here we use NFS heavily.
> This will need a no-op emulation of fchmod for Windows (since a file
> created here will be world-writable anyway).
OK, thanks. Also, older POSIXish hosts that lack mkstemp won't need
the fchmod either. I added the following to try to address these two points.
Revised complete patch attached, relative to trunk bzr 111938.
=== modified file 'src/filelock.c'
--- src/filelock.c 2013-03-04 19:27:39 +0000
+++ src/filelock.c 2013-03-04 19:36:45 +0000
@@ -407,15 +407,21 @@
USE_SAFE_ALLOCA;
char *nonce = SAFE_ALLOCA (lfdirlen + sizeof nonce_base);
int fd;
+ bool need_fchmod;
+ mode_t world_readable = S_IRUSR | S_IRGRP | S_IROTH;
memcpy (nonce, lfname, lfdirlen);
strcpy (nonce + lfdirlen, nonce_base);
#if HAVE_MKSTEMP
+ /* Prefer mkstemp if available, as it avoids a race between
+ mktemp and emacs_open. */
fd = mkstemp (nonce);
+ need_fchmod = 1;
#else
mktemp (nonce);
fd = emacs_open (nonce, O_WRONLY | O_CREAT | O_EXCL | O_BINARY,
- S_IRUSR | S_IWUSR);
+ world_readable);
+ need_fchmod = 0;
#endif
if (fd < 0)
@@ -425,7 +431,7 @@
ptrdiff_t lock_info_len = strlen (lock_info_str);
err = 0;
if (emacs_write (fd, lock_info_str, lock_info_len) != lock_info_len
- || fchmod (fd, S_IRUSR | S_IRGRP | S_IROTH) != 0)
+ || (need_fchmod && fchmod (fd, world_readable) != 0))
err = errno;
if (emacs_close (fd) != 0)
err = errno;
=== modified file 'src/w32.c'
--- src/w32.c 2013-03-03 23:12:54 +0000
+++ src/w32.c 2013-03-05 01:42:12 +0000
@@ -3416,6 +3416,12 @@
}
int
+fchmod (int fd, mode_t mode)
+{
+ return 0;
+}
+
+int
sys_rename_replace (const char *oldname, const char *newname, BOOL force)
{
BOOL result;
=== modified file 'src/w32.h'
--- src/w32.h 2013-03-03 23:12:54 +0000
+++ src/w32.h 2013-03-05 01:42:12 +0000
@@ -186,6 +186,7 @@
extern void srandom (int);
extern int random (void);
+extern int fchmod (int, mode_t);
extern int sys_rename_replace (char const *, char const *, BOOL);
extern int sys_pipe (int *);
[filelock2.txt (text/plain, attachment)]
This bug report was last modified 12 years and 83 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.