bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#13807: updated version to avoid MS-Windows vs non-MS-Windows clashes


From: Paul Eggert
Subject: bug#13807: updated version to avoid MS-Windows vs non-MS-Windows clashes
Date: Mon, 04 Mar 2013 18:25:32 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130221 Thunderbird/17.0.3

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 *);
 


Attachment: filelock2.txt
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]