aboutsummaryrefslogtreecommitdiffstats
path: root/filter.c
diff options
context:
space:
mode:
Diffstat (limited to 'filter.c')
-rw-r--r--filter.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/filter.c b/filter.c
index 949c931..70f5b74 100644
--- a/filter.c
+++ b/filter.c
@@ -42,6 +42,7 @@ void cgit_cleanup_filters(void)
42static int open_exec_filter(struct cgit_filter *base, va_list ap) 42static int open_exec_filter(struct cgit_filter *base, va_list ap)
43{ 43{
44 struct cgit_exec_filter *filter = (struct cgit_exec_filter *)base; 44 struct cgit_exec_filter *filter = (struct cgit_exec_filter *)base;
45 int pipe_fh[2];
45 int i; 46 int i;
46 47
47 for (i = 0; i < filter->base.argument_count; i++) 48 for (i = 0; i < filter->base.argument_count; i++)
@@ -49,19 +50,19 @@ static int open_exec_filter(struct cgit_filter *base, va_list ap)
49 50
50 filter->old_stdout = chk_positive(dup(STDOUT_FILENO), 51 filter->old_stdout = chk_positive(dup(STDOUT_FILENO),
51 "Unable to duplicate STDOUT"); 52 "Unable to duplicate STDOUT");
52 chk_zero(pipe(filter->pipe_fh), "Unable to create pipe to subprocess"); 53 chk_zero(pipe(pipe_fh), "Unable to create pipe to subprocess");
53 filter->pid = chk_non_negative(fork(), "Unable to create subprocess"); 54 filter->pid = chk_non_negative(fork(), "Unable to create subprocess");
54 if (filter->pid == 0) { 55 if (filter->pid == 0) {
55 close(filter->pipe_fh[1]); 56 close(pipe_fh[1]);
56 chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO), 57 chk_non_negative(dup2(pipe_fh[0], STDIN_FILENO),
57 "Unable to use pipe as STDIN"); 58 "Unable to use pipe as STDIN");
58 execvp(filter->cmd, filter->argv); 59 execvp(filter->cmd, filter->argv);
59 die_errno("Unable to exec subprocess %s", filter->cmd); 60 die_errno("Unable to exec subprocess %s", filter->cmd);
60 } 61 }
61 close(filter->pipe_fh[0]); 62 close(pipe_fh[0]);
62 chk_non_negative(dup2(filter->pipe_fh[1], STDOUT_FILENO), 63 chk_non_negative(dup2(pipe_fh[1], STDOUT_FILENO),
63 "Unable to use pipe as STDOUT"); 64 "Unable to use pipe as STDOUT");
64 close(filter->pipe_fh[1]); 65 close(pipe_fh[1]);
65 return 0; 66 return 0;
66} 67}
67 68