bug-coreutils
[Top][All Lists]
Advanced

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

coreutils patch to port to hosts lacking fsync


From: Paul Eggert
Subject: coreutils patch to port to hosts lacking fsync
Date: Tue, 19 Dec 2006 11:29:31 -0800
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

"Matthew Woehlke" <address@hidden> writes:

> "shred" is sort-of in the same boat due to lacking fsync()

I don't recall that problem but it is easy enough to fix.  Here's
a patch.

2006-12-19  Paul Eggert  <address@hidden>

        * m4/jm-macros.m4 (coreutils_MACROS): Check for fsync.
        * src/dd.c (fsync) [! HAVE_FSYNC]: Define.
        (dd_copy): Fall back on sync if fsync isn't available.
        * src/shred.c (dosync) [! HAVE_FSYNC]: Likewise.
        * src/dd.c (dd_copy): Check for EINTR from fdatasync, for
        consistency with fsync.

diff --git a/m4/jm-macros.m4 b/m4/jm-macros.m4
index fe9970b..1ef8c32 100644
--- a/m4/jm-macros.m4
+++ b/m4/jm-macros.m4
@@ -1,4 +1,4 @@
-#serial 105   -*- autoconf -*-
+#serial 106   -*- autoconf -*-

 dnl Misc type-related macros for coreutils.

@@ -77,6 +77,7 @@ AC_DEFUN([coreutils_MACROS],
   cu_PREREQ_STAT_PROG

   # for dd.c and shred.c
+  AC_CHECK_FUNCS_ONCE(fsync)
   coreutils_saved_libs=$LIBS
     AC_SEARCH_LIBS([fdatasync], [rt posix4],
                   [test "$ac_cv_search_fdatasync" = "none required" ||
diff --git a/src/dd.c b/src/dd.c
index 3449e12..35c0a43 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -68,6 +68,10 @@ static void process_signals (void);
 # define fdatasync(fd) (errno = ENOSYS, -1)
 #endif

+#if ! HAVE_FSYNC
+# define fsync(fd) (errno = ENOSYS, -1)
+#endif
+
 #define max(a, b) ((a) > (b) ? (a) : (b))
 #define output_char(c)                         \
   do                                           \
@@ -1602,22 +1606,31 @@ dd_copy (void)
        }
     }

-  if ((conversions_mask & C_FDATASYNC) && fdatasync (STDOUT_FILENO) != 0)
-    {
-      if (errno != ENOSYS && errno != EINVAL)
+  if (conversions_mask & C_FDATASYNC)
+    while (fdatasync (STDOUT_FILENO) != 0)
+      if (errno != EINTR)
        {
-         error (0, errno, _("fdatasync failed for %s"), quote (output_file));
-         exit_status = EXIT_FAILURE;
+         if (errno != ENOSYS && errno != EINVAL)
+           {
+             error (0, errno, _("fdatasync failed for %s"),
+                    quote (output_file));
+             exit_status = EXIT_FAILURE;
+           }
+         conversions_mask |= C_FSYNC;
+         break;
        }
-      conversions_mask |= C_FSYNC;
-    }

   if (conversions_mask & C_FSYNC)
     while (fsync (STDOUT_FILENO) != 0)
       if (errno != EINTR)
        {
-         error (0, errno, _("fsync failed for %s"), quote (output_file));
-         return EXIT_FAILURE;
+         if (errno != ENOSYS)
+           {
+             error (0, errno, _("fsync failed for %s"), quote (output_file));
+             exit_status = EXIT_FAILURE;
+           }
+         sync ();
+         break;
        }

   return exit_status;
diff --git a/src/shred.c b/src/shred.c
index 23a4944..d574cc7 100644
--- a/src/shred.c
+++ b/src/shred.c
@@ -306,6 +306,7 @@ dosync (int fd, char const *qname)
     }
 #endif

+#if HAVE_FSYNC
   if (fsync (fd) == 0)
     return 0;
   err = errno;
@@ -315,6 +316,7 @@ dosync (int fd, char const *qname)
       errno = err;
       return -1;
     }
+#endif

   sync ();
   return 0;
M ChangeLog
M m4/jm-macros.m4
M src/dd.c
M src/shred.c
Committed as 20795afc6dd68a1116c30a00f1c6c99e0a850b6f




reply via email to

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