From: Paul Eggert <eggert@cs.ucla.edu>
To: Dmitry Gutov <raaahh@gmail.com>
Cc: 13149@debbugs.gnu.org
Subject: bug#13149: 24.3.50; Emacs thinks file was changed outside Emacs, but it was not
Date: Tue, 15 Jan 2013 21:57:29 -0800 [thread overview]
Message-ID: <50F64149.6010704@cs.ucla.edu> (raw)
In-Reply-To: <50F5E9DB.1030309@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 323 bytes --]
On 01/15/2013 03:44 PM, Dmitry Gutov wrote:
> Maybe it's a sign of my system slowly falling apart.
It does sound like a fairly serious issue of some sort.
I did think of a patch (attached) but I'd rather not
apply it if the system in question is merely experimental,
since it introduces a race even on non-buggy systems.
[-- Attachment #2: mtime.txt --]
[-- Type: text/plain, Size: 4140 bytes --]
=== modified file 'src/ChangeLog'
--- src/ChangeLog 2013-01-15 21:38:58 +0000
+++ src/ChangeLog 2013-01-16 05:01:01 +0000
@@ -1,3 +1,18 @@
+2013-01-16 Paul Eggert <eggert@cs.ucla.edu>
+
+ Work around bug in vboxsf file system (Bug#13149).
+ The bug was observed on Ubuntu operating inside a virtual machine,
+ editing files mounted via vboxsf from the MS Windows 7 host.
+ The workaround introduces a race condition on non-buggy hosts,
+ but it's an unlikely race and anyway there's a nearly identical
+ nearby race that can't be fixed.
+ * fileio.c (valid_timestamp_file_system, timestamp_file_system):
+ New static vars.
+ (Fwrite_region): Test for file system time stamp bug.
+ (init_fileio): New function.
+ * lisp.h (init_fileio): Declare it.
+ * emacs.c (main): Call it.
+
2013-01-15 Paul Eggert <eggert@cs.ucla.edu>
* alloc.c (free_save_value): Now static.
=== modified file 'src/emacs.c'
--- src/emacs.c 2013-01-13 20:03:01 +0000
+++ src/emacs.c 2013-01-16 05:01:01 +0000
@@ -1317,6 +1317,7 @@
}
init_callproc (); /* Must follow init_cmdargs but not init_sys_modes. */
+ init_fileio ();
init_lread ();
#ifdef WINDOWSNT
/* Check to see if Emacs has been installed correctly. */
=== modified file 'src/fileio.c'
--- src/fileio.c 2013-01-15 10:14:31 +0000
+++ src/fileio.c 2013-01-16 05:04:51 +0000
@@ -103,6 +103,11 @@
/* Set by auto_save_1 if an error occurred during the last auto-save. */
static bool auto_save_error_occurred;
+/* If VALID_TIMESTAMP_FILE_SYSTEM, then TIMESTAMP_FILE_SYSTEM is the device
+ number of a file system where time stamps were observed to to work. */
+static bool valid_timestamp_file_system;
+static dev_t timestamp_file_system;
+
/* The symbol bound to coding-system-for-read when
insert-file-contents is called for recovering a file. This is not
an actual coding system name, but just an indicator to tell
@@ -5020,6 +5025,42 @@
/* Discard the unwind protect for close_file_unwind. */
specpdl_ptr = specpdl + count1;
+ /* Some file systems have a bug where st_mtime is updated merely
+ because a file was closed. Update MODTIME to the newer st_mtime
+ if this file system appears to have the bug. Working around this
+ bug introduces a race condition: to avoid most instances of the
+ race condition on non-buggy file systems, skip this check if the
+ most recently encountered non-buggy file system was the current
+ file system.
+
+ A race condition can occur if some other process modifies the
+ file between the fstat above and the stat below, but the race is
+ unlikely and a similar race between the last write and the fstat
+ above cannot possibly be closed anyway. */
+
+ if (visiting && EMACS_TIME_VALID_P (modtime)
+ && ! (valid_timestamp_file_system && st.st_dev == timestamp_file_system))
+ {
+ struct stat stat_st;
+ if (stat (fn, &stat_st) != 0)
+ ok = 0, save_errno = errno;
+ else if (stat_st.st_dev == st.st_dev && stat_st.st_ino == st.st_ino)
+ {
+ EMACS_TIME stat_modtime = get_stat_mtime (&stat_st);
+ if (EMACS_TIME_EQ (modtime, stat_modtime)
+ && st.st_size == stat_st.st_size)
+ {
+ timestamp_file_system = st.st_dev;
+ valid_timestamp_file_system = 1;
+ }
+ else
+ {
+ st.st_size = stat_st.st_size;
+ modtime = stat_modtime;
+ }
+ }
+ }
+
/* Call write-region-post-annotation-function. */
while (CONSP (Vwrite_region_annotation_buffers))
{
@@ -5814,8 +5855,13 @@
args[6] = predicate;
RETURN_UNGCPRO (Ffuncall (7, args));
}
+\f
+void
+init_fileio (void)
+{
+ valid_timestamp_file_system = 0;
+}
-\f
void
syms_of_fileio (void)
{
=== modified file 'src/lisp.h'
--- src/lisp.h 2013-01-15 21:38:58 +0000
+++ src/lisp.h 2013-01-16 05:01:01 +0000
@@ -3256,6 +3256,7 @@
extern bool internal_delete_file (Lisp_Object);
extern bool file_directory_p (const char *);
extern bool file_accessible_directory_p (const char *);
+extern void init_fileio (void);
extern void syms_of_fileio (void);
extern Lisp_Object make_temp_name (Lisp_Object, bool);
extern Lisp_Object Qdelete_file;
next prev parent reply other threads:[~2013-01-16 5:57 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-11 21:51 bug#13149: 24.3.50; Emacs thinks file was changed outside Emacs, but it was not Drew Adams
2012-12-11 22:48 ` Dmitry Gutov
2012-12-11 22:54 ` Drew Adams
2013-01-14 5:10 ` Dmitry Gutov
2013-01-14 14:57 ` Dmitry Gutov
2013-01-14 17:02 ` Eli Zaretskii
2013-01-14 22:22 ` Dmitry Gutov
2013-01-14 18:28 ` Paul Eggert
2013-01-14 22:20 ` Dmitry Gutov
2013-01-15 6:45 ` Paul Eggert
2013-01-15 8:54 ` Dmitry Gutov
2013-01-15 17:31 ` Paul Eggert
2013-01-15 21:38 ` Dmitry Gutov
2013-01-15 21:47 ` Paul Eggert
2013-01-15 22:11 ` Dmitry Gutov
2013-01-15 22:38 ` Paul Eggert
2013-01-15 23:09 ` Dmitry Gutov
2013-01-15 23:44 ` Dmitry Gutov
2013-01-16 5:57 ` Paul Eggert [this message]
2013-01-17 10:32 ` Dmitry Gutov
2013-01-17 17:05 ` Eli Zaretskii
2013-01-18 4:15 ` Dmitry Gutov
2013-01-18 7:49 ` Eli Zaretskii
2013-01-17 21:14 ` Paul Eggert
2013-01-18 4:55 ` Dmitry Gutov
2013-01-18 5:26 ` Paul Eggert
2013-01-17 21:33 ` Paul Eggert
2013-01-18 4:36 ` Dmitry Gutov
2013-01-18 5:01 ` Paul Eggert
2013-01-18 5:10 ` Dmitry Gutov
2013-01-18 5:25 ` Paul Eggert
2013-01-18 5:54 ` Dmitry Gutov
2013-01-18 6:22 ` Dmitry Gutov
2013-01-18 7:56 ` Eli Zaretskii
2013-01-18 14:45 ` Dmitry Gutov
2013-01-18 21:35 ` Paul Eggert
2013-01-18 22:52 ` Dmitry Gutov
2013-01-19 0:55 ` Paul Eggert
2013-01-19 1:09 ` Dmitry Gutov
2013-01-19 2:37 ` Paul Eggert
2013-01-19 4:02 ` Dmitry Gutov
2013-01-19 4:51 ` Paul Eggert
[not found] ` <DEB91990BBBB4255BFB466956EB54214@us.oracl! e.com>
[not found] ` <DEB91990BBBB4255BFB466956EB54214@us.oracl!>
[not found] ` <e.com@[87.69.4.28]>
[not found] ` <83wq! urc1u3.fsf@gnu.org>
[not found] ` <DEB91990BBBB4255BFB466956! EB54214@us.oracl!>
[not found] ` <DEB91990BBBB4255BFB466956EB54214@us.oracl!e.com>
2013-01-19 5:02 ` Drew Adams
2013-02-01 16:32 ` Drew Adams
2013-02-01 16:43 ` Drew Adams
2013-02-01 16:49 ` Drew Adams
2013-02-01 18:43 ` Eli Zaretskii
2013-02-01 19:19 ` Drew Adams
2013-02-01 19:36 ` Eli Zaretskii
2013-02-01 22:15 ` Drew Adams
2013-02-02 9:41 ` Eli Zaretskii
2013-02-02 16:06 ` Drew Adams
2013-02-01 19:38 ` Eli Zaretskii
2013-02-01 22:13 ` Drew Adams
2013-02-01 21:05 ` Paul Eggert
2013-02-01 22:14 ` Drew Adams
2013-02-01 22:22 ` Paul Eggert
2013-02-02 9:43 ` Eli Zaretskii
2013-03-19 8:39 ` Uwe Siart
2013-03-19 16:55 ` Eli Zaretskii
2013-03-19 17:50 ` Uwe Siart
2014-02-06 1:40 ` Lars Ingebrigtsen
2014-02-06 6:12 ` Drew Adams
2014-02-06 6:19 ` Eli Zaretskii
2013-02-02 9:38 ` Eli Zaretskii
2013-02-02 19:31 ` Paul Eggert
2013-01-18 7:57 ` Eli Zaretskii
2013-01-17 17:16 ` David Engster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50F64149.6010704@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=13149@debbugs.gnu.org \
--cc=raaahh@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).