OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/browser_main_loop.h" | 5 #include "content/browser/browser_main_loop.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/file_util.h" | |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
13 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
14 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
15 #include "base/path_service.h" | |
16 #include "base/pending_task.h" | 14 #include "base/pending_task.h" |
17 #include "base/power_monitor/power_monitor.h" | 15 #include "base/power_monitor/power_monitor.h" |
18 #include "base/process/process_metrics.h" | 16 #include "base/process/process_metrics.h" |
19 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
20 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
21 #include "base/system_monitor/system_monitor.h" | 19 #include "base/system_monitor/system_monitor.h" |
22 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
23 #include "base/timer/hi_res_timer_manager.h" | 21 #include "base/timer/hi_res_timer_manager.h" |
24 #include "content/browser/browser_thread_impl.h" | 22 #include "content/browser/browser_thread_impl.h" |
25 #include "content/browser/device_orientation/device_motion_service.h" | 23 #include "content/browser/device_orientation/device_motion_service.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 #endif | 112 #endif |
115 | 113 |
116 namespace content { | 114 namespace content { |
117 namespace { | 115 namespace { |
118 | 116 |
119 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 117 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
120 void SetupSandbox(const CommandLine& parsed_command_line) { | 118 void SetupSandbox(const CommandLine& parsed_command_line) { |
121 TRACE_EVENT0("startup", "SetupSandbox"); | 119 TRACE_EVENT0("startup", "SetupSandbox"); |
122 // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this | 120 // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this |
123 // code en masse out of chrome_main for now. | 121 // code en masse out of chrome_main for now. |
124 base::FilePath sandbox_binary; | 122 const char* sandbox_binary = NULL; |
125 bool env_chrome_devel_sandbox_set = false; | |
126 struct stat st; | 123 struct stat st; |
127 | 124 |
128 base::FilePath exe_dir; | 125 // In Chromium branded builds, developers can set an environment variable to |
129 if (PathService::Get(base::DIR_EXE, &exe_dir)) { | 126 // use the development sandbox. See |
130 base::FilePath sandbox_candidate = exe_dir.AppendASCII("chrome-sandbox"); | 127 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment |
131 if (base::PathExists(sandbox_candidate)) | 128 if (stat(base::kProcSelfExe, &st) == 0 && st.st_uid == getuid()) |
132 sandbox_binary = sandbox_candidate; | 129 sandbox_binary = getenv("CHROME_DEVEL_SANDBOX"); |
133 } | |
134 | 130 |
135 // In user-managed builds, including development builds, an environment | 131 #if defined(LINUX_SANDBOX_PATH) |
136 // variable is required to enable the sandbox. See | 132 if (!sandbox_binary) |
137 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment | 133 sandbox_binary = LINUX_SANDBOX_PATH; |
138 if (sandbox_binary.empty() && | 134 #endif |
139 stat(base::kProcSelfExe, &st) == 0 && st.st_uid == getuid()) { | |
140 const char* devel_sandbox_path = getenv("CHROME_DEVEL_SANDBOX"); | |
141 if (devel_sandbox_path) { | |
142 env_chrome_devel_sandbox_set = true; | |
143 sandbox_binary = base::FilePath(devel_sandbox_path); | |
144 } | |
145 } | |
146 | 135 |
147 const bool want_setuid_sandbox = | 136 const bool want_setuid_sandbox = |
148 !parsed_command_line.HasSwitch(switches::kNoSandbox) && | 137 !parsed_command_line.HasSwitch(switches::kNoSandbox) && |
149 !parsed_command_line.HasSwitch(switches::kDisableSetuidSandbox); | 138 !parsed_command_line.HasSwitch(switches::kDisableSetuidSandbox); |
150 | 139 |
151 if (want_setuid_sandbox) { | 140 if (want_setuid_sandbox) { |
152 static const char no_suid_error[] = "Running without the SUID sandbox! See " | 141 static const char no_suid_error[] = "Running without the SUID sandbox! See " |
153 "https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment " | 142 "https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment " |
154 "for more information on developing with the sandbox on."; | 143 "for more information on developing with the sandbox on."; |
155 if (sandbox_binary.empty()) { | 144 if (!sandbox_binary) { |
156 if (!env_chrome_devel_sandbox_set) { | 145 // This needs to be fatal. Talk to security@chromium.org if you feel |
157 // This needs to be fatal. Talk to security@chromium.org if you feel | 146 // otherwise. |
158 // otherwise. | 147 LOG(FATAL) << no_suid_error; |
159 LOG(FATAL) << no_suid_error; | 148 } |
160 } | 149 // TODO(jln): an empty CHROME_DEVEL_SANDBOX environment variable (as |
| 150 // opposed to a non existing one) is not fatal yet. This is needed because |
| 151 // of existing bots and scripts. Fix it (crbug.com/245376). |
| 152 if (sandbox_binary && *sandbox_binary == '\0') |
| 153 LOG(ERROR) << no_suid_error; |
| 154 } |
161 | 155 |
162 // TODO(jln): an empty CHROME_DEVEL_SANDBOX environment variable (as | 156 std::string sandbox_cmd; |
163 // opposed to a non existing one) is not fatal yet. This is needed | 157 if (want_setuid_sandbox && sandbox_binary) { |
164 // because of existing bots and scripts. Fix it (crbug.com/245376). | 158 sandbox_cmd = sandbox_binary; |
165 LOG(ERROR) << no_suid_error; | |
166 } | |
167 } | 159 } |
168 | 160 |
169 // Tickle the sandbox host and zygote host so they fork now. | 161 // Tickle the sandbox host and zygote host so they fork now. |
170 RenderSandboxHostLinux::GetInstance()->Init(sandbox_binary.value()); | 162 RenderSandboxHostLinux::GetInstance()->Init(sandbox_cmd); |
171 ZygoteHostImpl::GetInstance()->Init(sandbox_binary.value()); | 163 ZygoteHostImpl::GetInstance()->Init(sandbox_cmd); |
172 } | 164 } |
173 #endif | 165 #endif |
174 | 166 |
175 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 167 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
176 static void GLibLogHandler(const gchar* log_domain, | 168 static void GLibLogHandler(const gchar* log_domain, |
177 GLogLevelFlags log_level, | 169 GLogLevelFlags log_level, |
178 const gchar* message, | 170 const gchar* message, |
179 gpointer userdata) { | 171 gpointer userdata) { |
180 if (!log_domain) | 172 if (!log_domain) |
181 log_domain = "<unknown>"; | 173 log_domain = "<unknown>"; |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 if (parameters_.ui_task) | 948 if (parameters_.ui_task) |
957 base::MessageLoopForUI::current()->PostTask(FROM_HERE, | 949 base::MessageLoopForUI::current()->PostTask(FROM_HERE, |
958 *parameters_.ui_task); | 950 *parameters_.ui_task); |
959 | 951 |
960 base::RunLoop run_loop; | 952 base::RunLoop run_loop; |
961 run_loop.Run(); | 953 run_loop.Run(); |
962 #endif | 954 #endif |
963 } | 955 } |
964 | 956 |
965 } // namespace content | 957 } // namespace content |
OLD | NEW |