OSDN Git Service

2007-01-04 Paolo Bonzini <bonzini@gnu.org>
[pf3gnuchains/gcc-fork.git] / libiberty / pex-unix.c
index c92a429..c5fa984 100644 (file)
@@ -270,7 +270,8 @@ static void pex_child_error (struct pex_obj *, const char *, const char *, int)
 static int pex_unix_open_read (struct pex_obj *, const char *, int);
 static int pex_unix_open_write (struct pex_obj *, const char *, int);
 static long pex_unix_exec_child (struct pex_obj *, int, const char *,
-                                char * const *, int, int, int,
+                                char * const *, char * const *,
+                                int, int, int, int,
                                 const char **, int *);
 static int pex_unix_close (struct pex_obj *, int);
 static int pex_unix_wait (struct pex_obj *, long, int *, struct pex_time *,
@@ -352,12 +353,16 @@ pex_child_error (struct pex_obj *obj, const char *executable,
 
 /* Execute a child.  */
 
+extern char **environ;
+
 static long
 pex_unix_exec_child (struct pex_obj *obj, int flags, const char *executable,
-                    char * const * argv, int in, int out, int errdes,
-                    const char **errmsg, int *err)
+                    char * const * argv, char * const * env,
+                     int in, int out, int errdes,
+                    int toclose, const char **errmsg, int *err)
 {
   pid_t pid;
+
   /* We declare these to be volatile to avoid warnings from gcc about
      them being clobbered by vfork.  */
   volatile int sleep_interval;
@@ -404,11 +409,20 @@ pex_unix_exec_child (struct pex_obj *obj, int flags, const char *executable,
          if (close (errdes) < 0)
            pex_child_error (obj, executable, "close", errno);
        }
+      if (toclose >= 0)
+       {
+         if (close (toclose) < 0)
+           pex_child_error (obj, executable, "close", errno);
+       }
       if ((flags & PEX_STDERR_TO_STDOUT) != 0)
        {
          if (dup2 (STDOUT_FILE_NO, STDERR_FILE_NO) < 0)
            pex_child_error (obj, executable, "dup2", errno);
        }
+
+      if (env)
+        environ = (char**) env;
+
       if ((flags & PEX_SEARCH) != 0)
        {
          execvp (executable, argv);