Skip to content

Commit 4f2a2e9

Browse files
benpeartgitster
authored andcommitted
convert: update subprocess_read_status() to not die on EOF
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@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 99605d6 commit 4f2a2e9

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

convert.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,10 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len
635635
if (err)
636636
goto done;
637637

638-
subprocess_read_status(process->out, &filter_status);
638+
err = subprocess_read_status(process->out, &filter_status);
639+
if (err)
640+
goto done;
641+
639642
err = strcmp(filter_status.buf, "success");
640643
if (err)
641644
goto done;
@@ -644,7 +647,10 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len
644647
if (err)
645648
goto done;
646649

647-
subprocess_read_status(process->out, &filter_status);
650+
err = subprocess_read_status(process->out, &filter_status);
651+
if (err)
652+
goto done;
653+
648654
err = strcmp(filter_status.buf, "success");
649655

650656
done:

sub-process.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ struct subprocess_entry *subprocess_find_entry(struct hashmap *hashmap, const ch
2121
return hashmap_get(hashmap, &key, NULL);
2222
}
2323

24-
void subprocess_read_status(int fd, struct strbuf *status)
24+
int subprocess_read_status(int fd, struct strbuf *status)
2525
{
2626
struct strbuf **pair;
2727
char *line;
28+
int len;
29+
2830
for (;;) {
29-
line = packet_read_line(fd, NULL);
30-
if (!line)
31+
len = packet_read_line_gently(fd, NULL, &line);
32+
if ((len < 0) || !line)
3133
break;
3234
pair = strbuf_split_str(line, '=', 2);
3335
if (pair[0] && pair[0]->len && pair[1]) {
@@ -39,6 +41,8 @@ void subprocess_read_status(int fd, struct strbuf *status)
3941
}
4042
strbuf_list_free(pair);
4143
}
44+
45+
return (len < 0) ? len : 0;
4246
}
4347

4448
void subprocess_stop(struct hashmap *hashmap, struct subprocess_entry *entry)

sub-process.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ static inline struct child_process *subprocess_get_child_process(
4444
* key/value pairs and return the value from the last "status" packet
4545
*/
4646

47-
void subprocess_read_status(int fd, struct strbuf *status);
47+
int subprocess_read_status(int fd, struct strbuf *status);
4848

4949
#endif

0 commit comments

Comments
 (0)