git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 8/8] convert: Update subprocess_read_status to not die on EOF

From
Ben Peart <peartben@gmail.com>
Date
Mar 29, 2017, 15:53 UTC
Message-ID
<20170329155330.12860-9-benpeart@microsoft.com>
In-Reply-To
<20170329155330.12860-1-benpeart@microsoft.com>

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>
---
 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 2c4d27c193..202d7d0255 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)
 			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;
 }
 
 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.1.gvfs.1.18.ge47db72
Previous: Ben PeartNext: Ben Peart
Message 9 of 13 in “refactor the filter process code into a reusable module”
  1. 0/8 refactor the filter process code into a reusable moduleBen Peart, Mar 29, 2017
  2. 2/8 convert: Update convert to use new packet_writel() functionBen Peart, Mar 29, 2017
  3. 1/8 pkt-line: add packet_writel() and packet_read_line_gently()Ben Peart, Mar 29, 2017
  4. 3/8 convert: Split start_multi_file_filter into two separate functionsBen Peart, Mar 29, 2017
  5. 6/8 convert: rename reusable sub-process functionsBen Peart, Mar 29, 2017
  6. 7/8 sub-process: move sub-process functions into separate filesBen Peart, Mar 29, 2017
  7. Junio C HamanoMar 29, 2017
  8. Ben PeartMar 30, 2017
  9. 8/8 convert: Update subprocess_read_status to not die on EOFBen Peart, Mar 29, 2017
  10. 4/8 convert: Separate generic structures and variables from the filter specific onesBen Peart, Mar 29, 2017
  11. 5/8 convert: Update generic functions to only use generic data structuresBen Peart, Mar 29, 2017
  12. Junio C HamanoMar 29, 2017
  13. Ben PeartMar 30, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.