fence: Remove unnecessary pipes from libfence
PATCH 1/1 fence: Remove unnecessary pipes from libfence
Signed-off-by Lon Hohberger <[email protected]>
--- fence/libfence/agent.c | 46 ++++++++++++++++++++++------------------------ 1 files changed, 22 insertions(+), 24 deletions(-)
fence/libfence/agent.c +22 -24
@@ -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);
Signature · 1 line
1.6.2.5