summaryrefslogtreecommitdiff
path: root/convert.c
diff options
context:
space:
mode:
authorJohannes Sixt <johannes.sixt@telecom.at>2007-10-19 19:47:55 (GMT)
committerShawn O. Pearce <spearce@spearce.org>2007-10-21 05:30:39 (GMT)
commitdc1bfdcd1a8af81885f1831c5e6dcfe5cf61372e (patch)
treefda739a443a6852e5465b7b53e75727cf2f07cb6 /convert.c
parentf364cb88238bbb468b0e076c53a055bcb8603b60 (diff)
downloadgit-dc1bfdcd1a8af81885f1831c5e6dcfe5cf61372e.zip
git-dc1bfdcd1a8af81885f1831c5e6dcfe5cf61372e.tar.gz
git-dc1bfdcd1a8af81885f1831c5e6dcfe5cf61372e.tar.bz2
Use start_command() to run content filters instead of explicit fork/exec.
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> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'convert.c')
-rw-r--r--convert.c30
1 files changed, 7 insertions, 23 deletions
diff --git a/convert.c b/convert.c
index aa95834..d83c2fc 100644
--- a/convert.c
+++ b/convert.c
@@ -199,34 +199,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);