List for cgit developers and users
 help / color / mirror / Atom feed
Subject: [PATCH] filter: pipe_fh should be local
Date: Sat, 14 Oct 2017 22:02:29 +0300	[thread overview]
Message-ID: <20171014190229.4418-1-ville.skytta@iki.fi> (raw)

From: "Jason A. Donenfeld" <Jason at zx2c4.com>

Signed-off-by: Jason A. Donenfeld <Jason at zx2c4.com>
---
 cgit.h   |  1 -
 filter.c | 13 +++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/cgit.h b/cgit.h
index 0b88dcd..005ae63 100644
--- a/cgit.h
+++ b/cgit.h
@@ -71,7 +71,6 @@ struct cgit_exec_filter {
 	char *cmd;
 	char **argv;
 	int old_stdout;
-	int pipe_fh[2];
 	int pid;
 };
 
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)
 static int open_exec_filter(struct cgit_filter *base, va_list ap)
 {
 	struct cgit_exec_filter *filter = (struct cgit_exec_filter *)base;
+	int pipe_fh[2];
 	int i;
 
 	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)
 
 	filter->old_stdout = chk_positive(dup(STDOUT_FILENO),
 		"Unable to duplicate STDOUT");
-	chk_zero(pipe(filter->pipe_fh), "Unable to create pipe to subprocess");
+	chk_zero(pipe(pipe_fh), "Unable to create pipe to subprocess");
 	filter->pid = chk_non_negative(fork(), "Unable to create subprocess");
 	if (filter->pid == 0) {
-		close(filter->pipe_fh[1]);
-		chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO),
+		close(pipe_fh[1]);
+		chk_non_negative(dup2(pipe_fh[0], STDIN_FILENO),
 			"Unable to use pipe as STDIN");
 		execvp(filter->cmd, filter->argv);
 		die_errno("Unable to exec subprocess %s", filter->cmd);
 	}
-	close(filter->pipe_fh[0]);
-	chk_non_negative(dup2(filter->pipe_fh[1], STDOUT_FILENO),
+	close(pipe_fh[0]);
+	chk_non_negative(dup2(pipe_fh[1], STDOUT_FILENO),
 		"Unable to use pipe as STDOUT");
-	close(filter->pipe_fh[1]);
+	close(pipe_fh[1]);
 	return 0;
 }
 
-- 
2.14.1



             reply	other threads:[~2017-10-14 19:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-14 19:02  [this message]
2017-10-14 19:05 ` 

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171014190229.4418-1-ville.skytta@iki.fi \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).