When spawning processes, don't ignore the passed in environment
authorRay Strode <rstrode@redhat.com>
Thu, 10 Jul 2008 17:12:01 +0000 (13:12 -0400)
committerRay Strode <rstrode@redhat.com>
Sat, 12 Jul 2008 04:32:24 +0000 (00:32 -0400)
Previously, we'd always call execv() and unconditionally use
the environment of the parent.  Now we call execve() with the
passed in environment.  For compatibility, we detect if
the passed in environment is NULL and for that case, use the
environment from the parent instead.

dbus/dbus-spawn.c

index d74b326..35ccba6 100644 (file)
@@ -880,6 +880,7 @@ write_status_and_exit (int fd, int status)
 static void
 do_exec (int                       child_err_report_fd,
         char                    **argv,
+        char                    **envp,
         DBusSpawnChildSetupFunc   child_setup,
         void                     *user_data)
 {
@@ -910,8 +911,17 @@ do_exec (int                       child_err_report_fd,
        _dbus_warn ("Fd %d did not have the close-on-exec flag set!\n", i);
     }
 #endif
+
+  if (envp == NULL)
+    {
+      extern char **environ;
+
+      _dbus_assert (environ != NULL);
+
+      envp = environ;
+    }
   
-  execv (argv[0], argv);
+  execve (argv[0], argv, envp);
   
   /* Exec failed */
   write_err_and_exit (child_err_report_fd,
@@ -1190,6 +1200,7 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter          **sitter_p,
        {
          do_exec (child_err_report_pipe[WRITE_END],
                   argv,
+                  env,
                   child_setup, user_data);
           _dbus_assert_not_reached ("Got to code after exec() - should have exited on error");
        }
@@ -1218,6 +1229,8 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter          **sitter_p,
       else
         _dbus_babysitter_unref (sitter);
 
+      dbus_free_string_array (env);
+
       _DBUS_ASSERT_ERROR_IS_CLEAR (error);
       
       return TRUE;