public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* gzip-1.7-1 regression: cannot redirect output of gzip -l
@ 2016-04-19 11:21 Christian Franke
  2016-04-19 14:28 ` Eric Blake
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Franke @ 2016-04-19 11:21 UTC (permalink / raw)
  To: cygwin

gzip-1.7-1 reports a write error if result of -l is redirected:

$ uname -srvm
CYGWIN_NT-6.1-WOW 2.5.0(0.297/5/3) 2016-04-11 09:55 i686

$ cygcheck -f /bin/gzip
gzip-1.7-1

$ echo text | gzip > text.gz

$ gzip -l text.gz
         compressed        uncompressed  ratio uncompressed_name
                 25                   5 -40.0% text

$ gzip -l text.gz | cat
gzip: write error: Bad file descriptor

$ gzip -l text.gz > out
gzip: write error: Bad file descriptor

This breaks (at least) the zforce script.

gzip -c is not affected.

Christian


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gzip-1.7-1 regression: cannot redirect output of gzip -l
  2016-04-19 11:21 gzip-1.7-1 regression: cannot redirect output of gzip -l Christian Franke
@ 2016-04-19 14:28 ` Eric Blake
  2016-04-20  1:34   ` bug#23314: " Paul Eggert
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Blake @ 2016-04-19 14:28 UTC (permalink / raw)
  To: cygwin, bug-gzip

[-- Attachment #1: Type: text/plain, Size: 827 bytes --]

On 04/19/2016 03:49 AM, Christian Franke wrote:
> gzip-1.7-1 reports a write error if result of -l is redirected:
> 
> $ uname -srvm
> CYGWIN_NT-6.1-WOW 2.5.0(0.297/5/3) 2016-04-11 09:55 i686
> 
> $ cygcheck -f /bin/gzip
> gzip-1.7-1
> 
> $ echo text | gzip > text.gz
> 
> $ gzip -l text.gz
>          compressed        uncompressed  ratio uncompressed_name
>                  25                   5 -40.0% text
> 
> $ gzip -l text.gz | cat
> gzip: write error: Bad file descriptor

Thanks for the report; I can confirm the problem exists upstream, so I'm
redirecting your report there.

$ ./gzip -l text.gz | cat
./gzip: write error: Bad file descriptor
$ git describe HEAD
v1.7-2-ga420fba

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: bug#23314: gzip-1.7-1 regression: cannot redirect output of gzip -l
  2016-04-19 14:28 ` Eric Blake
@ 2016-04-20  1:34   ` Paul Eggert
  2016-04-20  5:57     ` Paul Eggert
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Eggert @ 2016-04-20  1:34 UTC (permalink / raw)
  To: 23314-done, Christian Franke
  Cc: Eric Blake, cygwin, Giorgio Ciucci, John Stanley

