Signed-off-by: Johannes Sixt <johannes.sixt@xxxxxxxxxx> --- convert.c | 36 ++++++++++-------------------------- 1 files changed, 10 insertions(+), 26 deletions(-) diff --git a/convert.c b/convert.c index 0d5e909..560679d 100644 --- a/convert.c +++ b/convert.c @@ -196,40 +196,24 @@ 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]; + struct child_process chld; int write_err, status; + const char *argv[] = { "sh", "-c", cmd, NULL }; - memset(&child_process, 0, sizeof(child_process)); + memset(&chld, 0, sizeof(chld)); + chld.argv = argv; + chld.in = -1; - if (pipe(pipe_feed) < 0) { - error("cannot create pipe to run external filter %s", cmd); - return 1; - } + if (start_command(&chld)) + return error("cannot fork to run external filter %s", cmd); - 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]); - - write_err = (write_in_full(pipe_feed[1], src, size) < 0); - if (close(pipe_feed[1])) + write_err = (write_in_full(chld.in, src, size) < 0); + if (close(chld.in)) write_err = 1; if (write_err) error("cannot feed the input to external filter %s", cmd); - status = finish_command(&child_process); + status = finish_command(&chld); if (status) error("external filter %s failed %d", cmd, -status); return (write_err || status); -- 1.5.3.3.1134.gee562 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html