convert: update subprocess_read_status() to not die on EOF
authorBen Peart <peartben@gmail.com>
Fri, 5 May 2017 15:28:02 +0000 (11:28 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 May 2017 04:01:57 +0000 (13:01 +0900)
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>
convert.c
sub-process.c
sub-process.h
index 79d04907a53e1abcc660395a59fd0703324f29e4..f1e168bc303c71542b692b2b9d08cdb2e2c98669 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -635,7 +635,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;
@@ -644,7 +647,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:
index 536b60ccedd7828af15d2a1ab5ff721e31ad3f92..92f8aea70aa0bc7654b89bebc3e72b197953e84a 100644 (file)
@@ -21,13 +21,15 @@ struct subprocess_entry *subprocess_find_entry(struct hashmap *hashmap, const ch
        return hashmap_get(hashmap, &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 < 0) || !line)
                        break;
                pair = strbuf_split_str(line, '=', 2);
                if (pair[0] && pair[0]->len && pair[1]) {
@@ -39,6 +41,8 @@ void subprocess_read_status(int fd, struct strbuf *status)
                }
                strbuf_list_free(pair);
        }
+
+       return (len < 0) ? len : 0;
 }
 
 void subprocess_stop(struct hashmap *hashmap, struct subprocess_entry *entry)
index a88e782bfc8bdbb3b8c651940019e01a9161a8f3..7d451e1cde8d8a5af93695d2fcaf58e76e30ec84 100644 (file)
@@ -44,6 +44,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