summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordkegel@google.com <dkegel@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-06 19:59:36 +0000
committerdkegel@google.com <dkegel@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-06 19:59:36 +0000
commit4883a4e4209bab557f4ba40a002936acf755205f (patch)
tree8b1aef5a4e1fe01ee5d4e178838dec8e98356177 /chrome
parente2ffeae017f1c85d472e3f04e62e4cba21f6e9a8 (diff)
downloadchromium_src-4883a4e4209bab557f4ba40a002936acf755205f.zip
chromium_src-4883a4e4209bab557f4ba40a002936acf755205f.tar.gz
chromium_src-4883a4e4209bab557f4ba40a002936acf755205f.tar.bz2
Prototype implementation of zygotes.
Limitations that need addressing still: - Doesn't forcibly terminate children that should have exited but haven't Enable with env var ENABLE_ZYGOTE_MANAGER=1. BUG=11841 TEST= start the browser, then make chrome and all .pak files unreadable; or alternately, start an installed browser, and uninstall the browser while it's running. Then create a new tab and browse to two new sites. Here's an example script to hide and unhide the .pak files (note: do not move the directory they're in, that doesn't work): #!/bin/sh chmod_all() { chmod $1 sconsbuild/Debug/chrome for path in . locales obj/chrome/app/intermediate/repack obj/global_intermediate/* themes do chmod $1 sconsbuild/Debug/$path/*.pak done } case $1 in hide) chmod_all 000 ;; show) chmod_all 755 ;; esac Review URL: http://codereview.chromium.org/115773 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17840 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/breakpad_linux.cc4
-rw-r--r--chrome/app/chrome_dll_main.cc15
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.cc7
-rw-r--r--chrome/common/ipc_channel_posix.cc8
-rw-r--r--chrome/common/process_watcher_posix.cc15
5 files changed, 40 insertions, 9 deletions
diff --git a/chrome/app/breakpad_linux.cc b/chrome/app/breakpad_linux.cc
index 0712241..0ee0bed 100644
--- a/chrome/app/breakpad_linux.cc
+++ b/chrome/app/breakpad_linux.cc
@@ -14,6 +14,7 @@
#include "base/file_version_info_linux.h"
#include "base/path_service.h"
#include "base/rand_util.h"
+#include "base/reserved_file_descriptors.h"
#include "breakpad/linux/directory_reader.h"
#include "breakpad/linux/exception_handler.h"
#include "breakpad/linux/linux_libc_support.h"
@@ -501,8 +502,7 @@ RendererCrashHandler(const void* crash_context, size_t crash_context_size,
void EnableRendererCrashDumping() {
// When the browser forks off our process, it installs the crash signal file
- // descriptor in this slot:
- static const int kMagicCrashSignalFd = 4;
+ // descriptor in slot kMagicCrashSignalFd.
// We deliberately leak this object.
google_breakpad::ExceptionHandler* handler =
diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc
index 006d923..b6ba22f 100644
--- a/chrome/app/chrome_dll_main.cc
+++ b/chrome/app/chrome_dll_main.cc
@@ -45,6 +45,9 @@
#if defined(OS_WIN)
#include "base/win_util.h"
#endif
+#if defined(OS_LINUX)
+#include "base/zygote_manager.h"
+#endif
#if defined(OS_MACOSX)
#include "chrome/app/breakpad_mac.h"
#elif defined(OS_LINUX)
@@ -292,6 +295,18 @@ int ChromeMain(int argc, const char** argv) {
// Initialize the command line.
#if defined(OS_WIN)
CommandLine::Init(0, NULL);
+#elif defined(OS_LINUX)
+ base::ZygoteManager* zm = base::ZygoteManager::Get();
+ std::vector<std::string>* zargv = NULL;
+ if (zm)
+ zargv = zm->Start();
+ if (zargv) {
+ // Forked child.
+ CommandLine::Init(*zargv);
+ } else {
+ // Original process.
+ CommandLine::Init(argc, argv);
+ }
#else
CommandLine::Init(argc, argv);
#endif
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index 771b4d6..9be8769 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -22,6 +22,7 @@
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/rand_util.h"
+#include "base/reserved_file_descriptors.h"
#include "base/scoped_ptr.h"
#include "base/shared_memory.h"
#include "base/singleton.h"
@@ -345,10 +346,12 @@ bool BrowserRenderProcessHost::Init() {
const int crash_signal_fd =
Singleton<RenderCrashHandlerHostLinux>()->GetDeathSignalSocket();
if (crash_signal_fd >= 0)
- fds_to_map.push_back(std::make_pair(crash_signal_fd, 4));
-#endif
+ fds_to_map.push_back(std::make_pair(crash_signal_fd, kMagicCrashSignalFd));
+ base::ForkApp(cmd_line.argv(), fds_to_map, &process);
+#else
base::LaunchApp(cmd_line.argv(), fds_to_map, false, &process);
#endif
+#endif
if (!process) {
channel_.reset();
return false;
diff --git a/chrome/common/ipc_channel_posix.cc b/chrome/common/ipc_channel_posix.cc
index b7a9666..52cad9d 100644
--- a/chrome/common/ipc_channel_posix.cc
+++ b/chrome/common/ipc_channel_posix.cc
@@ -20,6 +20,7 @@
#include "base/lock.h"
#include "base/logging.h"
#include "base/process_util.h"
+#include "base/reserved_file_descriptors.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/singleton.h"
@@ -114,10 +115,6 @@ class PipeMap {
ChannelToFDMap map_;
};
-// This is the file descriptor number that a client process expects to find its
-// IPC socket.
-static const int kClientChannelFd = 3;
-
// Used to map a channel name to the equivalent FD # in the client process.
int ChannelNameToClientFD(const std::string& channel_id) {
// See the large block comment above PipeMap for the reasoning here.
@@ -127,6 +124,9 @@ int ChannelNameToClientFD(const std::string& channel_id) {
// If we don't find an entry, we assume that the correct value has been
// inserted in the magic slot.
+ // kClientChannelFd is the file descriptor number that a client process
+ // expects to find its IPC socket; see reserved_file_descriptors.h.
+
return kClientChannelFd;
}
diff --git a/chrome/common/process_watcher_posix.cc b/chrome/common/process_watcher_posix.cc
index f1ae4f4..497b80b 100644
--- a/chrome/common/process_watcher_posix.cc
+++ b/chrome/common/process_watcher_posix.cc
@@ -11,6 +11,7 @@
#include "base/eintr_wrapper.h"
#include "base/platform_thread.h"
+#include "base/zygote_manager.h"
// Return true if the given child is dead. This will also reap the process.
// Doesn't block.
@@ -69,8 +70,20 @@ class BackgroundReaper : public PlatformThread::Delegate {
// static
void ProcessWatcher::EnsureProcessTerminated(base::ProcessHandle process) {
// If the child is already dead, then there's nothing to do
- if (IsChildDead(process))
+ const int result = HANDLE_EINTR(waitpid(process, NULL, WNOHANG));
+ if (result > 0)
return;
+ if (result == -1) {
+#if defined(OS_LINUX)
+ // If it wasn't our child, maybe it was the zygote manager's child
+ base::ZygoteManager* zm = base::ZygoteManager::Get();
+ if (zm) {
+ zm->EnsureProcessTerminated(process);
+ return;
+ }
+#endif // defined(OS_LINUX)
+ NOTREACHED();
+ }
BackgroundReaper* reaper = new BackgroundReaper(process);
PlatformThread::CreateNonJoinable(0, reaper);