diff options
| author | Paul Eggert | 2013-03-13 11:42:22 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-03-13 11:42:22 -0700 |
| commit | 47d7532e093db8a5068a40c587915121ffaaad18 (patch) | |
| tree | a99ea6eca34ea0e9c8d6e8a8d6291833ce27dca5 /src | |
| parent | c7ffccaf17d63cefd34bef0a9becc4e68df3b115 (diff) | |
| download | emacs-47d7532e093db8a5068a40c587915121ffaaad18.tar.gz emacs-47d7532e093db8a5068a40c587915121ffaaad18.zip | |
File synchronization fixes.
* admin/CPP-DEFINES (BSD_SYSTEM, HAVE_FSYNC): Remove.
* admin/merge-gnulib (GNULIB_MODULES): Add fsync, fdatasync.
* configure.ac (BSD_SYSTEM, BSD_SYSTEM_AHB): Remove; no longer needed.
(fsync): Remove check; now done by gnulib.
* lib/fdatasync.c, lib/fsync.c, m4/fdatasync.m4, m4/fsync.m4:
New files, from gnulib.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
* lib-src/Makefile.in (LIB_FDATASYNC): New macro.
(emacsclient${EXEEXT}): Use it.
* lib-src/emacsclient.c (main): Use fdatasync, not fsync, since we don't
care about metadata. Keep trying if interrupted.
* lib-src/movemail.c (main, popmail): Don't worry about BSD_SYSTEM, since
fsync is available everywhere (or there is a substitute). Don't
report an error if fsync returns EINVAL.
* nt/inc/ms-w32.h (fdatasync): New macro, suggested by Eli Zaretskii.
* src/Makefile.in (LIB_FDATASYNC): New macro.
(LIBES): Use it.
* src/conf_post.h (BSD_SYSTEM, BSD_SYSTEM_AHB): Remove; no longer needed.
* src/fileio.c (Fwrite_region, write_region_inhibit_fsync):
Don't worry about HAVE_FSYNC, since a substitute fsync is
available if the system lacks one.
(Fwrite_regin): Retry fsync if interrupted.
Fixes: debbugs:13944
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 11 | ||||
| -rw-r--r-- | src/Makefile.in | 3 | ||||
| -rw-r--r-- | src/conf_post.h | 13 | ||||
| -rw-r--r-- | src/fileio.c | 17 | ||||
| -rw-r--r-- | src/filelock.c | 8 | ||||
| -rw-r--r-- | src/sysdep.c | 5 |
6 files changed, 32 insertions, 25 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index ae6fe86f661..d328d0a74ca 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,14 @@ | |||
| 1 | 2013-03-13 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | File synchronization fixes (Bug#13944). | ||
| 4 | * Makefile.in (LIB_FDATASYNC): New macro. | ||
| 5 | (LIBES): Use it. | ||
| 6 | * conf_post.h (BSD_SYSTEM, BSD_SYSTEM_AHB): Remove; no longer needed. | ||
| 7 | * fileio.c (Fwrite_region, write_region_inhibit_fsync): | ||
| 8 | Don't worry about HAVE_FSYNC, since a substitute fsync is | ||
| 9 | available if the system lacks one. | ||
| 10 | (Fwrite_regin): Retry fsync if interrupted. | ||
| 11 | |||
| 1 | 2013-03-13 Eli Zaretskii <eliz@gnu.org> | 12 | 2013-03-13 Eli Zaretskii <eliz@gnu.org> |
| 2 | 13 | ||
| 3 | * w32term.c (w32_read_socket): If we Emacs frame is being | 14 | * w32term.c (w32_read_socket): If we Emacs frame is being |
diff --git a/src/Makefile.in b/src/Makefile.in index b2034a3379d..31de9714c65 100644 --- a/src/Makefile.in +++ b/src/Makefile.in | |||
| @@ -139,6 +139,7 @@ M17N_FLT_LIBS = @M17N_FLT_LIBS@ | |||
| 139 | 139 | ||
| 140 | LIB_CLOCK_GETTIME=@LIB_CLOCK_GETTIME@ | 140 | LIB_CLOCK_GETTIME=@LIB_CLOCK_GETTIME@ |
| 141 | LIB_EACCESS=@LIB_EACCESS@ | 141 | LIB_EACCESS=@LIB_EACCESS@ |
| 142 | LIB_FDATASYNC=@LIB_FDATASYNC@ | ||
| 142 | LIB_TIMER_TIME=@LIB_TIMER_TIME@ | 143 | LIB_TIMER_TIME=@LIB_TIMER_TIME@ |
| 143 | 144 | ||
| 144 | DBUS_CFLAGS = @DBUS_CFLAGS@ | 145 | DBUS_CFLAGS = @DBUS_CFLAGS@ |
| @@ -391,7 +392,7 @@ ALLOBJS = $(VMLIMIT_OBJ) $(obj) $(otherobj) | |||
| 391 | LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \ | 392 | LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \ |
| 392 | $(LIBX_OTHER) $(LIBSOUND) \ | 393 | $(LIBX_OTHER) $(LIBSOUND) \ |
| 393 | $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) \ | 394 | $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) \ |
| 394 | $(LIB_EACCESS) $(LIB_TIMER_TIME) $(DBUS_LIBS) \ | 395 | $(LIB_EACCESS) $(LIB_FDATASYNC) $(LIB_TIMER_TIME) $(DBUS_LIBS) \ |
| 395 | $(LIB_EXECINFO) \ | 396 | $(LIB_EXECINFO) \ |
| 396 | $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \ | 397 | $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \ |
| 397 | $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \ | 398 | $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \ |
diff --git a/src/conf_post.h b/src/conf_post.h index 6c9747a436c..5cb385d9029 100644 --- a/src/conf_post.h +++ b/src/conf_post.h | |||
| @@ -44,19 +44,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 44 | # define __has_attribute(a) 0 /* non-clang */ | 44 | # define __has_attribute(a) 0 /* non-clang */ |
| 45 | #endif | 45 | #endif |
| 46 | 46 | ||
| 47 | /* This silences a few compilation warnings on FreeBSD. */ | ||
| 48 | #ifdef BSD_SYSTEM_AHB | ||
| 49 | #undef BSD_SYSTEM_AHB | ||
| 50 | #undef BSD_SYSTEM | ||
| 51 | #if __FreeBSD__ == 1 | ||
| 52 | #define BSD_SYSTEM 199103 | ||
| 53 | #elif __FreeBSD__ == 2 | ||
| 54 | #define BSD_SYSTEM 199306 | ||
| 55 | #elif __FreeBSD__ >= 3 | ||
| 56 | #define BSD_SYSTEM 199506 | ||
| 57 | #endif | ||
| 58 | #endif | ||
| 59 | |||
| 60 | #ifdef DARWIN_OS | 47 | #ifdef DARWIN_OS |
| 61 | #ifdef emacs | 48 | #ifdef emacs |
| 62 | #define malloc unexec_malloc | 49 | #define malloc unexec_malloc |
diff --git a/src/fileio.c b/src/fileio.c index 8937f7ca477..724250c8aaa 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -4959,20 +4959,23 @@ This calls `write-region-annotate-functions' at the start, and | |||
| 4959 | 4959 | ||
| 4960 | immediate_quit = 0; | 4960 | immediate_quit = 0; |
| 4961 | 4961 | ||
| 4962 | #ifdef HAVE_FSYNC | ||
| 4963 | /* fsync appears to change the modtime on BSD4.2. | 4962 | /* fsync appears to change the modtime on BSD4.2. |
| 4964 | Disk full in NFS may be reported here. */ | 4963 | Disk full in NFS may be reported here. */ |
| 4965 | /* mib says that closing the file will try to write as fast as NFS can do | 4964 | /* mib says that closing the file will try to write as fast as NFS can do |
| 4966 | it, and that means the fsync here is not crucial for autosave files. */ | 4965 | it, and that means the fsync here is not crucial for autosave files. */ |
| 4967 | if (!auto_saving && !write_region_inhibit_fsync && fsync (desc) < 0) | 4966 | if (!auto_saving && !write_region_inhibit_fsync) |
| 4968 | { | 4967 | { |
| 4969 | /* If fsync fails with EINTR, don't treat that as serious. Also | 4968 | /* Transfer data and metadata to disk, retrying if interrupted. Also, |
| 4970 | ignore EINVAL which happens when fsync is not supported on this | 4969 | ignore EINVAL which happens when fsync is not supported on this |
| 4971 | file. */ | 4970 | file. */ |
| 4972 | if (errno != EINTR && errno != EINVAL) | 4971 | while (fsync (desc) != 0) |
| 4973 | ok = 0, save_errno = errno; | 4972 | if (errno != EINTR) |
| 4973 | { | ||
| 4974 | if (errno != EINVAL) | ||
| 4975 | ok = 0, save_errno = errno; | ||
| 4976 | break; | ||
| 4977 | } | ||
| 4974 | } | 4978 | } |
| 4975 | #endif | ||
| 4976 | 4979 | ||
| 4977 | modtime = invalid_emacs_time (); | 4980 | modtime = invalid_emacs_time (); |
| 4978 | if (visiting) | 4981 | if (visiting) |
| @@ -6046,13 +6049,11 @@ in the buffer; this is the default behavior, because the auto-save | |||
| 6046 | file is usually more useful if it contains the deleted text. */); | 6049 | file is usually more useful if it contains the deleted text. */); |
| 6047 | Vauto_save_include_big_deletions = Qnil; | 6050 | Vauto_save_include_big_deletions = Qnil; |
| 6048 | 6051 | ||
| 6049 | #ifdef HAVE_FSYNC | ||
| 6050 | DEFVAR_BOOL ("write-region-inhibit-fsync", write_region_inhibit_fsync, | 6052 | DEFVAR_BOOL ("write-region-inhibit-fsync", write_region_inhibit_fsync, |
| 6051 | doc: /* Non-nil means don't call fsync in `write-region'. | 6053 | doc: /* Non-nil means don't call fsync in `write-region'. |
| 6052 | This variable affects calls to `write-region' as well as save commands. | 6054 | This variable affects calls to `write-region' as well as save commands. |
| 6053 | A non-nil value may result in data loss! */); | 6055 | A non-nil value may result in data loss! */); |
| 6054 | write_region_inhibit_fsync = 0; | 6056 | write_region_inhibit_fsync = 0; |
| 6055 | #endif | ||
| 6056 | 6057 | ||
| 6057 | DEFVAR_BOOL ("delete-by-moving-to-trash", delete_by_moving_to_trash, | 6058 | DEFVAR_BOOL ("delete-by-moving-to-trash", delete_by_moving_to_trash, |
| 6058 | doc: /* Specifies whether to use the system's trash can. | 6059 | doc: /* Specifies whether to use the system's trash can. |
diff --git a/src/filelock.c b/src/filelock.c index 32992896c2b..f17d3182eab 100644 --- a/src/filelock.c +++ b/src/filelock.c | |||
| @@ -437,6 +437,14 @@ create_lock_file (char *lfname, char *lock_info_str, bool force) | |||
| 437 | if (emacs_write (fd, lock_info_str, lock_info_len) != lock_info_len | 437 | if (emacs_write (fd, lock_info_str, lock_info_len) != lock_info_len |
| 438 | || (need_fchmod && fchmod (fd, world_readable) != 0)) | 438 | || (need_fchmod && fchmod (fd, world_readable) != 0)) |
| 439 | err = errno; | 439 | err = errno; |
| 440 | else | ||
| 441 | while (fsync (fd) != 0) | ||
| 442 | if (errno != EINTR) | ||
| 443 | { | ||
| 444 | if (errno != EINVAL) | ||
| 445 | err = errno; | ||
| 446 | break; | ||
| 447 | } | ||
| 440 | if (emacs_close (fd) != 0) | 448 | if (emacs_close (fd) != 0) |
| 441 | err = errno; | 449 | err = errno; |
| 442 | if (!err && rename_lock_file (nonce, lfname, force) != 0) | 450 | if (!err && rename_lock_file (nonce, lfname, force) != 0) |
diff --git a/src/sysdep.c b/src/sysdep.c index b99f179210c..bff11fc9f75 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -1289,10 +1289,9 @@ reset_sys_modes (struct tty_display_info *tty_out) | |||
| 1289 | if (tty_out->terminal->reset_terminal_modes_hook) | 1289 | if (tty_out->terminal->reset_terminal_modes_hook) |
| 1290 | tty_out->terminal->reset_terminal_modes_hook (tty_out->terminal); | 1290 | tty_out->terminal->reset_terminal_modes_hook (tty_out->terminal); |
| 1291 | 1291 | ||
| 1292 | #ifdef BSD_SYSTEM | ||
| 1293 | /* Avoid possible loss of output when changing terminal modes. */ | 1292 | /* Avoid possible loss of output when changing terminal modes. */ |
| 1294 | fsync (fileno (tty_out->output)); | 1293 | while (fdatasync (fileno (tty_out->output)) != 0 && errno == EINTR) |
| 1295 | #endif | 1294 | continue; |
| 1296 | 1295 | ||
| 1297 | #ifndef DOS_NT | 1296 | #ifndef DOS_NT |
| 1298 | #ifdef F_SETOWN | 1297 | #ifdef F_SETOWN |