Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: content/zygote/zygote_main_linux.cc

Issue 23956010: Define magic descriptors in one place. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/zygote/zygote_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/zygote/zygote_main.h" 5 #include "content/zygote/zygote_main.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <pthread.h> 9 #include <pthread.h>
10 #include <stdio.h> 10 #include <stdio.h>
11 #include <sys/socket.h> 11 #include <sys/socket.h>
12 #include <sys/stat.h> 12 #include <sys/stat.h>
13 #include <sys/types.h> 13 #include <sys/types.h>
14 #include <sys/wait.h> 14 #include <sys/wait.h>
15 #include <unistd.h> 15 #include <unistd.h>
16 16
17 #include "base/basictypes.h" 17 #include "base/basictypes.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "base/linux_util.h" 19 #include "base/linux_util.h"
20 #include "base/native_library.h" 20 #include "base/native_library.h"
21 #include "base/pickle.h" 21 #include "base/pickle.h"
22 #include "base/posix/eintr_wrapper.h" 22 #include "base/posix/eintr_wrapper.h"
23 #include "base/posix/unix_domain_socket_linux.h" 23 #include "base/posix/unix_domain_socket_linux.h"
24 #include "base/rand_util.h" 24 #include "base/rand_util.h"
25 #include "base/sys_info.h" 25 #include "base/sys_info.h"
26 #include "build/build_config.h" 26 #include "build/build_config.h"
27 #include "content/common/child_process_sandbox_support_impl_linux.h"
27 #include "content/common/font_config_ipc_linux.h" 28 #include "content/common/font_config_ipc_linux.h"
28 #include "content/common/pepper_plugin_list.h" 29 #include "content/common/pepper_plugin_list.h"
29 #include "content/common/sandbox_linux.h" 30 #include "content/common/sandbox_linux.h"
30 #include "content/common/zygote_commands_linux.h" 31 #include "content/common/zygote_commands_linux.h"
31 #include "content/public/common/content_switches.h" 32 #include "content/public/common/content_switches.h"
32 #include "content/public/common/main_function_params.h" 33 #include "content/public/common/main_function_params.h"
33 #include "content/public/common/pepper_plugin_info.h" 34 #include "content/public/common/pepper_plugin_info.h"
34 #include "content/public/common/sandbox_linux.h" 35 #include "content/public/common/sandbox_linux.h"
35 #include "content/public/common/zygote_fork_delegate_linux.h" 36 #include "content/public/common/zygote_fork_delegate_linux.h"
36 #include "content/zygote/zygote_linux.h" 37 #include "content/zygote/zygote_linux.h"
(...skipping 22 matching lines...) Expand all
59 static void ProxyLocaltimeCallToBrowser(time_t input, struct tm* output, 60 static void ProxyLocaltimeCallToBrowser(time_t input, struct tm* output,
60 char* timezone_out, 61 char* timezone_out,
61 size_t timezone_out_len) { 62 size_t timezone_out_len) {
62 Pickle request; 63 Pickle request;
63 request.WriteInt(LinuxSandbox::METHOD_LOCALTIME); 64 request.WriteInt(LinuxSandbox::METHOD_LOCALTIME);
64 request.WriteString( 65 request.WriteString(
65 std::string(reinterpret_cast<char*>(&input), sizeof(input))); 66 std::string(reinterpret_cast<char*>(&input), sizeof(input)));
66 67
67 uint8_t reply_buf[512]; 68 uint8_t reply_buf[512];
68 const ssize_t r = UnixDomainSocket::SendRecvMsg( 69 const ssize_t r = UnixDomainSocket::SendRecvMsg(
69 Zygote::kMagicSandboxIPCDescriptor, reply_buf, sizeof(reply_buf), NULL, 70 GetSandboxFD(), reply_buf, sizeof(reply_buf), NULL,
70 request); 71 request);
71 if (r == -1) { 72 if (r == -1) {
72 memset(output, 0, sizeof(struct tm)); 73 memset(output, 0, sizeof(struct tm));
73 return; 74 return;
74 } 75 }
75 76
76 Pickle reply(reinterpret_cast<char*>(reply_buf), r); 77 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
77 PickleIterator iter(reply); 78 PickleIterator iter(reply);
78 std::string result, timezone; 79 std::string result, timezone;
79 if (!reply.ReadString(&iter, &result) || 80 if (!reply.ReadString(&iter, &result) ||
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 #error Which SSL library are you using? 296 #error Which SSL library are you using?
296 #endif 297 #endif
297 #if defined(ENABLE_PLUGINS) 298 #if defined(ENABLE_PLUGINS)
298 // Ensure access to the Pepper plugins before the sandbox is turned on. 299 // Ensure access to the Pepper plugins before the sandbox is turned on.
299 PreloadPepperPlugins(); 300 PreloadPepperPlugins();
300 #endif 301 #endif
301 #if defined(ENABLE_WEBRTC) 302 #if defined(ENABLE_WEBRTC)
302 InitializeWebRtcModule(); 303 InitializeWebRtcModule();
303 #endif 304 #endif
304 SkFontConfigInterface::SetGlobal( 305 SkFontConfigInterface::SetGlobal(
305 new FontConfigIPC(Zygote::kMagicSandboxIPCDescriptor))->unref(); 306 new FontConfigIPC(GetSandboxFD()))->unref();
306 } 307 }
307 308
308 // Do nothing here 309 // Do nothing here
309 static void SIGCHLDHandler(int signal) { 310 static void SIGCHLDHandler(int signal) {
310 } 311 }
311 312
312 // The current process will become a process reaper like init. 313 // The current process will become a process reaper like init.
313 // We fork a child that will continue normally, when it dies, we can safely 314 // We fork a child that will continue normally, when it dies, we can safely
314 // exit. 315 // exit.
315 // We need to be careful we close the magic kZygoteIdFd properly in the parent 316 // We need to be careful we close the magic kZygoteIdFd properly in the parent
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 ZygoteForkDelegate* forkdelegate) { 462 ZygoteForkDelegate* forkdelegate) {
462 g_am_zygote_or_renderer = true; 463 g_am_zygote_or_renderer = true;
463 sandbox::InitLibcUrandomOverrides(); 464 sandbox::InitLibcUrandomOverrides();
464 465
465 LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance(); 466 LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance();
466 // This will pre-initialize the various sandboxes that need it. 467 // This will pre-initialize the various sandboxes that need it.
467 linux_sandbox->PreinitializeSandbox(); 468 linux_sandbox->PreinitializeSandbox();
468 469
469 if (forkdelegate != NULL) { 470 if (forkdelegate != NULL) {
470 VLOG(1) << "ZygoteMain: initializing fork delegate"; 471 VLOG(1) << "ZygoteMain: initializing fork delegate";
471 forkdelegate->Init(Zygote::kMagicSandboxIPCDescriptor); 472 forkdelegate->Init(GetSandboxFD());
472 } else { 473 } else {
473 VLOG(1) << "ZygoteMain: fork delegate is NULL"; 474 VLOG(1) << "ZygoteMain: fork delegate is NULL";
474 } 475 }
475 476
476 // Turn on the sandbox. 477 // Turn on the sandbox.
477 bool using_suid_sandbox = false; 478 bool using_suid_sandbox = false;
478 bool has_started_new_init = false; 479 bool has_started_new_init = false;
479 480
480 if (!EnterSuidSandbox(linux_sandbox, 481 if (!EnterSuidSandbox(linux_sandbox,
481 &using_suid_sandbox, 482 &using_suid_sandbox,
(...skipping 13 matching lines...) Expand all
495 } 496 }
496 497
497 int sandbox_flags = linux_sandbox->GetStatus(); 498 int sandbox_flags = linux_sandbox->GetStatus();
498 499
499 Zygote zygote(sandbox_flags, forkdelegate); 500 Zygote zygote(sandbox_flags, forkdelegate);
500 // This function call can return multiple times, once per fork(). 501 // This function call can return multiple times, once per fork().
501 return zygote.ProcessRequests(); 502 return zygote.ProcessRequests();
502 } 503 }
503 504
504 } // namespace content 505 } // namespace content
OLDNEW
« no previous file with comments | « content/zygote/zygote_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698