[Cluster-devel] [PATCH] fence: Remove unnecessary pipes from libfence
Lon Hohberger
lhh at redhat.com
Thu Dec 3 17:11:17 UTC 2009
Signed-off-by: Lon Hohberger <lhh at 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
More information about the Cluster-devel
mailing list