* [Cluster-devel] [PATCH] fence: Remove unnecessary pipes from libfence
@ 2009-12-03 17:11 Lon Hohberger
0 siblings, 0 replies; only message in thread
From: Lon Hohberger @ 2009-12-03 17:11 UTC (permalink / raw)
To: cluster-devel.redhat.com
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2009-12-03 17:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-03 17:11 [Cluster-devel] [PATCH] fence: Remove unnecessary pipes from libfence Lon Hohberger
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).