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>
Johannes Sixt committed
Oct 19, 2007 at 21:47 UTC
dc1bfdcd1a8af81885f1831c5e6dcfe5cf61372e
1 file changed
+7
-23
convert.c
+7
-23
@@ -199,34 +199,18 @@ static int filter_buffer(const char *path, const char *src,
199
* Spawn cmd and feed the buffer contents through its stdin.
200
*/
201
struct child_process child_process;
202
- int pipe_feed[2];
202
int write_err, status;
203
+ const char *argv[] = { "sh", "-c", cmd, NULL };
204
205
memset(&child_process, 0, sizeof(child_process));
206
+ child_process.argv = argv;
207
+ child_process.in = -1;
208
207
- if (pipe(pipe_feed) < 0) {
208
- error("cannot create pipe to run external filter %s", cmd);
209
- return 1;
210
- }
211
-
212
- child_process.pid = fork();
213
- if (child_process.pid < 0) {
214
- error("cannot fork to run external filter %s", cmd);
215
- close(pipe_feed[0]);
216
- close(pipe_feed[1]);
217
- return 1;
218
- }
219
- if (!child_process.pid) {
220
- dup2(pipe_feed[0], 0);
221
- close(pipe_feed[0]);
222
- close(pipe_feed[1]);
223
- execlp("sh", "sh", "-c", cmd, NULL);
224
- return 1;
225
- }
226
- close(pipe_feed[0]);
209
+ if (start_command(&child_process))
210
+ return error("cannot fork to run external filter %s", cmd);
211
228
- write_err = (write_in_full(pipe_feed[1], src, size) < 0);
229
- if (close(pipe_feed[1]))
212
+ write_err = (write_in_full(child_process.in, src, size) < 0);
213
+ if (close(child_process.in))
214
write_err = 1;
215
if (write_err)
216
error("cannot feed the input to external filter %s", cmd);