[-- Attachment #1: Type: text/plain, Size: 84 bytes --]

Thanks for reporting the problem. I installed the attached gzip patch on 
savannah.

[-- Attachment #2: 0001-gzip-fix-bug-with-l-output-to-pipes.patch --]
[-- Type: application/x-patch, Size: 3589 bytes --]

[-- Attachment #3: Type: text/plain, Size: 218 bytes --]

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: bug#23314: gzip-1.7-1 regression: cannot redirect output of gzip -l
  2016-04-20  1:34   ` bug#23314: " Paul Eggert
@ 2016-04-20  5:57     ` Paul Eggert
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Eggert @ 2016-04-20  5:57 UTC (permalink / raw)
  To: 23314-done; +Cc: Eric Blake, cygwin

[-- Attachment #1: Type: text/plain, Size: 215 bytes --]

Come to think of it, that part of gzip can be simplified considerably, which 
should make future problems like this less likely. I installed the attached 
additional patch. Yay, 46 fewer files in the gzip tarball!


[-- Attachment #2: 0001-gzip-simplify-by-closing-ourselves.patch --]
[-- Type: text/x-diff, Size: 5459 bytes --]

From 02b67e301e66c8641230afbe8663f2d503c0f57b Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Tue, 19 Apr 2016 22:05:57 -0700
Subject: [PATCH] gzip: simplify by closing ourselves

This simplifies the previous fix, by avoiding the use of the
closein module.  That module was problematic, as gzip normally
does not use stdio for output and never uses it for input.
Also, it is a heavyweight module, as it drags many files into lib
(c-ctype.c, c-ctype.h, closein.c, closein.h, closeout.c, closeout.h,
close-stream.c, close-stream.h, config.charset, c-strcasecmp.c,
c-strcaseeq.h, c-strcase.h, c-strncasecmp.c, fpending.c, fpending.h,
freadahead.c, freadahead.h, localcharset.c, localcharset.h, mbrtowc.c,
mbsinit.c, quotearg.c, quotearg.h, quote.h, ref-add.sin, ref-del.sin,
streq.h, wctype-h.c, wctype.in.h) and into m4 (closein.m4, closeout.m4,
close-stream.m4, codeset.m4, configmake.m4, fpending.m4, freadahead.m4,
glibc21.m4, localcharset.m4, locale-fr.m4, locale-ja.m4, locale-zh.m4,
mbrtowc.m4, mbsinit.m4, mbstate_t.m4, quotearg.m4, wctype_h.m4),
and these files are thus no longer needed.
* bootstrap.conf (gnulib_modules): Remove closein.
* gzip.c: Don't include closein.h.
(stdin_was_read): New static var.
(main): Don't use close_stdin.
Invoke finish_out to exit after outputting via stdio's stdout.
Close stdin after reading it.
Restore previous way of closing stdout.
(treat_stdin): Record that stdin was read.
(finish_out): New function.
---
 bootstrap.conf |  1 -
 gzip.c         | 33 +++++++++++++++++++++++++--------
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 25acaac..6cbaaa2 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -24,7 +24,6 @@ gnulib_modules='
 announce-gen
 calloc
 close
-closein
 dirname-lgpl
 fclose
 fcntl
diff --git a/gzip.c b/gzip.c
index 3b8de4d..4a51b13 100644
--- a/gzip.c
+++ b/gzip.c
@@ -63,7 +63,6 @@ static char const *const license_msg[] = {
 #include <sys/stat.h>
 #include <errno.h>
 
-#include "closein.h"
 #include "tailor.h"
 #include "gzip.h"
 #include "intprops.h"
@@ -206,6 +205,8 @@ static int volatile exiting_signal;
 /* If nonnegative, close this file descriptor and unlink ofname on error.  */
 static int volatile remove_ofname_fd = -1;
 
+static bool stdin_was_read;
+
 off_t bytes_in;             /* number of input bytes */
 off_t bytes_out;            /* number of output bytes */
 static off_t total_in;      /* input bytes for all files */
@@ -317,6 +318,7 @@ local void install_signal_handlers (void);
 local void remove_output_file (void);
 local RETSIGTYPE abort_gzip_signal (int);
 local void do_exit      (int exitcode) ATTRIBUTE_NORETURN;
+static void finish_out (void);
       int main          (int argc, char **argv);
 static int (*work) (int infile, int outfile) = zip; /* function to call */
 
@@ -427,8 +429,6 @@ int main (int argc, char **argv)
     program_name = gzip_base_name (argv[0]);
     proglen = strlen (program_name);
 
-    atexit (close_stdin);
-
     /* Suppress .exe for MSDOS, OS/2 and VMS: */
     if (4 < proglen && strequ (program_name + proglen - 4, ".exe"))
       program_name[proglen - 4] = '\0';
@@ -527,13 +527,13 @@ int main (int argc, char **argv)
         case 'f':
             force++; break;
         case 'h': case 'H':
-            help(); do_exit(OK); break;
+            help (); finish_out (); break;
         case 'k':
             keep = 1; break;
         case 'l':
             list = decompress = to_stdout = 1; break;
         case 'L':
-            license(); do_exit(OK); break;
+            license (); finish_out (); break;
         case 'm': /* undocumented, may change later */
             no_time = 1; break;
         case 'M': /* undocumented, may change later */
@@ -580,7 +580,7 @@ int main (int argc, char **argv)
         case 'v' + ENV_OPTION:
             verbose++; quiet = 0; break;
         case 'V':
-            version(); do_exit(OK); break;
+            version (); finish_out (); break;
         case 'Z':
 #ifdef LZW
             do_lzw = 1; break;
@@ -664,6 +664,11 @@ int main (int argc, char **argv)
     } else {  /* Standard input */
         treat_stdin();
     }
+    if (stdin_was_read && close (STDIN_FILENO) != 0)
+      {
+        strcpy (ifname, "stdin");
+        read_error ();
+      }
     if (list)
       {
         /* Output any totals, and check for output errors.  */
@@ -672,8 +677,11 @@ int main (int argc, char **argv)
         if (fflush (stdout) != 0)
           write_error ();
       }
-    if (to_stdout && synchronous && fdatasync (STDOUT_FILENO) != 0
-        && errno != EINVAL && errno != EBADF)
+    if (to_stdout
+        && ((synchronous
+             && fdatasync (STDOUT_FILENO) != 0 && errno != EINVAL)
+            || close (STDOUT_FILENO) != 0)
+        && errno != EBADF)
       write_error ();
     do_exit(exit_code);
     return exit_code; /* just to avoid lint warning */
@@ -759,6 +767,7 @@ local void treat_stdin()
     to_stdout = 1;
     part_nb = 0;
     ifd = STDIN_FILENO;
+    stdin_was_read = true;
 
     if (decompress) {
         method = get_method(ifd);
@@ -2093,6 +2102,14 @@ local void do_exit(exitcode)
     exit(exitcode);
 }
 
+static void
+finish_out (void)
+{
+  if (fclose (stdout) != 0)
+    write_error ();
+  do_exit (OK);
+}
+
 /* ========================================================================
  * Close and unlink the output file.
  */
-- 
2.5.5



[-- Attachment #3: Type: text/plain, Size: 218 bytes --]

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-20  5:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-19 11:21 gzip-1.7-1 regression: cannot redirect output of gzip -l Christian Franke
2016-04-19 14:28 ` Eric Blake
2016-04-20  1:34   ` bug#23314: " Paul Eggert
2016-04-20  5:57     ` Paul Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).