summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2002-11-10 15:22:41 +0000
committerWerner Koch <wk@gnupg.org>2002-11-10 15:22:41 +0000
commit724fb11c8bc88199da10e3eb8e3064ce6a92081c (patch)
tree39da95fe86da2cdcd67026db4640bf345682f9a5
parente638b3342a80ce6a01e44b2c47e51c51bb42e5c5 (diff)
downloadlibassuan-724fb11c8bc88199da10e3eb8e3064ce6a92081c.tar.gz
* assuan-pipe-connect.c (assuan_pipe_connect): Changed the order
of the dups to handle cases where we have already used fd 2 for other things.
-rw-r--r--src/ChangeLog6
-rw-r--r--src/assuan-pipe-connect.c69
2 files changed, 40 insertions, 35 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 552a9c8..85dc5ef 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2002-11-10 Werner Koch <wk@gnupg.org>
+
+ * assuan-pipe-connect.c (assuan_pipe_connect): Changed the order
+ of the dups to handle cases where we have already used fd 2 for
+ other things.
+
2002-10-31 Neal H. Walfield <neal@g10code.de>
* assuan-util.c: Include <ctype.h>.
diff --git a/src/assuan-pipe-connect.c b/src/assuan-pipe-connect.c
index 0cb48ca..e280be6 100644
--- a/src/assuan-pipe-connect.c
+++ b/src/assuan-pipe-connect.c
@@ -172,25 +172,23 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[],
char errbuf[512];
int *fdp;
- /* Close all files which will not be duped and are not in the
- fd_child_list. */
- n = sysconf (_SC_OPEN_MAX);
- if (n < 0)
- n = MAX_OPEN_FDS;
- for (i=0; i < n; i++)
+ /* Dup handles to stdin/stdout. */
+ if (rp[1] != STDOUT_FILENO)
{
- fdp = fd_child_list;
- if (fdp)
- {
- while (*fdp != -1 && *fdp != i)
- fdp++;
- }
-
- if (!(fdp && *fdp != -1)
- && i != rp[1] && i != wp[0])
- close(i);
+ if (dup2 (rp[1], STDOUT_FILENO) == -1)
+ {
+ LOGERROR1 ("dup2 failed in child: %s\n", strerror (errno));
+ _exit (4);
+ }
+ }
+ if (wp[0] != STDIN_FILENO)
+ {
+ if (dup2 (wp[0], STDIN_FILENO) == -1)
+ {
+ LOGERROR1 ("dup2 failed in child: %s\n", strerror (errno));
+ _exit (4);
+ }
}
- errno = 0;
/* Dup stderr to /dev/null unless it is in the list of FDs to be
passed to the child. */
@@ -213,28 +211,29 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[],
LOGERROR1 ("dup2(dev/null, 2) failed: %s\n", strerror (errno));
_exit (4);
}
- close (fd);
}
- /* Dup handles and to stdin/stdout and exec. */
- if (rp[1] != STDOUT_FILENO)
- {
- if (dup2 (rp[1], STDOUT_FILENO) == -1)
- {
- LOGERROR1 ("dup2 failed in child: %s\n", strerror (errno));
- _exit (4);
- }
- close (rp[1]);
- }
- if (wp[0] != STDIN_FILENO)
+
+ /* Close all files which will not be duped and are not in the
+ fd_child_list. */
+ n = sysconf (_SC_OPEN_MAX);
+ if (n < 0)
+ n = MAX_OPEN_FDS;
+ for (i=0; i < n; i++)
{
- if (dup2 (wp[0], STDIN_FILENO) == -1)
- {
- LOGERROR1 ("dup2 failed in child: %s\n", strerror (errno));
- _exit (4);
- }
- close (wp[0]);
+ if ( i = STDIN_FILENO || i == STDOUT_FILENO || i == STDERR_FILENO)
+ continue;
+ fdp = fd_child_list;
+ if (fdp)
+ {
+ while (*fdp != -1 && *fdp != i)
+ fdp++;
+ }
+
+ if (!(fdp && *fdp != -1))
+ close(i);
}
+ errno = 0;
execv (name, argv);
/* oops - use the pipe to tell the parent about it */