* gzip.c (handled_sig): Move out of install_signal_handlers, and
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 25 Nov 2007 17:19:45 +0000 (17:19 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 25 Nov 2007 17:19:45 +0000 (17:19 +0000)
move previous to all uses of SIGPIPE, to fix a bug encountered when
porting to mingw32.  Reported by Robert Millan in
<http://lists.gnu.org/archive/html/bug-gzip/2007-11/msg00007.html>.

ChangeLog
gzip.c

index 474efe782b08184c8729d27fa5ae692cf8e4b9da..e220819b316261a79e1b742e444ba056a6f39bc2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-11-25  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * gzip.c (handled_sig): Move out of install_signal_handlers, and
+       move previous to all uses of SIGPIPE, to fix a bug encountered when
+       porting to mingw32.  Reported by Robert Millan in
+       <http://lists.gnu.org/archive/html/bug-gzip/2007-11/msg00007.html>.
+
 2007-10-04  Paul Eggert  <eggert@cs.ucla.edu>
 
        * doc/gzip.texi: Adjust to new fdl.texi format, in gnulib.
diff --git a/gzip.c b/gzip.c
index 7de582da39dcd0fc146100ed354adef76c8aede1..b8916c1010c33ca24beb73eeb90c3de8c50826a7 100644 (file)
--- a/gzip.c
+++ b/gzip.c
@@ -232,6 +232,30 @@ unsigned insize;           /* valid bytes in inbuf */
 unsigned inptr;            /* index of next byte to be processed in inbuf */
 unsigned outcnt;           /* bytes in output buffer */
 
+static int handled_sig[] =
+  {
+    /* SIGINT must be first, as 'foreground' depends on it.  */
+    SIGINT
+
+#ifdef SIGHUP
+    , SIGHUP
+#endif
+#ifdef SIGPIPE
+    , SIGPIPE
+#else
+# define SIGPIPE 0
+#endif
+#ifdef SIGTERM
+    , SIGTERM
+#endif
+#ifdef SIGXCPU
+    , SIGXCPU
+#endif
+#ifdef SIGXFSZ
+    , SIGXFSZ
+#endif
+  };
+
 struct option longopts[] =
 {
  /* { name  has_arg  *flag  val } */
@@ -1755,30 +1779,7 @@ local void treat_dir (fd, dir)
 static void
 install_signal_handlers ()
 {
-  static int sig[] =
-    {
-      /* SIGINT must be first, as 'foreground' depends on it.  */
-      SIGINT
-
-#ifdef SIGHUP
-      , SIGHUP
-#endif
-#ifdef SIGPIPE
-      , SIGPIPE
-#else
-# define SIGPIPE 0
-#endif
-#ifdef SIGTERM
-      , SIGTERM
-#endif
-#ifdef SIGXCPU
-      , SIGXCPU
-#endif
-#ifdef SIGXFSZ
-      , SIGXFSZ
-#endif
-    };
-  int nsigs = sizeof sig / sizeof sig[0];
+  int nsigs = sizeof handled_sig / sizeof handled_sig[0];
   int i;
 
 #if SA_NOCLDSTOP
@@ -1787,9 +1788,9 @@ install_signal_handlers ()
   sigemptyset (&caught_signals);
   for (i = 0; i < nsigs; i++)
     {
-      sigaction (sig[i], NULL, &act);
+      sigaction (handled_sig[i], NULL, &act);
       if (act.sa_handler != SIG_IGN)
-       sigaddset (&caught_signals, sig[i]);
+       sigaddset (&caught_signals, handled_sig[i]);
     }
 
   act.sa_handler = abort_gzip_signal;
@@ -1797,20 +1798,20 @@ install_signal_handlers ()
   act.sa_flags = 0;
 
   for (i = 0; i < nsigs; i++)
-    if (sigismember (&caught_signals, sig[i]))
+    if (sigismember (&caught_signals, handled_sig[i]))
       {
        if (i == 0)
          foreground = 1;
-       sigaction (sig[i], &act, NULL);
+       sigaction (handled_sig[i], &act, NULL);
       }
 #else
   for (i = 0; i < nsigs; i++)
-    if (signal (sig[i], SIG_IGN) != SIG_IGN)
+    if (signal (handled_sig[i], SIG_IGN) != SIG_IGN)
       {
        if (i == 0)
          foreground = 1;
-       signal (sig[i], abort_gzip_signal);
-       siginterrupt (sig[i], 1);
+       signal (handled_sig[i], abort_gzip_signal);
+       siginterrupt (handled_sig[i], 1);
       }
 #endif
 }