diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-10 23:04:55 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-10 23:04:55 +0000 |
commit | 361e25c6d29fdae737b5ddf846606093b5502187 (patch) | |
tree | 3114ddee1266088582391d5be9d0ab7aecbd5b8d /chrome/test/chrome_process_util.cc | |
parent | c6b652b9298b037d8a18dd241061122200019dba (diff) | |
download | chromium_src-361e25c6d29fdae737b5ddf846606093b5502187.zip chromium_src-361e25c6d29fdae737b5ddf846606093b5502187.tar.gz chromium_src-361e25c6d29fdae737b5ddf846606093b5502187.tar.bz2 |
Linux: refactor zygote support
http://code.google.com/p/chromium/wiki/LinuxZygote
* Move Chrome specific bits out of base
* Move away from the idea of reserved file descriptors (which don't
really work with zygotes)
* Load resources before forking renderers (means that we don't need
communication between the zygote process and the renderers)
* Make sure that gdb works against the browser again
* Make sure that we have different ASLR between the renderers and the
browser.
http://codereview.chromium.org/119335
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18109 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/chrome_process_util.cc')
-rw-r--r-- | chrome/test/chrome_process_util.cc | 76 |
1 files changed, 35 insertions, 41 deletions
diff --git a/chrome/test/chrome_process_util.cc b/chrome/test/chrome_process_util.cc index 296b291..4a5f5bb 100644 --- a/chrome/test/chrome_process_util.cc +++ b/chrome/test/chrome_process_util.cc @@ -5,6 +5,7 @@ #include "chrome/test/chrome_process_util.h" #include <vector> +#include <set> #include "base/process_util.h" #include "base/time.h" @@ -14,26 +15,6 @@ using base::Time; using base::TimeDelta; -namespace { - -class ChromeProcessFilter : public base::ProcessFilter { - public: - explicit ChromeProcessFilter(base::ProcessId browser_pid) - : browser_pid_(browser_pid) {} - - virtual bool Includes(base::ProcessId pid, base::ProcessId parent_pid) const { - // Match browser process itself and its children. - return browser_pid_ == pid || browser_pid_ == parent_pid; - } - - private: - base::ProcessId browser_pid_; - - DISALLOW_COPY_AND_ASSIGN(ChromeProcessFilter); -}; - -} // namespace - void TerminateAllChromeProcesses(const FilePath& data_dir) { // Total time the function will wait for chrome processes // to terminate after it told them to do so. @@ -70,6 +51,24 @@ void TerminateAllChromeProcesses(const FilePath& data_dir) { base::CloseProcessHandle(*it); } +class ChildProcessFilter : public base::ProcessFilter { + public: + explicit ChildProcessFilter(base::ProcessId parent_pid) + : parent_pids_(&parent_pid, (&parent_pid) + 1) {} + + explicit ChildProcessFilter(std::vector<base::ProcessId> parent_pids) + : parent_pids_(parent_pids.begin(), parent_pids.end()) {} + + virtual bool Includes(base::ProcessId pid, base::ProcessId parent_pid) const { + return parent_pids_.find(parent_pid) != parent_pids_.end(); + } + + private: + const std::set<base::ProcessId> parent_pids_; + + DISALLOW_COPY_AND_ASSIGN(ChildProcessFilter); +}; + ChromeProcessList GetRunningChromeProcesses(const FilePath& data_dir) { ChromeProcessList result; @@ -77,37 +76,32 @@ ChromeProcessList GetRunningChromeProcesses(const FilePath& data_dir) { if (browser_pid < 0) return result; - // Normally, the browser is the parent process for all the renderers - base::ProcessId parent_pid = browser_pid; - -#if defined(OS_LINUX) - // But if the browser's parent is the same executable as the browser, - // then it's the zygote manager, and it's the parent for all the renderers. - base::ProcessId manager_pid = base::GetParentProcessId(browser_pid); - FilePath selfPath = base::GetProcessExecutablePath(browser_pid); - FilePath managerPath = base::GetProcessExecutablePath(manager_pid); - if (!selfPath.empty() && !managerPath.empty() && selfPath == managerPath) { - LOG(INFO) << "Zygote manager in use."; - parent_pid = manager_pid; - } -#endif - - ChromeProcessFilter filter(parent_pid); + ChildProcessFilter filter(browser_pid); base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName, &filter); const ProcessEntry* process_entry; while ((process_entry = it.NextProcessEntry())) { #if defined(OS_WIN) result.push_back(process_entry->th32ProcessID); -#elif defined(OS_LINUX) - // Don't count the zygote manager, that screws up unit tests, - // and it will exit cleanly on its own when first client exits. - if (process_entry->pid != manager_pid) - result.push_back(process_entry->pid); #elif defined(OS_POSIX) result.push_back(process_entry->pid); #endif } +#if defined(OS_LINUX) + // On Linux we might be running with a zygote process for the renderers. + // Because of that we sweep the list of processes again and pick those which + // are children of one of the processes that we've already seen. + { + ChildProcessFilter filter(result); + base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName, + &filter); + while ((process_entry = it.NextProcessEntry())) + result.push_back(process_entry->pid); + } +#endif + + result.push_back(browser_pid); + return result; } |