unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 13149@debbugs.gnu.org, Paul Eggert <eggert@cs.ucla.edu>
Subject: bug#13149: 24.3.50; Emacs thinks file was changed outside Emacs, but it was not
Date: Fri, 18 Jan 2013 18:45:14 +0400	[thread overview]
Message-ID: <50F95FFA.3080601@yandex.ru> (raw)
In-Reply-To: <83a9s67wlr.fsf@gnu.org>

On 18.01.2013 11:56, Eli Zaretskii wrote:
>> Date: Thu, 17 Jan 2013 21:25:31 -0800
>> From: Paul Eggert <eggert@cs.ucla.edu>
>> CC: 13149@debbugs.gnu.org, Eli Zaretskii <eliz@gnu.org>
>>
>> On 01/17/2013 09:10 PM, Dmitry Gutov wrote:
>>> cifs:
>>>
>>> 1358485764.638001400 fstat
>>> 1358485764.638001400 lstat
>>> 1358485764.638001400 stat
>>> *
>>> 1358485764.638001400 fstat
>>> 1358485764.638001400 lstat
>>> 1358485764.638001400 stat
>>
>> That looks busted, since there's
>> a 10 ms sleep followed by a write at the two
>> points I marked "*" above, which means that
>> fstat, lstat, and stat are all wrong after the "*".
>
> Who said anything was actually written to the file?  You'd need
> 'fsync' to be sure, don't you?

Sticking fsync(fd) after the call to 'write' doesn't change anything.

If, however, I move the 'nanosleep' after the 'write' and set the 
interval to 1 or 2 seconds, on vboxsf the numbers often become 
different, but without guarantee. With 1 second, they usually the same, 
with 2 second, they're mostly different, but still the same sometimes.

gutov@vbx:~/docs/Ruby$ ~/emacs-bzr/fs-test2
1358520180.757726300 fstat
1358520180.757726300 lstat
1358520180.757726300 stat

1358520181.689844700 fstat
1358520181.689844700 lstat
1358520181.689844700 stat

gutov@vbx:~/docs/Ruby$ ~/emacs-bzr/fs-test2
1358520183.414063600 fstat
1358520183.414063600 lstat
1358520183.414063600 stat

1358520183.414063600 fstat
1358520183.414063600 lstat
1358520183.414063600 stat

Adding another 'nanosleep' before the 'write' doesn't change that.

On cifs, the numbers are never different.

#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>

static int
report_times (int fd, char const *file)
{
   struct stat fst, lst, st;
   if (fstat (fd, &fst) != 0)
     return perror ("fstat"), -1;
   if (lstat (file, &lst) != 0)
     return perror ("lstat"), -1;
   if (stat (file, &st) != 0)
     return perror ("stat"), -1;
   printf ("%ld.%09ld fstat\n", (long) fst.st_mtim.tv_sec, 
fst.st_mtim.tv_nsec);
   printf ("%ld.%09ld lstat\n", (long) lst.st_mtim.tv_sec, 
lst.st_mtim.tv_nsec);
   printf ("%ld.%09ld stat\n", (long) st.st_mtim.tv_sec, 
st.st_mtim.tv_nsec);
   printf ("\n");
   return 0;
}

int
main (void)
{
   static char const file[] = "foo";
   struct timespec interval, bef_interval;
   int fd;
   unlink (file);
   fd = open (file, O_CREAT | O_WRONLY, -1);
   if (fd < 0)
     return perror ("open"), 1;
   if (report_times (fd, file) != 0)
     return 1;
   bef_interval.tv_sec = 0;
   bef_interval.tv_nsec = 100000000;
   interval.tv_sec = 2;
   interval.tv_nsec = 0;
   //  if (nanosleep (&bef_interval, 0) != 0)
   //  return perror ("nanosleep"), 1;
   if (write (fd, file, sizeof file - 1) != sizeof file - 1)
     return perror ("write"), 1;
   // fsync(fd);
   if (nanosleep (&interval, 0) != 0)
     return perror ("nanosleep"), 1;
   if (report_times (fd, file) != 0)
     return 1;
   return 0;
}






  reply	other threads:[~2013-01-18 14:45 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
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 [this message]
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! 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!>
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=50F95FFA.3080601@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=13149@debbugs.gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    /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).