[RFA] save/restore environ in libiberty pex_unix_exec_child

Doug Evans dje@google.com
Mon Dec 7 17:26:00 GMT 2009


Hi.

I ran into this while using pex_run_in_environment in gdb.

Ok to check in?

2009-12-07  Doug Evans  <dje@google.com>

	* pex-unix.c (pex_unix_exec_child): Save/restore environ.

==== //depot2/gcctools/google_vendor_src_branch/gdb/gdb-7.0.x-prod/libiberty/pex-unix.c#1 - /usr/local/google/home/dje/ctools/gdb/7.0.x-prod/depot2/gcctools/google_vendor_src_branch/gdb/gdb-7.0.x-prod/libiberty/pex-unix.c ====
--- /tmp/g4-67641/cache/depot2/gcctools/google_vendor_src_branch/gdb/gdb-7.0.x-prod/libiberty/pex-unix.c#1	2009-12-06 12:30:36.000000000 -0800
+++ /usr/local/google/home/dje/ctools/gdb/7.0.x-prod/depot2/gcctools/google_vendor_src_branch/gdb/gdb-7.0.x-prod/libiberty/pex-unix.c	2009-12-06 12:27:46.000000000 -0800
@@ -397,6 +397,10 @@
   volatile int sleep_interval;
   volatile int retries;
 
+  /* We vfork and then set environ in the child before calling execvp.
+     This clobbers the parent's environ so we need to restore it.  */
+  char **save_environ = environ;
+
   sleep_interval = 1;
   pid = -1;
   for (retries = 0; retries < 4; ++retries)
@@ -468,6 +472,7 @@
 
     default:
       /* Parent process.  */
+      environ = save_environ;
       if (in != STDIN_FILE_NO)
 	{
 	  if (close (in) < 0)



More information about the Gdb-patches mailing list