[Pkg-gnupg-commit] [libassuan] 55/437: * 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.

Eric Dorland eric at moszumanska.debian.org
Fri May 22 05:33:23 UTC 2015


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository libassuan.

commit 724fb11c8bc88199da10e3eb8e3064ce6a92081c
Author: Werner Koch <wk at gnupg.org>
Date:   Sun Nov 10 15:22:41 2002 +0000

    * 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.
---
 src/ChangeLog             |  6 +++++
 src/assuan-pipe-connect.c | 69 +++++++++++++++++++++++------------------------
 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 at 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 at 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 */

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/libassuan.git



More information about the Pkg-gnupg-commit mailing list