emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r111888: Fix race conditions with MS-


From: Eli Zaretskii
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111888: Fix race conditions with MS-Windows lock files by using _sopen.
Date: Wed, 27 Feb 2013 20:37:31 +0200
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111888
fixes bug: http://debbugs.gnu.org/13807
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Wed 2013-02-27 20:37:31 +0200
message:
  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.
modified:
  src/ChangeLog
  src/filelock.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-02-27 07:42:43 +0000
+++ b/src/ChangeLog     2013-02-27 18:37:31 +0000
@@ -1,3 +1,10 @@
+2013-02-27  Eli Zaretskii  <address@hidden>
+
+       * 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.
+       (Bug#13807)
+
 2013-02-27  Paul Eggert  <address@hidden>
 
        * callint.c (Qcall_interactively):

=== modified file 'src/filelock.c'
--- a/src/filelock.c    2013-02-25 17:36:03 +0000
+++ b/src/filelock.c    2013-02-27 18:37:31 +0000
@@ -44,6 +44,7 @@
 #include "coding.h"
 #include "systime.h"
 #ifdef WINDOWSNT
+#include <share.h>
 #include "w32.h"       /* for dostounix_filename */
 #endif
 
@@ -353,12 +354,17 @@
      create a regular file with the lock info written as its
      contents.  */
   {
-    int fd = emacs_open (lfname, O_WRONLY | O_BINARY | O_CREAT | O_EXCL,
-                        S_IREAD | S_IWRITE);
+    /* Deny everybody else any kind of access to the file until we are
+       done writing it and close the handle.  This makes the entire
+       open/write/close operation atomic, as far as other processes
+       are concerned.  */
+    int fd = _sopen (lfname,
+                    _O_WRONLY | _O_BINARY | _O_CREAT | _O_EXCL | _O_NOINHERIT,
+                    _SH_DENYRW, S_IREAD | S_IWRITE);
 
     if (fd < 0 && errno == EEXIST && force)
-      fd = emacs_open (lfname, O_WRONLY | O_BINARY | O_TRUNC,
-                      S_IREAD | S_IWRITE);
+      fd = _sopen (lfname, _O_WRONLY | _O_BINARY | _O_TRUNC |_O_NOINHERIT,
+                  _SH_DENYRW, S_IREAD | S_IWRITE);
     if (fd >= 0)
       {
        ssize_t lock_info_len = strlen (lock_info_str);


reply via email to

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