bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] af_alg: distiguish I/O errors better


From: Paul Eggert
Subject: [PATCH] af_alg: distiguish I/O errors better
Date: Wed, 9 May 2018 12:05:39 -0700

* lib/af_alg.c (afalg_buffer, afalg_stream): Return -EAFNOSUPPORT,
not -EIO, if it’s OK for the caller to try again with user-mode code.
(afalg_stream) [!_WIN32 || __CYGWIN__]: Return -EIO (not possibly
some other error number) if fflush fails, as the caller should not
try again that case.
---
 ChangeLog    |  7 +++++++
 lib/af_alg.c | 16 ++++------------
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9c40bd672..3a9dc63ec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2018-05-09  Paul Eggert  <address@hidden>
 
+       af_alg: distiguish I/O errors better
+       * lib/af_alg.c (afalg_buffer, afalg_stream): Return -EAFNOSUPPORT,
+       not -EIO, if it’s OK for the caller to try again with user-mode code.
+       (afalg_stream) [!_WIN32 || __CYGWIN__]: Return -EIO (not possibly
+       some other error number) if fflush fails, as the caller should not
+       try again that case.
+
        af_alg: avoid gotos
        * lib/af_alg.c (afalg_buffer, afalg_stream): Rewrite to avoid
        gotos, as they were a source of unreliability and made the code a
diff --git a/lib/af_alg.c b/lib/af_alg.c
index 64bde8d74..cfc31529a 100644
--- a/lib/af_alg.c
+++ b/lib/af_alg.c
@@ -79,14 +79,14 @@ afalg_buffer (const char *buffer, size_t len, const char 
*alg,
       ssize_t size = (len > BLOCKSIZE ? BLOCKSIZE : len);
       if (send (ofd, buffer, size, MSG_MORE) != size)
         {
-          result = -EIO;
+          result = -EAFNOSUPPORT;
           break;
         }
       buffer += size;
       len -= size;
       if (len == 0)
         {
-          result = read (ofd, resblock, hashlen) == hashlen ? -EIO: 0;
+          result = read (ofd, resblock, hashlen) == hashlen ? -EAFNOSUPPORT: 0;
           break;
         }
     }
@@ -116,22 +116,14 @@ afalg_stream (FILE *stream, const char *alg,
          Note: fflush on an input stream after ungetc does not work as expected
          on some platforms.  Therefore this situation is not supported here.  
*/
       if (fflush (stream))
-        {
-#if defined _WIN32 && ! defined __CYGWIN__
-          result = -EIO;
-#else
-          result = -errno;
-#endif
-        }
+        result = -EIO;
       else
         {
           off_t nbytes = st.st_size - lseek (fd, 0, SEEK_CUR);
           /* On Linux < 4.9, the value for an empty stream is wrong (all 0).
              See <https://patchwork.kernel.org/patch/9308641/>.  */
-          if (nbytes <= 0)
+          if (nbytes <= 0 || sendfile (ofd, fd, NULL, nbytes) != nbytes)
             result = -EAFNOSUPPORT;
-          else if (sendfile (ofd, fd, NULL, nbytes) != nbytes)
-            result = -EIO;
         }
     }
   else
-- 
2.17.0




reply via email to

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