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/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/path_service.h" | |
14 #include "base/pending_task.h" | 15 #include "base/pending_task.h" |
15 #include "base/power_monitor/power_monitor.h" | 16 #include "base/power_monitor/power_monitor.h" |
16 #include "base/process/process_metrics.h" | 17 #include "base/process/process_metrics.h" |
17 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
19 #include "base/system_monitor/system_monitor.h" | 20 #include "base/system_monitor/system_monitor.h" |
20 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
21 #include "base/timer/hi_res_timer_manager.h" | 22 #include "base/timer/hi_res_timer_manager.h" |
22 #include "content/browser/browser_thread_impl.h" | 23 #include "content/browser/browser_thread_impl.h" |
23 #include "content/browser/device_orientation/device_motion_service.h" | 24 #include "content/browser/device_orientation/device_motion_service.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 #endif | 111 #endif |
111 | 112 |
112 namespace content { | 113 namespace content { |
113 namespace { | 114 namespace { |
114 | 115 |
115 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 116 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
116 void SetupSandbox(const CommandLine& parsed_command_line) { | 117 void SetupSandbox(const CommandLine& parsed_command_line) { |
117 TRACE_EVENT0("startup", "SetupSandbox"); | 118 TRACE_EVENT0("startup", "SetupSandbox"); |
118 // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this | 119 // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this |
119 // code en masse out of chrome_main for now. | 120 // code en masse out of chrome_main for now. |
120 const char* sandbox_binary = NULL; | 121 base::FilePath sandbox_binary; |
122 bool env_chrome_devel_sandbox_set = false; | |
121 struct stat st; | 123 struct stat st; |
122 | 124 |
123 // In Chromium branded builds, developers can set an environment variable to | 125 // In Chromium branded builds, developers can set an environment variable to |
jln (very slow on Chromium)
2013/07/30 02:03:59
The comment is misleading (not your fault).
Could
Paweł Hajdan Jr.
2013/07/30 19:12:33
Done.
| |
124 // use the development sandbox. See | 126 // use the development sandbox. See |
125 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment | 127 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment |
126 if (stat(base::kProcSelfExe, &st) == 0 && st.st_uid == getuid()) | 128 if (stat(base::kProcSelfExe, &st) == 0 && st.st_uid == getuid()) { |
127 sandbox_binary = getenv("CHROME_DEVEL_SANDBOX"); | 129 const char* devel_sandbox_path = getenv("CHROME_DEVEL_SANDBOX"); |
128 | 130 if (devel_sandbox_path) { |
129 #if defined(LINUX_SANDBOX_PATH) | 131 env_chrome_devel_sandbox_set = true; |
130 if (!sandbox_binary) | 132 sandbox_binary = base::FilePath(devel_sandbox_path); |
131 sandbox_binary = LINUX_SANDBOX_PATH; | 133 } |
132 #endif | 134 } else { |
135 base::FilePath exe_dir; | |
jln (very slow on Chromium)
2013/07/30 02:03:59
I think Release Chrome will no longer start as roo
Paweł Hajdan Jr.
2013/07/30 19:12:33
Done.
| |
136 if (PathService::Get(base::DIR_EXE, &exe_dir)) | |
137 sandbox_binary = exe_dir.AppendASCII("chrome-sandbox"); | |
138 } | |
133 | 139 |
134 const bool want_setuid_sandbox = | 140 const bool want_setuid_sandbox = |
135 !parsed_command_line.HasSwitch(switches::kNoSandbox) && | 141 !parsed_command_line.HasSwitch(switches::kNoSandbox) && |
136 !parsed_command_line.HasSwitch(switches::kDisableSetuidSandbox); | 142 !parsed_command_line.HasSwitch(switches::kDisableSetuidSandbox); |
137 | 143 |
138 if (want_setuid_sandbox) { | 144 if (want_setuid_sandbox) { |
139 static const char no_suid_error[] = "Running without the SUID sandbox! See " | 145 static const char no_suid_error[] = "Running without the SUID sandbox! See " |
140 "https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment " | 146 "https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment " |
141 "for more information on developing with the sandbox on."; | 147 "for more information on developing with the sandbox on."; |
142 if (!sandbox_binary) { | 148 if (sandbox_binary.empty()) { |
143 // This needs to be fatal. Talk to security@chromium.org if you feel | 149 if (!env_chrome_devel_sandbox_set) { |
144 // otherwise. | 150 // This needs to be fatal. Talk to security@chromium.org if you feel |
145 LOG(FATAL) << no_suid_error; | 151 // otherwise. |
152 LOG(FATAL) << no_suid_error; | |
153 } | |
154 | |
155 // TODO(jln): an empty CHROME_DEVEL_SANDBOX environment variable (as | |
156 // opposed to a non existing one) is not fatal yet. This is needed | |
157 // because of existing bots and scripts. Fix it (crbug.com/245376). | |
158 LOG(ERROR) << no_suid_error; | |
146 } | 159 } |
147 // TODO(jln): an empty CHROME_DEVEL_SANDBOX environment variable (as | |
148 // opposed to a non existing one) is not fatal yet. This is needed because | |
149 // of existing bots and scripts. Fix it (crbug.com/245376). | |
150 if (sandbox_binary && *sandbox_binary == '\0') | |
151 LOG(ERROR) << no_suid_error; | |
152 } | |
153 | |
154 std::string sandbox_cmd; | |
155 if (want_setuid_sandbox && sandbox_binary) { | |
156 sandbox_cmd = sandbox_binary; | |
157 } | 160 } |
158 | 161 |
159 // Tickle the sandbox host and zygote host so they fork now. | 162 // Tickle the sandbox host and zygote host so they fork now. |
160 RenderSandboxHostLinux::GetInstance()->Init(sandbox_cmd); | 163 RenderSandboxHostLinux::GetInstance()->Init(sandbox_binary.value()); |
161 ZygoteHostImpl::GetInstance()->Init(sandbox_cmd); | 164 ZygoteHostImpl::GetInstance()->Init(sandbox_binary.value()); |
162 } | 165 } |
163 #endif | 166 #endif |
164 | 167 |
165 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 168 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
166 static void GLibLogHandler(const gchar* log_domain, | 169 static void GLibLogHandler(const gchar* log_domain, |
167 GLogLevelFlags log_level, | 170 GLogLevelFlags log_level, |
168 const gchar* message, | 171 const gchar* message, |
169 gpointer userdata) { | 172 gpointer userdata) { |
170 if (!log_domain) | 173 if (!log_domain) |
171 log_domain = "<unknown>"; | 174 log_domain = "<unknown>"; |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 if (parameters_.ui_task) | 904 if (parameters_.ui_task) |
902 base::MessageLoopForUI::current()->PostTask(FROM_HERE, | 905 base::MessageLoopForUI::current()->PostTask(FROM_HERE, |
903 *parameters_.ui_task); | 906 *parameters_.ui_task); |
904 | 907 |
905 base::RunLoop run_loop; | 908 base::RunLoop run_loop; |
906 run_loop.Run(); | 909 run_loop.Run(); |
907 #endif | 910 #endif |
908 } | 911 } |
909 | 912 |
910 } // namespace content | 913 } // namespace content |
OLD | NEW |