FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Cluster Development

 
 
LinkBack Thread Tools
 
Old 12-03-2009, 04:11 PM
Lon Hohberger
 
Default fence: Remove unnecessary pipes from libfence

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
 

Thread Tools




All times are GMT. The time now is 12:57 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org