cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Lon Hohberger <lhh@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH] fence: Remove unnecessary pipes from libfence
Date: Thu,  3 Dec 2009 12:11:17 -0500	[thread overview]
Message-ID: <1259860277-27976-1-git-send-email-lhh@redhat.com> (raw)

Signed-off-by: Lon Hohberger <lhh@redhat.com>
---
 fence/libfence/agent.c |   46 ++++++++++++++++++++++------------------------
 1 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/fence/libfence/agent.c b/fence/libfence/agent.c
index 5577fda..c3ca116 100644
--- a/fence/libfence/agent.c
+++ b/fence/libfence/agent.c
@@ -26,26 +26,20 @@
 static int run_agent(char *agent, char *args, int *agent_result)
 {
 	int pid, status, len;
-	int pr_fd, pw_fd;  /* parent read/write file descriptors */
+	int pw_fd;  /* parent read/write file descriptors */
 	int cr_fd, cw_fd;  /* child read/write file descriptors */
-	int fd1[2];
-	int fd2[2];
+	int fd[2];
 
-	cr_fd = cw_fd = pr_fd = pw_fd = -1;
+	cr_fd = cw_fd = pw_fd = -1;
 
 	if (args == NULL || agent == NULL)
 		goto fail;
 	len = strlen(args);
 
-	if (pipe(fd1))
+	if (pipe(fd))
 		goto fail;
-	pr_fd = fd1[0];
-	cw_fd = fd1[1];
-
-	if (pipe(fd2))
-		goto fail;
-	cr_fd = fd2[0];
-	pw_fd = fd2[1];
+	cr_fd = fd[0];
+	pw_fd = fd[1];
 
 	pid = fork();
 	if (pid < 0) {
@@ -57,7 +51,7 @@ static int run_agent(char *agent, char *args, int *agent_result)
 		/* parent */
 		int ret;
 
-		fcntl(pr_fd, F_SETFL, fcntl(pr_fd, F_GETFL, 0) | O_NONBLOCK);
+		close(cr_fd);
 
 		do {
 			ret = write(pw_fd, args, len);
@@ -77,33 +71,37 @@ static int run_agent(char *agent, char *args, int *agent_result)
 		}
 	} else {
 		/* child */
+		close(pw_fd);
 
-		close(1);
-		if (dup(cw_fd) < 0)
+		/* Standard input = from pipe in parent */
+		close(0);
+		if (dup2(cr_fd, 0) < 0)
 			goto fail;
+		close(cr_fd);
+
+		/* stdout/stderr = /dev/null for agents */
+		close(1);
 		close(2);
-		if (dup(cw_fd) < 0)
+		cw_fd = open("/dev/null", O_WRONLY);
+		if (cw_fd < 0)
 			goto fail;
-		close(0);
-		if (dup(cr_fd) < 0)
+		if (dup2(cw_fd, 1) < 0)
 			goto fail;
-		/* keep cw_fd open so parent can report all errors. */
-		close(pr_fd);
-		close(cr_fd);
-		close(pw_fd);
+		if (dup2(cw_fd, 2) < 0)
+			goto fail;
+		if (cw_fd >= 3)
+			close(cw_fd);
 
 		execlp(agent, agent, NULL);
 		exit(EXIT_FAILURE);
 	}
 
-	close(pr_fd);
 	close(cw_fd);
 	close(cr_fd);
 	close(pw_fd);
 	return 0;
 
  fail:
-	close(pr_fd);
 	close(cw_fd);
 	close(cr_fd);
 	close(pw_fd);
-- 
1.6.2.5



                 reply	other threads:[~2009-12-03 17:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1259860277-27976-1-git-send-email-lhh@redhat.com \
    --to=lhh@redhat.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).