From 7665470353aeda94026db669697ad1e1a6b32877 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sun, 4 Jan 2009 18:05:10 +0000 Subject: [PATCH] Use new mdup(3mLib) function. It makes descriptor juggling much more reliable. Increase version requirement on mLib to 2.1.0. --- configure.ac | 2 +- exec.c | 13 +++++-------- fwd.h | 1 + 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 64308fb..d5c3316 100644 --- a/configure.ac +++ b/configure.ac @@ -56,7 +56,7 @@ AC_SEARCH_LIBS([socket], [socket]) AC_SEARCH_LIBS([gethostbyname], [nsl resolv]) dnl Packages. -PKG_CHECK_MODULES([mLib], [mLib >= 2.0.4]) +PKG_CHECK_MODULES([mLib], [mLib >= 2.1.0]) dnl Functions. AC_CHECK_FUNCS([inet_aton]) diff --git a/exec.c b/exec.c index 753fc4c..bdd9b5b 100644 --- a/exec.c +++ b/exec.c @@ -464,6 +464,7 @@ static void xept_attach(endpt *e, reffd *in, reffd *out) if (kid == 0) { xopts *xo = xe->xo; + mdup_fd md[3]; /* --- Fiddle with the file descriptors --- * * @@ -473,18 +474,14 @@ static void xept_attach(endpt *e, reffd *in, reffd *out) */ close(fd[0]); - if (dup2(in->fd, STDIN_FILENO) < 0 || - dup2(out->fd, STDOUT_FILENO) < 0 || - dup2(fd[1], STDERR_FILENO) < 0) { + md[0].cur = in->fd; md[0].want = STDIN_FILENO; + md[1].cur = out->fd; md[1].want = STDOUT_FILENO; + md[2].cur = fd[1]; md[2].want = STDERR_FILENO; + if (mdup(md, 3)) { moan("couldn't manipulate file descriptors: %s", strerror(errno)); _exit(1); } - if (in->fd > 2) - close(in->fd); - if (out->fd > 2) - close(out->fd); - fdflags(STDIN_FILENO, O_NONBLOCK, 0, FD_CLOEXEC, 0); fdflags(STDOUT_FILENO, O_NONBLOCK, 0, FD_CLOEXEC, 0); fdflags(STDERR_FILENO, O_NONBLOCK, 0, FD_CLOEXEC, 0); diff --git a/fwd.h b/fwd.h index b45f397..6c16fb6 100644 --- a/fwd.h +++ b/fwd.h @@ -87,6 +87,7 @@ #include #include #include +#include #include #include #include -- 2.11.0