[PATCH 03/14] Use start_command() to run content filters instead of explicit fork/exec.

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <gitster@...>
Cc: <git@...>, Johannes Sixt <johannes.sixt@...>
Date: Saturday, October 13, 2007 - 4:06 pm

The previous code already used finish_command() to wait for the process
to terminate, but did not use start_command() to run it.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
 convert.c |   30 +++++++-----------------------
 1 files changed, 7 insertions(+), 23 deletions(-)

diff --git a/convert.c b/convert.c
index d77c8eb..6d64994 100644
--- a/convert.c
+++ b/convert.c
@@ -208,34 +208,18 @@ static int filter_buffer(const char *path, const char *src,
 	 * Spawn cmd and feed the buffer contents through its stdin.
 	 */
 	struct child_process child_process;
-	int pipe_feed[2];
 	int write_err, status;
+	const char *argv[] = { "sh", "-c", cmd, NULL };
 
 	memset(&child_process, 0, sizeof(child_process));
+	child_process.argv = argv;
+	child_process.in = -1;
 
-	if (pipe(pipe_feed) < 0) {
-		error("cannot create pipe to run external filter %s", cmd);
-		return 1;
-	}
-
-	child_process.pid = fork();
-	if (child_process.pid < 0) {
-		error("cannot fork to run external filter %s", cmd);
-		close(pipe_feed[0]);
-		close(pipe_feed[1]);
-		return 1;
-	}
-	if (!child_process.pid) {
-		dup2(pipe_feed[0], 0);
-		close(pipe_feed[0]);
-		close(pipe_feed[1]);
-		execlp("sh", "sh", "-c", cmd, NULL);
-		return 1;
-	}
-	close(pipe_feed[0]);
+	if (start_command(&child_process))
+		return error("cannot fork to run external filter %s", cmd);
 
-	write_err = (write_in_full(pipe_feed[1], src, size) < 0);
-	if (close(pipe_feed[1]))
+	write_err = (write_in_full(child_process.in, src, size) < 0);
+	if (close(child_process.in))
 		write_err = 1;
 	if (write_err)
 		error("cannot feed the input to external filter %s", cmd);
-- 
1.5.3.3.1134.gee562

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/14] fork/exec removal series, Johannes Sixt, (Sat Oct 13, 4:06 pm)
Re: [PATCH 0/14] fork/exec removal series, Shawn O. Pearce, (Sat Oct 13, 10:11 pm)
Re: [PATCH 0/14] fork/exec removal series, Johannes Schindelin, (Sat Oct 13, 10:50 pm)
Re: [PATCH 0/14] fork/exec removal series, Shawn O. Pearce, (Sat Oct 13, 10:58 pm)
Re: [PATCH 0/14] fork/exec removal series, Pierre Habouzit, (Sun Oct 14, 3:12 am)
Re: [PATCH 0/14] fork/exec removal series, Johannes Schindelin, (Sun Oct 14, 1:09 pm)
Re: [PATCH 0/14] fork/exec removal series, Pierre Habouzit, (Sun Oct 14, 3:17 am)
Re: [PATCH 0/14] fork/exec removal series, Pierre Habouzit, (Sun Oct 14, 3:28 am)
Re: [PATCH 0/14] fork/exec removal series, Andreas Ericsson, (Sun Oct 14, 5:10 am)
Re: [PATCH 01/14] Change git_connect() to return a struct ch..., Johannes Schindelin, (Sat Oct 13, 8:57 pm)
Re: [PATCH 01/14] Change git_connect() to return a struct ch..., Johannes Schindelin, (Sun Oct 14, 1:10 pm)
[PATCH 03/14] Use start_command() to run content filters ins..., Johannes Sixt, (Sat Oct 13, 4:06 pm)