From 12565da6e491e9519ced70c798b67676f4bcf46f Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Mon, 22 Jan 2018 23:35:27 +0000 Subject: [PATCH] Allow pipe filters to signal when they are interrupted again 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 | 4 +--- src/recodext.h | 2 ++ src/task.c | 28 ++++++++++------------------ 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/main.c b/src/main.c index 154d48c..fa3c5f0 100644 --- a/src/main.c +++ b/src/main.c @@ -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); } diff --git a/src/recodext.h b/src/recodext.h index 100c5f4..b453d81 100644 --- a/src/recodext.h +++ b/src/recodext.h @@ -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); diff --git a/src/task.c b/src/task.c index 04a15df..11fd977 100644 --- a/src/task.c +++ b/src/task.c @@ -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) @@ -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 -- 2.50.1