> On 07 Apr 2017, at 14:03, Ben Peart <peartben@xxxxxxxxx> wrote: > > Enable sub-processes to gracefully handle when the process dies by > updating subprocess_read_status to return an error on EOF instead of > dying. > > Update apply_multi_file_filter to take advantage of the revised > subprocess_read_status. > > Signed-off-by: Ben Peart <benpeart@xxxxxxxxxxxxx> > --- > convert.c | 10 ++++++++-- > sub-process.c | 10 +++++++--- > sub-process.h | 2 +- > 3 files changed, 16 insertions(+), 6 deletions(-) > > diff --git a/convert.c b/convert.c > index baa41da760..9e181e27ad 100644 > --- a/convert.c > +++ b/convert.c > @@ -629,7 +629,10 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len > if (err) > goto done; > > - subprocess_read_status(process->out, &filter_status); > + err = subprocess_read_status(process->out, &filter_status); > + if (err) > + goto done; > + > err = strcmp(filter_status.buf, "success"); > if (err) > goto done; > @@ -638,7 +641,10 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len > if (err) > goto done; > > - subprocess_read_status(process->out, &filter_status); > + err = subprocess_read_status(process->out, &filter_status); > + if (err) > + goto done; > + > err = strcmp(filter_status.buf, "success"); > > done: > diff --git a/sub-process.c b/sub-process.c > index 60bb650012..c5057cafcd 100644 > --- a/sub-process.c > +++ b/sub-process.c > @@ -30,13 +30,15 @@ struct subprocess_entry *subprocess_find_entry(const char *cmd) > return hashmap_get(&subprocess_map, &key, NULL); > } > > -void subprocess_read_status(int fd, struct strbuf *status) > +int subprocess_read_status(int fd, struct strbuf *status) > { > struct strbuf **pair; > char *line; > + int len; > + > for (;;) { > - line = packet_read_line(fd, NULL); > - if (!line) > + len = packet_read_line_gently(fd, NULL, &line); > + if ((len == -1) || !line) Minor nit: Maybe "if ((len < 0) || !line)" ? > break; > pair = strbuf_split_str(line, '=', 2); > if (pair[0] && pair[0]->len && pair[1]) { > @@ -48,6 +50,8 @@ void subprocess_read_status(int fd, struct strbuf *status) > } > strbuf_list_free(pair); > } > + > + return len == -1 ? len : 0; Minor nit: Maybe "return len < 0 ? len : 0; > } > > void subprocess_stop(struct subprocess_entry *entry) > diff --git a/sub-process.h b/sub-process.h > index 0cf1760a0a..5a1eeeece0 100644 > --- a/sub-process.h > +++ b/sub-process.h > @@ -41,6 +41,6 @@ static inline struct child_process *subprocess_get_child_process( > * key/value pairs and return the value from the last "status" packet > */ > > -void subprocess_read_status(int fd, struct strbuf *status); > +int subprocess_read_status(int fd, struct strbuf *status); > > #endif > -- > 2.12.0.windows.1.31.g1548525701.dirty > Looks good to me. Thanks, Lars