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>
Ben Peart committed
May 5, 2017 at 11:28 UTC
4f2a2e9f0e26c1c543d1f282d6e88b3d0f608d07
3 files changed
+16
-6
convert.c
+8
-2
@@ -635,7 +635,10 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len
635
if (err)
636
goto done;
637
638
- subprocess_read_status(process->out, &filter_status);
638
+ err = subprocess_read_status(process->out, &filter_status);
639
+ if (err)
640
+ goto done;
641
+
642
err = strcmp(filter_status.buf, "success");
643
if (err)
644
goto done;
@@ -644,7 +647,10 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len
647
if (err)
648
goto done;
649
647
- subprocess_read_status(process->out, &filter_status);
650
+ err = subprocess_read_status(process->out, &filter_status);
651
+ if (err)
652
+ goto done;
653
+
654
err = strcmp(filter_status.buf, "success");
655
656
done:
sub-process.c
+7
-3
@@ -21,13 +21,15 @@ struct subprocess_entry *subprocess_find_entry(struct hashmap *hashmap, const ch
21
return hashmap_get(hashmap, &key, NULL);
22
}
23
24
-void subprocess_read_status(int fd, struct strbuf *status)
24
+int subprocess_read_status(int fd, struct strbuf *status)
25
{
26
struct strbuf **pair;
27
char *line;
28
+ int len;
29
+
30
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)
33
break;
34
pair = strbuf_split_str(line, '=', 2);
35
if (pair[0] && pair[0]->len && pair[1]) {
@@ -39,6 +41,8 @@ void subprocess_read_status(int fd, struct strbuf *status)
41
}
42
strbuf_list_free(pair);
43
}
44
+
45
+ return (len < 0) ? len : 0;
46
}
47
48
void subprocess_stop(struct hashmap *hashmap, struct subprocess_entry *entry)
sub-process.h
+1
-1
@@ -44,6 +44,6 @@ static inline struct child_process *subprocess_get_child_process(
44
* key/value pairs and return the value from the last "status" packet
45
*/
46
47
-void subprocess_read_status(int fd, struct strbuf *status);
47
+int subprocess_read_status(int fd, struct strbuf *status);
48
49
#endif