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 | |
| 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
| -rw-r--r-- | ChangeLog | 7 | ||||
| -rw-r--r-- | admin/CPP-DEFINES | 2 | ||||
| -rw-r--r-- | admin/ChangeLog | 6 | ||||
| -rwxr-xr-x | admin/merge-gnulib | 3 | ||||
| -rw-r--r-- | configure.ac | 36 | ||||
| -rw-r--r-- | lib-src/ChangeLog | 9 | ||||
| -rw-r--r-- | lib-src/Makefile.in | 4 | ||||
| -rw-r--r-- | lib-src/emacsclient.c | 6 | ||||
| -rw-r--r-- | lib-src/movemail.c | 17 | ||||
| -rw-r--r-- | lib/fdatasync.c | 27 | ||||
| -rw-r--r-- | lib/fsync.c | 83 | ||||
| -rw-r--r-- | lib/gnulib.mk | 20 | ||||
| -rw-r--r-- | m4/fdatasync.m4 | 32 | ||||
| -rw-r--r-- | m4/fsync.m4 | 17 | ||||
| -rw-r--r-- | m4/gnulib-comp.m4 | 17 | ||||
| -rw-r--r-- | nt/ChangeLog | 5 | ||||
| -rw-r--r-- | nt/inc/ms-w32.h | 1 | ||||
| -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 |
23 files changed, 273 insertions, 76 deletions
| @@ -1,5 +1,12 @@ | |||
| 1 | 2013-03-13 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2013-03-13 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | File synchronization fixes (Bug#13944). | ||
| 4 | * configure.ac (BSD_SYSTEM, BSD_SYSTEM_AHB): Remove; no longer needed. | ||
| 5 | (fsync): Remove check; now done by gnulib. | ||
| 6 | * lib/fdatasync.c, lib/fsync.c, m4/fdatasync.m4, m4/fsync.m4: | ||
| 7 | New files, from gnulib. | ||
| 8 | * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate. | ||
| 9 | |||
| 3 | Merge from gnulib, incorporating: | 10 | Merge from gnulib, incorporating: |
| 4 | 2013-03-13 putenv: port to Solaris 10 | 11 | 2013-03-13 putenv: port to Solaris 10 |
| 5 | 2013-03-12 mktime: fix configure typo | 12 | 2013-03-12 mktime: fix configure typo |
diff --git a/admin/CPP-DEFINES b/admin/CPP-DEFINES index da8dec5a0f6..c11c3c3b489 100644 --- a/admin/CPP-DEFINES +++ b/admin/CPP-DEFINES | |||
| @@ -9,7 +9,6 @@ documented in config.in, and this file would not be necessary. | |||
| 9 | 9 | ||
| 10 | AIX | 10 | AIX |
| 11 | _AIX | 11 | _AIX |
| 12 | BSD_SYSTEM | ||
| 13 | CYGWIN Compiling the Cygwin port. | 12 | CYGWIN Compiling the Cygwin port. |
| 14 | __CYGWIN__ Ditto | 13 | __CYGWIN__ Ditto |
| 15 | GNU_LINUX | 14 | GNU_LINUX |
| @@ -149,7 +148,6 @@ HAVE_FORK | |||
| 149 | HAVE_FREEIFADDRS | 148 | HAVE_FREEIFADDRS |
| 150 | HAVE_FREETYPE | 149 | HAVE_FREETYPE |
| 151 | HAVE_FSEEKO | 150 | HAVE_FSEEKO |
| 152 | HAVE_FSYNC | ||
| 153 | HAVE_FUTIMENS | 151 | HAVE_FUTIMENS |
| 154 | HAVE_FUTIMES | 152 | HAVE_FUTIMES |
| 155 | HAVE_FUTIMESAT | 153 | HAVE_FUTIMESAT |
diff --git a/admin/ChangeLog b/admin/ChangeLog index a0fd90e0d15..fcc339c17cd 100644 --- a/admin/ChangeLog +++ b/admin/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2013-03-13 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | File synchronization fixes (Bug#13944). | ||
| 4 | * CPP-DEFINES (BSD_SYSTEM, HAVE_FSYNC): Remove. | ||
| 5 | * merge-gnulib (GNULIB_MODULES): Add fsync, fdatasync. | ||
| 6 | |||
| 1 | 2013-03-11 Paul Eggert <eggert@cs.ucla.edu> | 7 | 2013-03-11 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 8 | ||
| 3 | * notes/unicode: Improve notes about Emacs source file encoding. | 9 | * notes/unicode: Improve notes about Emacs source file encoding. |
diff --git a/admin/merge-gnulib b/admin/merge-gnulib index b43f2bd9bb8..100749191f0 100755 --- a/admin/merge-gnulib +++ b/admin/merge-gnulib | |||
| @@ -29,7 +29,8 @@ GNULIB_MODULES=' | |||
| 29 | alloca-opt c-ctype c-strcase | 29 | alloca-opt c-ctype c-strcase |
| 30 | careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 | 30 | careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 |
| 31 | dtoastr dtotimespec dup2 environ execinfo faccessat | 31 | dtoastr dtotimespec dup2 environ execinfo faccessat |
| 32 | fcntl-h fdopendir filemode fstatat getloadavg getopt-gnu gettime gettimeofday | 32 | fcntl-h fdatasync fdopendir filemode fstatat fsync |
| 33 | getloadavg getopt-gnu gettime gettimeofday | ||
| 33 | ignore-value intprops largefile lstat | 34 | ignore-value intprops largefile lstat |
| 34 | manywarnings memrchr mktime | 35 | manywarnings memrchr mktime |
| 35 | pselect pthread_sigmask putenv readlink readlinkat | 36 | pselect pthread_sigmask putenv readlink readlinkat |
diff --git a/configure.ac b/configure.ac index aed625e44a9..0d1f31032a9 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -2872,7 +2872,7 @@ select getpagesize setlocale \ | |||
| 2872 | utimes getrlimit setrlimit shutdown getaddrinfo \ | 2872 | utimes getrlimit setrlimit shutdown getaddrinfo \ |
| 2873 | strsignal setitimer \ | 2873 | strsignal setitimer \ |
| 2874 | sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \ | 2874 | sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \ |
| 2875 | gai_strerror mkstemp getline getdelim fsync sync \ | 2875 | gai_strerror mkstemp getline getdelim sync \ |
| 2876 | difftime posix_memalign \ | 2876 | difftime posix_memalign \ |
| 2877 | getpwent endpwent getgrent endgrent \ | 2877 | getpwent endpwent getgrent endgrent \ |
| 2878 | touchlock \ | 2878 | touchlock \ |
| @@ -3774,7 +3774,6 @@ esac | |||
| 3774 | 3774 | ||
| 3775 | dnl Define symbols to identify the version of Unix this is. | 3775 | dnl Define symbols to identify the version of Unix this is. |
| 3776 | dnl Define all the symbols that apply correctly. | 3776 | dnl Define all the symbols that apply correctly. |
| 3777 | AH_TEMPLATE(BSD_SYSTEM, [Define if the system is compatible with BSD 4.2.]) | ||
| 3778 | AH_TEMPLATE(DOS_NT, [Define if the system is MS DOS or MS Windows.]) | 3777 | AH_TEMPLATE(DOS_NT, [Define if the system is MS DOS or MS Windows.]) |
| 3779 | AH_TEMPLATE(MSDOS, [Define if the system is MS DOS.]) | 3778 | AH_TEMPLATE(MSDOS, [Define if the system is MS DOS.]) |
| 3780 | AH_TEMPLATE(USG, [Define if the system is compatible with System III.]) | 3779 | AH_TEMPLATE(USG, [Define if the system is compatible with System III.]) |
| @@ -3798,30 +3797,12 @@ case $opsys in | |||
| 3798 | ;; | 3797 | ;; |
| 3799 | 3798 | ||
| 3800 | darwin) | 3799 | darwin) |
| 3801 | dnl BSD4_3 and BSD4_4 are already defined in sys/param.h. | 3800 | dnl Not __APPLE__, as this may not be defined on non-OSX Darwin. |
| 3802 | AC_DEFINE(BSD_SYSTEM, []) | 3801 | dnl Not DARWIN, because Panther and lower CoreFoundation.h use DARWIN to |
| 3803 | dnl More specific than the above two. We cannot use __APPLE__ as this | ||
| 3804 | dnl may not be defined on non-OSX Darwin, and we cannot define DARWIN | ||
| 3805 | dnl here because Panther and lower CoreFoundation.h uses DARWIN to | ||
| 3806 | dnl distinguish OS X from pure Darwin. | 3802 | dnl distinguish OS X from pure Darwin. |
| 3807 | AC_DEFINE(DARWIN_OS, [], [Define if the system is Darwin.]) | 3803 | AC_DEFINE(DARWIN_OS, [], [Define if the system is Darwin.]) |
| 3808 | ;; | 3804 | ;; |
| 3809 | 3805 | ||
| 3810 | freebsd) | ||
| 3811 | dnl Hack to avoid calling AC_PREPROC_IFELSE multiple times. | ||
| 3812 | dnl Would not be needed with autoconf >= 2.67, where the | ||
| 3813 | dnl preprocessed output is accessible in "conftest.i". | ||
| 3814 | AC_DEFINE(BSD_SYSTEM_AHB, 1, [Define if AH_BOTTOM should change BSD_SYSTEM.]) | ||
| 3815 | ;; | ||
| 3816 | |||
| 3817 | gnu | netbsd | openbsd ) | ||
| 3818 | AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[ | ||
| 3819 | #ifndef BSD_SYSTEM | ||
| 3820 | # error "BSD_SYSTEM not defined" | ||
| 3821 | #endif | ||
| 3822 | ]], [[]])], [], AC_DEFINE(BSD_SYSTEM, 43) ) | ||
| 3823 | ;; | ||
| 3824 | |||
| 3825 | gnu-linux | gnu-kfreebsd ) | 3806 | gnu-linux | gnu-kfreebsd ) |
| 3826 | AC_DEFINE(USG, []) | 3807 | AC_DEFINE(USG, []) |
| 3827 | AC_DEFINE(GNU_LINUX, [], [Define if ths system is compatible with GNU/Linux.]) | 3808 | AC_DEFINE(GNU_LINUX, [], [Define if ths system is compatible with GNU/Linux.]) |
| @@ -4185,15 +4166,8 @@ case "$opsys" in | |||
| 4185 | LD_SWITCH_SYSTEM_TEMACS="-fno-pie -prebind $libs_nsgui -Xlinker -headerpad -Xlinker $headerpad_extra" | 4166 | LD_SWITCH_SYSTEM_TEMACS="-fno-pie -prebind $libs_nsgui -Xlinker -headerpad -Xlinker $headerpad_extra" |
| 4186 | 4167 | ||
| 4187 | ## This is here because src/Makefile.in did some extra fiddling around | 4168 | ## This is here because src/Makefile.in did some extra fiddling around |
| 4188 | ## with LD_SWITCH_SYSTEM. The cpp logic was: | 4169 | ## with LD_SWITCH_SYSTEM. It seems cleaner to put this in |
| 4189 | ## #ifndef LD_SWITCH_SYSTEM | 4170 | ## LD_SWITCH_SYSTEM_TEMACS instead, |
| 4190 | ## #if !defined (__GNUC__) && ((defined (BSD_SYSTEM) && !defined (COFF))) | ||
| 4191 | ## Since all the *bsds define LD_SWITCH_SYSTEM, this simplifies to: | ||
| 4192 | ## not using gcc, darwin. | ||
| 4193 | ## Because this was done in src/Makefile.in, the resulting part of | ||
| 4194 | ## LD_SWITCH_SYSTEM was not used in configure (ie, in ac_link). | ||
| 4195 | ## It therefore seems cleaner to put this in LD_SWITCH_SYSTEM_TEMACS, | ||
| 4196 | ## rather than LD_SWITCH_SYSTEM. | ||
| 4197 | test "x$LD_SWITCH_SYSTEM" = "x" && test "x$GCC" != "xyes" && \ | 4171 | test "x$LD_SWITCH_SYSTEM" = "x" && test "x$GCC" != "xyes" && \ |
| 4198 | LD_SWITCH_SYSTEM_TEMACS="-X $LD_SWITCH_SYSTEM_TEMACS" | 4172 | LD_SWITCH_SYSTEM_TEMACS="-X $LD_SWITCH_SYSTEM_TEMACS" |
| 4199 | ;; | 4173 | ;; |
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 6ecfb283ff6..d8ec0579422 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog | |||
| @@ -1,5 +1,14 @@ | |||
| 1 | 2013-03-13 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2013-03-13 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | File synchronization fixes (Bug#13944). | ||
| 4 | * Makefile.in (LIB_FDATASYNC): New macro. | ||
| 5 | (emacsclient${EXEEXT}): Use it. | ||
| 6 | * emacsclient.c (main): Use fdatasync, not fsync, since we don't | ||
| 7 | care about metadata. Keep trying if interrupted. | ||
| 8 | * movemail.c (main, popmail): Don't worry about BSD_SYSTEM, since | ||
| 9 | fsync is available everywhere (or there is a substitute). Don't | ||
| 10 | report an error if fsync returns EINVAL. | ||
| 11 | |||
| 3 | Static checking by Sun C 5.12. | 12 | Static checking by Sun C 5.12. |
| 4 | * etags.c (analyse_regex): Omit unreachable code. | 13 | * etags.c (analyse_regex): Omit unreachable code. |
| 5 | 14 | ||
diff --git a/lib-src/Makefile.in b/lib-src/Makefile.in index 8a6960ee2fe..7069af9767a 100644 --- a/lib-src/Makefile.in +++ b/lib-src/Makefile.in | |||
| @@ -161,6 +161,8 @@ LIBRESOLV=@LIBRESOLV@ | |||
| 161 | LIBS_MAIL=@LIBS_MAIL@ | 161 | LIBS_MAIL=@LIBS_MAIL@ |
| 162 | ## empty or -lrt or -lposix4 if HAVE_CLOCK_GETTIME | 162 | ## empty or -lrt or -lposix4 if HAVE_CLOCK_GETTIME |
| 163 | LIB_CLOCK_GETTIME = @LIB_CLOCK_GETTIME@ | 163 | LIB_CLOCK_GETTIME = @LIB_CLOCK_GETTIME@ |
| 164 | ## empty or -lrt or -lposix4 if HAVE_FDATASYNC | ||
| 165 | LIB_FDATASYNC = @LIB_FDATASYNC@ | ||
| 164 | 166 | ||
| 165 | ## Extra libraries to use when linking movemail. | 167 | ## Extra libraries to use when linking movemail. |
| 166 | LIBS_MOVE = $(LIBS_MAIL) $(KRB4LIB) $(DESLIB) $(KRB5LIB) $(CRYPTOLIB) \ | 168 | LIBS_MOVE = $(LIBS_MAIL) $(KRB4LIB) $(DESLIB) $(KRB5LIB) $(CRYPTOLIB) \ |
| @@ -334,7 +336,7 @@ pop.o: ${srcdir}/pop.c ${srcdir}/../lib/min-max.h $(config_h) | |||
| 334 | emacsclient${EXEEXT}: ${srcdir}/emacsclient.c $(config_h) | 336 | emacsclient${EXEEXT}: ${srcdir}/emacsclient.c $(config_h) |
| 335 | $(CC) ${ALL_CFLAGS} ${srcdir}/emacsclient.c \ | 337 | $(CC) ${ALL_CFLAGS} ${srcdir}/emacsclient.c \ |
| 336 | -DVERSION="\"${version}\"" \ | 338 | -DVERSION="\"${version}\"" \ |
| 337 | $(LOADLIBES) -o emacsclient | 339 | $(LOADLIBES) $(LIB_FDATASYNC) -o emacsclient |
| 338 | 340 | ||
| 339 | hexl${EXEEXT}: ${srcdir}/hexl.c $(config_h) | 341 | hexl${EXEEXT}: ${srcdir}/hexl.c $(config_h) |
| 340 | $(CC) ${ALL_CFLAGS} ${srcdir}/hexl.c $(LOADLIBES) -o hexl | 342 | $(CC) ${ALL_CFLAGS} ${srcdir}/hexl.c $(LOADLIBES) -o hexl |
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 6feaf18ba60..898e8d69b07 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c | |||
| @@ -1724,7 +1724,8 @@ main (int argc, char **argv) | |||
| 1724 | needlf = 2; | 1724 | needlf = 2; |
| 1725 | } | 1725 | } |
| 1726 | fflush (stdout); | 1726 | fflush (stdout); |
| 1727 | fsync (1); | 1727 | while (fdatasync (1) != 0 && errno == EINTR) |
| 1728 | continue; | ||
| 1728 | 1729 | ||
| 1729 | /* Now, wait for an answer and print any messages. */ | 1730 | /* Now, wait for an answer and print any messages. */ |
| 1730 | while (exit_status == EXIT_SUCCESS) | 1731 | while (exit_status == EXIT_SUCCESS) |
| @@ -1825,7 +1826,8 @@ main (int argc, char **argv) | |||
| 1825 | if (needlf) | 1826 | if (needlf) |
| 1826 | printf ("\n"); | 1827 | printf ("\n"); |
| 1827 | fflush (stdout); | 1828 | fflush (stdout); |
| 1828 | fsync (1); | 1829 | while (fdatasync (1) != 0 && errno == EINTR) |
| 1830 | continue; | ||
| 1829 | 1831 | ||
| 1830 | if (rl < 0) | 1832 | if (rl < 0) |
| 1831 | exit_status = EXIT_FAILURE; | 1833 | exit_status = EXIT_FAILURE; |
diff --git a/lib-src/movemail.c b/lib-src/movemail.c index 190937d762b..81ac8aa187c 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c | |||
| @@ -466,10 +466,8 @@ main (int argc, char **argv) | |||
| 466 | } | 466 | } |
| 467 | } | 467 | } |
| 468 | 468 | ||
| 469 | #ifdef BSD_SYSTEM | 469 | if (fsync (outdesc) != 0 && errno != EINVAL) |
| 470 | if (fsync (outdesc) < 0) | ||
| 471 | pfatal_and_delete (outname); | 470 | pfatal_and_delete (outname); |
| 472 | #endif | ||
| 473 | 471 | ||
| 474 | /* Prevent symlink attacks truncating other users' mailboxes */ | 472 | /* Prevent symlink attacks truncating other users' mailboxes */ |
| 475 | if (setregid (-1, real_gid) < 0) | 473 | if (setregid (-1, real_gid) < 0) |
| @@ -750,21 +748,14 @@ popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse | |||
| 750 | } | 748 | } |
| 751 | } | 749 | } |
| 752 | 750 | ||
| 753 | /* On AFS, a call to write only modifies the file in the local | 751 | if (fsync (mbfi) != 0 && errno != EINVAL) |
| 754 | * workstation's AFS cache. The changes are not written to the server | ||
| 755 | * until a call to fsync or close is made. Users with AFS home | ||
| 756 | * directories have lost mail when over quota because these checks were | ||
| 757 | * not made in previous versions of movemail. */ | ||
| 758 | |||
| 759 | #ifdef BSD_SYSTEM | ||
| 760 | if (fsync (mbfi) < 0) | ||
| 761 | { | 752 | { |
| 762 | error ("Error in fsync: %s", strerror (errno), 0); | 753 | error ("Error in fsync: %s", strerror (errno), 0); |
| 754 | close (mbfi); | ||
| 763 | return EXIT_FAILURE; | 755 | return EXIT_FAILURE; |
| 764 | } | 756 | } |
| 765 | #endif | ||
| 766 | 757 | ||
| 767 | if (close (mbfi) == -1) | 758 | if (close (mbfi) != 0) |
| 768 | { | 759 | { |
| 769 | error ("Error in close: %s", strerror (errno), 0); | 760 | error ("Error in close: %s", strerror (errno), 0); |
| 770 | return EXIT_FAILURE; | 761 | return EXIT_FAILURE; |
diff --git a/lib/fdatasync.c b/lib/fdatasync.c new file mode 100644 index 00000000000..8f9bf15a527 --- /dev/null +++ b/lib/fdatasync.c | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | /* Emulate fdatasync on platforms that lack it. | ||
| 2 | |||
| 3 | Copyright (C) 2011-2013 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This library is free software; you can redistribute it and/or | ||
| 6 | modify it under the terms of the GNU General Public | ||
| 7 | License as published by the Free Software Foundation; either | ||
| 8 | version 3 of the License, or (at your option) any later version. | ||
| 9 | |||
| 10 | This library is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 13 | General Public License for more details. | ||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License | ||
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 17 | |||
| 18 | #include <config.h> | ||
| 19 | #include <unistd.h> | ||
| 20 | |||
| 21 | int | ||
| 22 | fdatasync (int fd) | ||
| 23 | { | ||
| 24 | /* This does more work than strictly necessary, but is the best we | ||
| 25 | can do portably. */ | ||
| 26 | return fsync (fd); | ||
| 27 | } | ||
diff --git a/lib/fsync.c b/lib/fsync.c new file mode 100644 index 00000000000..8a1a975049e --- /dev/null +++ b/lib/fsync.c | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | /* Emulate fsync on platforms that lack it, primarily Windows and | ||
| 2 | cross-compilers like MinGW. | ||
| 3 | |||
| 4 | This is derived from sqlite3 sources. | ||
| 5 | http://www.sqlite.org/cvstrac/rlog?f=sqlite/src/os_win.c | ||
| 6 | http://www.sqlite.org/copyright.html | ||
| 7 | |||
| 8 | Written by Richard W.M. Jones <rjones.at.redhat.com> | ||
| 9 | |||
| 10 | Copyright (C) 2008-2013 Free Software Foundation, Inc. | ||
| 11 | |||
| 12 | This library is free software; you can redistribute it and/or | ||
| 13 | modify it under the terms of the GNU General Public | ||
| 14 | License as published by the Free Software Foundation; either | ||
| 15 | version 3 of the License, or (at your option) any later version. | ||
| 16 | |||
| 17 | This library is distributed in the hope that it will be useful, | ||
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 20 | General Public License for more details. | ||
| 21 | |||
| 22 | You should have received a copy of the GNU General Public License | ||
| 23 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 24 | |||
| 25 | #include <config.h> | ||
| 26 | #include <unistd.h> | ||
| 27 | |||
| 28 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | ||
| 29 | |||
| 30 | /* FlushFileBuffers */ | ||
| 31 | # define WIN32_LEAN_AND_MEAN | ||
| 32 | # include <windows.h> | ||
| 33 | |||
| 34 | # include <errno.h> | ||
| 35 | |||
| 36 | /* Get _get_osfhandle. */ | ||
| 37 | # include "msvc-nothrow.h" | ||
| 38 | |||
| 39 | int | ||
| 40 | fsync (int fd) | ||
| 41 | { | ||
| 42 | HANDLE h = (HANDLE) _get_osfhandle (fd); | ||
| 43 | DWORD err; | ||
| 44 | |||
| 45 | if (h == INVALID_HANDLE_VALUE) | ||
| 46 | { | ||
| 47 | errno = EBADF; | ||
| 48 | return -1; | ||
| 49 | } | ||
| 50 | |||
| 51 | if (!FlushFileBuffers (h)) | ||
| 52 | { | ||
| 53 | /* Translate some Windows errors into rough approximations of Unix | ||
| 54 | * errors. MSDN is useless as usual - in this case it doesn't | ||
| 55 | * document the full range of errors. | ||
| 56 | */ | ||
| 57 | err = GetLastError (); | ||
| 58 | switch (err) | ||
| 59 | { | ||
| 60 | case ERROR_ACCESS_DENIED: | ||
| 61 | /* For a read-only handle, fsync should succeed, even though we have | ||
| 62 | no way to sync the access-time changes. */ | ||
| 63 | return 0; | ||
| 64 | |||
| 65 | /* eg. Trying to fsync a tty. */ | ||
| 66 | case ERROR_INVALID_HANDLE: | ||
| 67 | errno = EINVAL; | ||
| 68 | break; | ||
| 69 | |||
| 70 | default: | ||
| 71 | errno = EIO; | ||
| 72 | } | ||
| 73 | return -1; | ||
| 74 | } | ||
| 75 | |||
| 76 | return 0; | ||
| 77 | } | ||
| 78 | |||
| 79 | #else /* !Windows */ | ||
| 80 | |||
| 81 | # error "This platform lacks fsync function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib." | ||
| 82 | |||
| 83 | #endif /* !Windows */ | ||
diff --git a/lib/gnulib.mk b/lib/gnulib.mk index c130cbc65b8..4b754ec21dd 100644 --- a/lib/gnulib.mk +++ b/lib/gnulib.mk | |||
| @@ -21,7 +21,7 @@ | |||
| 21 | # the same distribution terms as the rest of that program. | 21 | # the same distribution terms as the rest of that program. |
| 22 | # | 22 | # |
| 23 | # Generated by gnulib-tool. | 23 | # Generated by gnulib-tool. |
| 24 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=dup --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=open --avoid=openat-die --avoid=opendir --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat fcntl-h fdopendir filemode fstatat getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings memrchr mktime pselect pthread_sigmask putenv readlink readlinkat sig2str socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub unsetenv utimens warnings | 24 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=dup --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=open --avoid=openat-die --avoid=opendir --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat fcntl-h fdatasync fdopendir filemode fstatat fsync getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings memrchr mktime pselect pthread_sigmask putenv readlink readlinkat sig2str socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub unsetenv utimens warnings |
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | MOSTLYCLEANFILES += core *.stackdump | 27 | MOSTLYCLEANFILES += core *.stackdump |
| @@ -297,6 +297,15 @@ EXTRA_DIST += fcntl.in.h | |||
| 297 | 297 | ||
| 298 | ## end gnulib module fcntl-h | 298 | ## end gnulib module fcntl-h |
| 299 | 299 | ||
| 300 | ## begin gnulib module fdatasync | ||
| 301 | |||
| 302 | |||
| 303 | EXTRA_DIST += fdatasync.c | ||
| 304 | |||
| 305 | EXTRA_libgnu_a_SOURCES += fdatasync.c | ||
| 306 | |||
| 307 | ## end gnulib module fdatasync | ||
| 308 | |||
| 300 | ## begin gnulib module fdopendir | 309 | ## begin gnulib module fdopendir |
| 301 | 310 | ||
| 302 | 311 | ||
| @@ -332,6 +341,15 @@ EXTRA_libgnu_a_SOURCES += at-func.c fstatat.c | |||
| 332 | 341 | ||
| 333 | ## end gnulib module fstatat | 342 | ## end gnulib module fstatat |
| 334 | 343 | ||
| 344 | ## begin gnulib module fsync | ||
| 345 | |||
| 346 | |||
| 347 | EXTRA_DIST += fsync.c | ||
| 348 | |||
| 349 | EXTRA_libgnu_a_SOURCES += fsync.c | ||
| 350 | |||
| 351 | ## end gnulib module fsync | ||
| 352 | |||
| 335 | ## begin gnulib module getgroups | 353 | ## begin gnulib module getgroups |
| 336 | 354 | ||
| 337 | if gl_GNULIB_ENABLED_getgroups | 355 | if gl_GNULIB_ENABLED_getgroups |
diff --git a/m4/fdatasync.m4 b/m4/fdatasync.m4 new file mode 100644 index 00000000000..551c0d9ff4e --- /dev/null +++ b/m4/fdatasync.m4 | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | # fdatasync.m4 serial 4 | ||
| 2 | dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. | ||
| 3 | dnl This file is free software; the Free Software Foundation | ||
| 4 | dnl gives unlimited permission to copy and/or distribute it, | ||
| 5 | dnl with or without modifications, as long as this notice is preserved. | ||
| 6 | |||
| 7 | AC_DEFUN([gl_FUNC_FDATASYNC], | ||
| 8 | [ | ||
| 9 | AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) | ||
| 10 | |||
| 11 | dnl Using AC_CHECK_FUNCS_ONCE would break our subsequent AC_SEARCH_LIBS | ||
| 12 | AC_CHECK_DECLS_ONCE([fdatasync]) | ||
| 13 | LIB_FDATASYNC= | ||
| 14 | AC_SUBST([LIB_FDATASYNC]) | ||
| 15 | |||
| 16 | if test $ac_cv_have_decl_fdatasync = no; then | ||
| 17 | HAVE_DECL_FDATASYNC=0 | ||
| 18 | dnl Mac OS X 10.7 has fdatasync but does not declare it. | ||
| 19 | AC_CHECK_FUNCS([fdatasync]) | ||
| 20 | if test $ac_cv_func_fdatasync = no; then | ||
| 21 | HAVE_FDATASYNC=0 | ||
| 22 | fi | ||
| 23 | else | ||
| 24 | dnl Solaris <= 2.6 has fdatasync() in libposix4. | ||
| 25 | dnl Solaris 7..10 has it in librt. | ||
| 26 | gl_saved_libs=$LIBS | ||
| 27 | AC_SEARCH_LIBS([fdatasync], [rt posix4], | ||
| 28 | [test "$ac_cv_search_fdatasync" = "none required" || | ||
| 29 | LIB_FDATASYNC=$ac_cv_search_fdatasync]) | ||
| 30 | LIBS=$gl_saved_libs | ||
| 31 | fi | ||
| 32 | ]) | ||
diff --git a/m4/fsync.m4 b/m4/fsync.m4 new file mode 100644 index 00000000000..43f51528d6b --- /dev/null +++ b/m4/fsync.m4 | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | # fsync.m4 serial 2 | ||
| 2 | dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. | ||
| 3 | dnl This file is free software; the Free Software Foundation | ||
| 4 | dnl gives unlimited permission to copy and/or distribute it, | ||
| 5 | dnl with or without modifications, as long as this notice is preserved. | ||
| 6 | |||
| 7 | AC_DEFUN([gl_FUNC_FSYNC], | ||
| 8 | [ | ||
| 9 | AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) | ||
| 10 | AC_CHECK_FUNCS_ONCE([fsync]) | ||
| 11 | if test $ac_cv_func_fsync = no; then | ||
| 12 | HAVE_FSYNC=0 | ||
| 13 | fi | ||
| 14 | ]) | ||
| 15 | |||
| 16 | # Prerequisites of lib/fsync.c. | ||
| 17 | AC_DEFUN([gl_PREREQ_FSYNC], [:]) | ||
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index 6c3012d827f..d304f10b76f 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 | |||
| @@ -63,10 +63,12 @@ AC_DEFUN([gl_EARLY], | |||
| 63 | # Code from module extern-inline: | 63 | # Code from module extern-inline: |
| 64 | # Code from module faccessat: | 64 | # Code from module faccessat: |
| 65 | # Code from module fcntl-h: | 65 | # Code from module fcntl-h: |
| 66 | # Code from module fdatasync: | ||
| 66 | # Code from module fdopendir: | 67 | # Code from module fdopendir: |
| 67 | # Code from module filemode: | 68 | # Code from module filemode: |
| 68 | # Code from module fpending: | 69 | # Code from module fpending: |
| 69 | # Code from module fstatat: | 70 | # Code from module fstatat: |
| 71 | # Code from module fsync: | ||
| 70 | # Code from module getgroups: | 72 | # Code from module getgroups: |
| 71 | # Code from module getloadavg: | 73 | # Code from module getloadavg: |
| 72 | # Code from module getopt-gnu: | 74 | # Code from module getopt-gnu: |
| @@ -187,6 +189,11 @@ AC_DEFUN([gl_INIT], | |||
| 187 | gl_MODULE_INDICATOR([faccessat]) | 189 | gl_MODULE_INDICATOR([faccessat]) |
| 188 | gl_UNISTD_MODULE_INDICATOR([faccessat]) | 190 | gl_UNISTD_MODULE_INDICATOR([faccessat]) |
| 189 | gl_FCNTL_H | 191 | gl_FCNTL_H |
| 192 | gl_FUNC_FDATASYNC | ||
| 193 | if test $HAVE_FDATASYNC = 0; then | ||
| 194 | AC_LIBOBJ([fdatasync]) | ||
| 195 | fi | ||
| 196 | gl_UNISTD_MODULE_INDICATOR([fdatasync]) | ||
| 190 | gl_FUNC_FDOPENDIR | 197 | gl_FUNC_FDOPENDIR |
| 191 | if test $HAVE_FDOPENDIR = 0 || test $REPLACE_FDOPENDIR = 1; then | 198 | if test $HAVE_FDOPENDIR = 0 || test $REPLACE_FDOPENDIR = 1; then |
| 192 | AC_LIBOBJ([fdopendir]) | 199 | AC_LIBOBJ([fdopendir]) |
| @@ -204,6 +211,12 @@ AC_DEFUN([gl_INIT], | |||
| 204 | AC_LIBOBJ([fstatat]) | 211 | AC_LIBOBJ([fstatat]) |
| 205 | fi | 212 | fi |
| 206 | gl_SYS_STAT_MODULE_INDICATOR([fstatat]) | 213 | gl_SYS_STAT_MODULE_INDICATOR([fstatat]) |
| 214 | gl_FUNC_FSYNC | ||
| 215 | if test $HAVE_FSYNC = 0; then | ||
| 216 | AC_LIBOBJ([fsync]) | ||
| 217 | gl_PREREQ_FSYNC | ||
| 218 | fi | ||
| 219 | gl_UNISTD_MODULE_INDICATOR([fsync]) | ||
| 207 | gl_GETLOADAVG | 220 | gl_GETLOADAVG |
| 208 | if test $HAVE_GETLOADAVG = 0; then | 221 | if test $HAVE_GETLOADAVG = 0; then |
| 209 | AC_LIBOBJ([getloadavg]) | 222 | AC_LIBOBJ([getloadavg]) |
| @@ -743,12 +756,14 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
| 743 | lib/execinfo.in.h | 756 | lib/execinfo.in.h |
| 744 | lib/faccessat.c | 757 | lib/faccessat.c |
| 745 | lib/fcntl.in.h | 758 | lib/fcntl.in.h |
| 759 | lib/fdatasync.c | ||
| 746 | lib/fdopendir.c | 760 | lib/fdopendir.c |
| 747 | lib/filemode.c | 761 | lib/filemode.c |
| 748 | lib/filemode.h | 762 | lib/filemode.h |
| 749 | lib/fpending.c | 763 | lib/fpending.c |
| 750 | lib/fpending.h | 764 | lib/fpending.h |
| 751 | lib/fstatat.c | 765 | lib/fstatat.c |
| 766 | lib/fsync.c | ||
| 752 | lib/ftoastr.c | 767 | lib/ftoastr.c |
| 753 | lib/ftoastr.h | 768 | lib/ftoastr.h |
| 754 | lib/getgroups.c | 769 | lib/getgroups.c |
| @@ -842,10 +857,12 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
| 842 | m4/faccessat.m4 | 857 | m4/faccessat.m4 |
| 843 | m4/fcntl-o.m4 | 858 | m4/fcntl-o.m4 |
| 844 | m4/fcntl_h.m4 | 859 | m4/fcntl_h.m4 |
| 860 | m4/fdatasync.m4 | ||
| 845 | m4/fdopendir.m4 | 861 | m4/fdopendir.m4 |
| 846 | m4/filemode.m4 | 862 | m4/filemode.m4 |
| 847 | m4/fpending.m4 | 863 | m4/fpending.m4 |
| 848 | m4/fstatat.m4 | 864 | m4/fstatat.m4 |
| 865 | m4/fsync.m4 | ||
| 849 | m4/getgroups.m4 | 866 | m4/getgroups.m4 |
| 850 | m4/getloadavg.m4 | 867 | m4/getloadavg.m4 |
| 851 | m4/getopt.m4 | 868 | m4/getopt.m4 |
diff --git a/nt/ChangeLog b/nt/ChangeLog index dcda682cfc6..48c1cb8bc82 100644 --- a/nt/ChangeLog +++ b/nt/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2013-03-13 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | File synchronization fixes (Bug#13944). | ||
| 4 | * inc/ms-w32.h (fdatasync): New macro, suggested by Eli Zaretskii. | ||
| 5 | |||
| 1 | 2013-03-05 Paul Eggert <eggert@cs.ucla.edu> | 6 | 2013-03-05 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 7 | ||
| 3 | FILE's lock is now always .#FILE and may be a regular file (Bug#13807). | 8 | FILE's lock is now always .#FILE and may be a regular file (Bug#13807). |
diff --git a/nt/inc/ms-w32.h b/nt/inc/ms-w32.h index 9473fbe3ca6..12402390895 100644 --- a/nt/inc/ms-w32.h +++ b/nt/inc/ms-w32.h | |||
| @@ -220,6 +220,7 @@ extern int sys_unlink (const char *); | |||
| 220 | /* Map to MSVC names. */ | 220 | /* Map to MSVC names. */ |
| 221 | #define execlp _execlp | 221 | #define execlp _execlp |
| 222 | #define execvp _execvp | 222 | #define execvp _execvp |
| 223 | #define fdatasync _commit | ||
| 223 | #define fdopen _fdopen | 224 | #define fdopen _fdopen |
| 224 | #ifndef fileno | 225 | #ifndef fileno |
| 225 | #define fileno _fileno | 226 | #define fileno _fileno |
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 |