summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-20 23:16:24 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-20 23:16:24 +0000
commit1d769c1b75d700e219d01a6c6419e52b3f8d22cb (patch)
treeba024f8673885eada3135f530b885a3041a92635 /base
parentc85cfbd98c6bf26e730fdd15538c624cb52352e9 (diff)
downloadchromium_src-1d769c1b75d700e219d01a6c6419e52b3f8d22cb.zip
chromium_src-1d769c1b75d700e219d01a6c6419e52b3f8d22cb.tar.gz
chromium_src-1d769c1b75d700e219d01a6c6419e52b3f8d22cb.tar.bz2
Switch to using vfork() instead of fork() when we can.
This means we can avoid creating new page tables, but that we share our memory mappings / stack with the parent. This is a bit more fragile, but should be workable. This saves us some work since we are just going to exec(). This also removes some sandbox unsetting code, since we shouldn't be spawning processing under the sandbox anyway. BUG=19863 Review URL: http://codereview.chromium.org/173141 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23911 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/process_util_posix.cc50
1 files changed, 28 insertions, 22 deletions
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc
index ecb4937..d81776f 100644
--- a/base/process_util_posix.cc
+++ b/base/process_util_posix.cc
@@ -224,25 +224,40 @@ bool LaunchApp(const std::vector<std::string>& argv,
const environment_vector& environ,
const file_handle_mapping_vector& fds_to_remap,
bool wait, ProcessHandle* process_handle) {
- pid_t pid = fork();
+ // 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<char*> argv_cstr(new char*[argv.size() + 1]);
+ for (size_t i = 0; i < argv.size(); i++)
+ argv_cstr[i] = const_cast<char*>(argv[i].c_str());
+ argv_cstr[argv.size()] = NULL;
+
+ pid_t pid = use_vfork ? vfork() : 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));
- }
- 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);
+ 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);
+ }
}
}
}
@@ -255,17 +270,8 @@ bool LaunchApp(const std::vector<std::string>& 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<char*> argv_cstr(new char*[argv.size() + 1]);
- for (size_t i = 0; i < argv.size(); i++)
- argv_cstr[i] = const_cast<char*>(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;