Allow pipe filters to signal when they are interrupted again
authorReuben Thomas <rrt@sc3d.org>
Mon, 22 Jan 2018 23:35:27 +0000 (23:35 +0000)
committerReuben Thomas <rrt@sc3d.org>
Tue, 23 Jan 2018 07:16:19 +0000 (07:16 +0000)
Make the interrupted variable, previously static in main,
recode_interrupted, defined in task.c (hence in librecode), so that it can
now be tested at the end of a pipe recode.

src/main.c
src/recodext.h
src/task.c

index 154d48c1ab08a4df157bc9f5812e6c56f07c7abe..fa3c5f0e602de3c749f133b6405dbf1c30639b3c 100644 (file)
@@ -134,12 +134,10 @@ task_perror (RECODE_CONST_TASK task)
 | Signal handler.  |
 `-----------------*/
 
-static bool interrupted = 0;   /* set when some signal has been received */
-
 static void
 signal_handler (int number)
 {
-  interrupted = 1;
+  recode_interrupted = 1;
   signal (number, signal_handler);
 }
 
index 100c5f471be6e6e2c7b83cf07950d96174cc7a6d..b453d815a5187509a0f9106435075a2dbb5700a4 100644 (file)
@@ -234,6 +234,8 @@ struct recode_surface_list
 | Description of a single step of recoding.  |
 `-------------------------------------------*/
 
+extern bool recode_interrupted;
+
 typedef bool (*Recode_init) (RECODE_STEP, RECODE_CONST_REQUEST,
                              RECODE_CONST_OPTION_LIST,
                              RECODE_CONST_OPTION_LIST);
index 04a15dfb5e123a2fdf586b36a0a6b2e026acc053..11fd977b4c8439bb2073308b9e65a87ef8f8a35a 100644 (file)
@@ -26,6 +26,8 @@
 
 #include "xbinary-io.h"
 
+bool recode_interrupted = 0;   /* set by signal handler when some signal has been received */
+
 /* Buffer size used in transform_mere_copy.  */
 #define BUFFER_SIZE (16 * 1024)
 \f
@@ -275,15 +277,15 @@ perform_sequence (RECODE_TASK task, enum recode_sequence_strategy strategy)
 
       if (sequence_index + 1 < (unsigned)request->sequence_length)
        {
-         switch (strategy)
-           {
-           case RECODE_SEQUENCE_IN_MEMORY:
+          if (strategy == RECODE_SEQUENCE_IN_MEMORY)
+            {
              subtask->output = output;
              subtask->output.cursor = subtask->output.buffer;
-             break;
+            }
 
 #if HAVE_PIPE
-           case RECODE_SEQUENCE_WITH_PIPE:
+          if (strategy == RECODE_SEQUENCE_WITH_PIPE)
+            {
              /* Create all subprocesses, from the first to the last, and
                 interconnect them.  */
 
@@ -339,13 +341,8 @@ perform_sequence (RECODE_TASK task, enum recode_sequence_strategy strategy)
                      SUBTASK_RETURN (subtask);
                    }
                }
-             break;
+            }
 #endif
-
-           default: /* Should never happen */
-             recode_if_nogo (RECODE_INTERNAL_ERROR, subtask);
-             break;
-           }
        }
       else
        {
@@ -382,11 +379,8 @@ perform_sequence (RECODE_TASK task, enum recode_sequence_strategy strategy)
 
          if (strategy == RECODE_SEQUENCE_WITH_PIPE)
            break;      /* parent process: escape from loop */
-       }
 
-      if (strategy == RECODE_SEQUENCE_IN_MEMORY)
-       {
-         /* Post-step clean up.  */
+         /* Post-step clean up for memory sequence.  */
 
          if (subtask->input.file)
            {
@@ -472,15 +466,13 @@ perform_sequence (RECODE_TASK task, enum recode_sequence_strategy strategy)
                  }
            }
 
-#if 0
-         if (interrupted) /* FIXME: interrupted is static in main.c */
+         if (recode_interrupted)
            /* FIXME: It is not very clear what happened in sub-processes.  */
            if (task->error_so_far < task->fail_level)
              {
                task->error_so_far = task->fail_level;
                task->error_at_step = request->sequence_array + (unsigned)request->sequence_length - 1;
              }
-#endif
        }
     }
   else