04f3d29
diff -urp bison-2.4-pm/lib/subpipe.c bison-2.4/lib/subpipe.c
04f3d29
--- bison-2.4-pm/lib/subpipe.c	2008-07-14 10:56:12.000000000 +0200
04f3d29
+++ bison-2.4/lib/subpipe.c	2008-11-20 14:37:42.000000000 +0100
04f3d29
@@ -143,7 +143,9 @@ create_subpipe (char const * const *argv
04f3d29
 }
04f3d29
 
04f3d29
 
04f3d29
-/* Wait for the subprocess to exit.  */
04f3d29
+/* Wait for the subprocess to exit.  PROGRAM==NULL means errors
04f3d29
+   shouldn't be emitted, typically becuase we are reaping the subpipe
04f3d29
+   in response to some other error. */
04f3d29
 
04f3d29
 void
04f3d29
 reap_subpipe (pid_t pid, char const *program)
04f3d29
@@ -151,11 +153,14 @@ reap_subpipe (pid_t pid, char const *pro
04f3d29
 #if HAVE_WAITPID || defined waitpid
04f3d29
   int wstatus;
04f3d29
   if (waitpid (pid, &wstatus, 0) < 0)
04f3d29
-    error (EXIT_FAILURE, errno, "waitpid");
04f3d29
+    {
04f3d29
+      if (program)
04f3d29
+	error (EXIT_FAILURE, errno, "waitpid");
04f3d29
+    }
04f3d29
   else
04f3d29
     {
04f3d29
       int status = WIFEXITED (wstatus) ? WEXITSTATUS (wstatus) : -1;
04f3d29
-      if (status)
04f3d29
+      if (status && program)
04f3d29
 	error (EXIT_FAILURE, 0,
04f3d29
 	       _(status == 126
04f3d29
 		 ? "subsidiary program `%s' could not be invoked"
04f3d29
diff -urp bison-2.4-pm/src/output.c bison-2.4/src/output.c
04f3d29
--- bison-2.4-pm/src/output.c	2008-11-02 19:09:10.000000000 +0100
04f3d29
+++ bison-2.4/src/output.c	2008-11-20 14:39:08.000000000 +0100
04f3d29
@@ -467,6 +467,21 @@ prepare_actions (void)
04f3d29
 | Call the skeleton parser.  |
04f3d29
 `---------------------------*/
04f3d29
 
04f3d29
+static pid_t pid = 0;
04f3d29
+
04f3d29
+/* Clean up opened pipe. */
04f3d29
+static void
04f3d29
+die (void)
04f3d29
+{
04f3d29
+  static int dying = 0;
04f3d29
+  if (pid && !dying)
04f3d29
+    {
04f3d29
+      dying = 1;
04f3d29
+      reap_subpipe (pid, NULL);
04f3d29
+      pid = 0;
04f3d29
+    }
04f3d29
+}
04f3d29
+
04f3d29
 static void
04f3d29
 output_skeleton (void)
04f3d29
 {
04f3d29
@@ -474,7 +489,6 @@ output_skeleton (void)
04f3d29
   FILE *out;
04f3d29
   int filter_fd[2];
04f3d29
   char const *argv[9];
04f3d29
-  pid_t pid;
04f3d29
 
04f3d29
   /* Compute the names of the package data dir and skeleton files.  */
04f3d29
   char const m4sugar[] = "m4sugar/m4sugar.m4";
04f3d29
@@ -586,6 +600,7 @@ output_skeleton (void)
04f3d29
   scan_skel (in);
04f3d29
   xfclose (in);
04f3d29
   reap_subpipe (pid, m4);
04f3d29
+  pid = 0;
04f3d29
   timevar_pop (TV_M4);
04f3d29
 }
04f3d29
 
04f3d29
@@ -653,6 +669,14 @@ prepare (void)
04f3d29
 void
04f3d29
 output (void)
04f3d29
 {
04f3d29
+  /* Register shutdown handler.  */
04f3d29
+  static int registered = 0;
04f3d29
+  if (!registered)
04f3d29
+    {
04f3d29
+      registered = 1;
04f3d29
+      atexit (die);
04f3d29
+    }
04f3d29
+
04f3d29
   obstack_init (&format_obstack);
04f3d29
 
04f3d29
   prepare_symbols ();