Explorar o código

libdpkg: Do not handle EINTR in compression code

The current callers for the compression code do not install signal
handlers, so there is no occasion to test the EINTR handling.
Perhaps for this reason, since commit 7bf6e0 (add support for using
libz, 2000-12-09) when the current compression/decompression code
was introduced, the EINTR handling has been broken in a number of
ways:

 * Interrupted reads were treated as end of file until very recently.
 * Interrupted writes during decompression cause portions of the
   output to be discarded.
 * Interrupted writes during compression are treated as errors,
   unless the interruption happens before any data from the output
   buffer can be consumed.

Since zlib at least cannot recover from an interrupted write anyway,
it seems better to always treat EINTR like any other error. For now
callers should specify the SA_RESTART flag when installing signal
handlers for correct behavior on System V style operating systems
(such as Solaris).

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Guillem Jover <guillem@debian.org>
Jonathan Nieder %!s(int64=16) %!d(string=hai) anos
pai
achega
c9d8174c1b
Modificáronse 1 ficheiros con 9 adicións e 19 borrados
  1. 9 19
      lib/dpkg/compress.c

+ 9 - 19
lib/dpkg/compress.c

@@ -83,10 +83,9 @@ decompress_cat(enum compress_type type, int fd_in, int fd_out,
           if (actualread < 0 ) {
             int err = 0;
             const char *errmsg = gzerror(gzfile, &err);
-            if (err == Z_ERRNO) {
-              if (errno == EINTR) continue;
+
+            if (err == Z_ERRNO)
               errmsg= strerror(errno);
-            }
             ohshit(_("%s: internal gzip read error: '%s'"), v.buf, errmsg);
           }
           if (actualread == 0) /* EOF. */
@@ -112,10 +111,9 @@ decompress_cat(enum compress_type type, int fd_in, int fd_out,
           if (actualread < 0 ) {
             int err = 0;
             const char *errmsg = BZ2_bzerror(bzfile, &err);
-            if (err == BZ_IO_ERROR) {
-              if (errno == EINTR) continue;
+
+            if (err == BZ_IO_ERROR)
               errmsg= strerror(errno);
-            }
             ohshit(_("%s: internal bzip2 read error: '%s'"), v.buf, errmsg);
           }
           if (actualread == 0) /* EOF. */
@@ -168,10 +166,8 @@ compress_cat(enum compress_type type, int fd_in, int fd_out,
           int actualread, actualwrite;
 
           actualread = read(fd_in, buffer, sizeof(buffer));
-          if (actualread < 0 ) {
-            if (errno == EINTR) continue;
+          if (actualread < 0)
             ohshite(_("%s: internal gzip read error"), v.buf);
-          }
           if (actualread == 0) /* EOF. */
             break;
 
@@ -179,10 +175,8 @@ compress_cat(enum compress_type type, int fd_in, int fd_out,
           if (actualwrite != actualread) {
             int err = 0;
             const char *errmsg = gzerror(gzfile, &err);
-            if (err == Z_ERRNO) {
-              if (errno == EINTR) continue;
-            errmsg= strerror(errno);
-            }
+            if (err == Z_ERRNO)
+              errmsg = strerror(errno);
             ohshit(_("%s: internal gzip write error: '%s'"), v.buf, errmsg);
           }
         }
@@ -207,10 +201,8 @@ compress_cat(enum compress_type type, int fd_in, int fd_out,
           int actualread, actualwrite;
 
           actualread = read(fd_in, buffer, sizeof(buffer));
-          if (actualread < 0 ) {
-            if (errno == EINTR) continue;
+          if (actualread < 0)
             ohshite(_("%s: internal bzip2 read error"), v.buf);
-          }
           if (actualread == 0) /* EOF. */
             break;
 
@@ -218,10 +210,8 @@ compress_cat(enum compress_type type, int fd_in, int fd_out,
           if (actualwrite != actualread) {
             int err = 0;
             const char *errmsg = BZ2_bzerror(bzfile, &err);
-            if (err == BZ_IO_ERROR) {
-              if (errno == EINTR) continue;
+            if (err == BZ_IO_ERROR)
               errmsg= strerror(errno);
-            }
             ohshit(_("%s: internal bzip2 write error: '%s'"), v.buf, errmsg);
           }
         }