From e65723081b1f5e0a2fd1fddd411fe64806a9d7ef Mon Sep 17 00:00:00 2001 From: "deanm@chromium.org" Date: Fri, 21 Aug 2009 17:05:54 +0000 Subject: Revert r23911, which switched from fork to vfork(). Everything still worked correctly, but our performance bots didn't measure any improvements. Perhaps I just ended up measuring the dtrace overhead of fork vs vfork. BUG=19863 Review URL: http://codereview.chromium.org/174229 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23969 0039d316-1c4b-4281-b951-d872f2087c98 --- base/process_util_posix.cc | 50 ++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) (limited to 'base/process_util_posix.cc') diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc index d81776f..ecb4937 100644 --- a/base/process_util_posix.cc +++ b/base/process_util_posix.cc @@ -224,40 +224,25 @@ bool LaunchApp(const std::vector& argv, const environment_vector& environ, const file_handle_mapping_vector& fds_to_remap, bool wait, ProcessHandle* process_handle) { - // We call vfork() for additional performance (avoids touching the page - // tables). This makes things a bit more dangerous since the child and - // parent share the same address space and stack. Try to do most of our - // operations before the fork, and hope that everything we do have to do - // will be ok... - bool use_vfork = (environ.size() == 0); - - InjectiveMultimap fd_shuffle; - for (file_handle_mapping_vector::const_iterator - it = fds_to_remap.begin(); it != fds_to_remap.end(); ++it) { - fd_shuffle.push_back(InjectionArc(it->first, it->second, false)); - } - - scoped_array argv_cstr(new char*[argv.size() + 1]); - for (size_t i = 0; i < argv.size(); i++) - argv_cstr[i] = const_cast(argv[i].c_str()); - argv_cstr[argv.size()] = NULL; - - pid_t pid = use_vfork ? vfork() : fork(); + pid_t pid = fork(); if (pid < 0) return false; if (pid == 0) { // Child process + InjectiveMultimap fd_shuffle; + for (file_handle_mapping_vector::const_iterator + it = fds_to_remap.begin(); it != fds_to_remap.end(); ++it) { + fd_shuffle.push_back(InjectionArc(it->first, it->second, false)); + } - if (!use_vfork) { - for (environment_vector::const_iterator it = environ.begin(); - it != environ.end(); ++it) { - if (it->first) { - if (it->second) { - setenv(it->first, it->second, 1); - } else { - unsetenv(it->first); - } + for (environment_vector::const_iterator it = environ.begin(); + it != environ.end(); ++it) { + if (it->first) { + if (it->second) { + setenv(it->first, it->second, 1); + } else { + unsetenv(it->first); } } } @@ -270,8 +255,17 @@ bool LaunchApp(const std::vector& argv, if (!ShuffleFileDescriptors(fd_shuffle)) _exit(127); + // If we are using the SUID sandbox, it sets a magic environment variable + // ("SBX_D"), so we remove that variable from the environment here on the + // off chance that it's already set. + unsetenv("SBX_D"); + CloseSuperfluousFds(fd_shuffle); + scoped_array argv_cstr(new char*[argv.size() + 1]); + for (size_t i = 0; i < argv.size(); i++) + argv_cstr[i] = const_cast(argv[i].c_str()); + argv_cstr[argv.size()] = NULL; execvp(argv_cstr[0], argv_cstr.get()); LOG(ERROR) << "LaunchApp: exec failed!, argv_cstr[0] " << argv_cstr[0] << ", errno " << errno; -- cgit v1.1