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

Side by Side Diff: chrome/app/chrome_dll_main.cc

Issue 262020: Add support for getting the real process id from within the suid sandbox. The... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix SOCK_ typo, only send zygote magic string when using the sandbox Created 11 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « base/linux_util.h ('k') | chrome/browser/renderer_host/render_sandbox_host_linux.h » ('j') | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 // TODO(port): the ifdefs in here are a first step towards trying to determine 5 // TODO(port): the ifdefs in here are a first step towards trying to determine
6 // the correct abstraction for all the OS functionality required at this 6 // the correct abstraction for all the OS functionality required at this
7 // stage of process initialization. It should not be taken as a final 7 // stage of process initialization. It should not be taken as a final
8 // abstraction. 8 // abstraction.
9 9
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 11
12 #if defined(OS_WIN) 12 #if defined(OS_WIN)
13 #include <algorithm> 13 #include <algorithm>
14 #include <atlbase.h> 14 #include <atlbase.h>
15 #include <atlapp.h> 15 #include <atlapp.h>
16 #include <malloc.h> 16 #include <malloc.h>
17 #include <new.h> 17 #include <new.h>
18 #elif defined(OS_POSIX) 18 #elif defined(OS_POSIX)
19 #include <locale.h> 19 #include <locale.h>
20 #include <signal.h> 20 #include <signal.h>
21 #include <sys/stat.h>
21 #include <sys/types.h> 22 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <unistd.h> 23 #include <unistd.h>
24 #endif 24 #endif
25 25
26 #if defined(OS_LINUX) 26 #if defined(OS_LINUX)
27 #include <gdk/gdk.h> 27 #include <gdk/gdk.h>
28 #include <glib.h> 28 #include <glib.h>
29 #include <gtk/gtk.h> 29 #include <gtk/gtk.h>
30 #include <stdlib.h>
30 #include <string.h> 31 #include <string.h>
31 #endif 32 #endif
32 33
33 #include "app/app_paths.h" 34 #include "app/app_paths.h"
34 #include "app/resource_bundle.h" 35 #include "app/resource_bundle.h"
35 #include "base/at_exit.h" 36 #include "base/at_exit.h"
36 #include "base/command_line.h" 37 #include "base/command_line.h"
37 #include "base/debug_util.h" 38 #include "base/debug_util.h"
38 #include "base/i18n/icu_util.h" 39 #include "base/i18n/icu_util.h"
39 #include "base/message_loop.h" 40 #include "base/message_loop.h"
(...skipping 11 matching lines...) Expand all
51 #include "chrome/common/chrome_paths.h" 52 #include "chrome/common/chrome_paths.h"
52 #include "chrome/common/chrome_switches.h" 53 #include "chrome/common/chrome_switches.h"
53 #include "chrome/common/logging_chrome.h" 54 #include "chrome/common/logging_chrome.h"
54 #include "chrome/common/main_function_params.h" 55 #include "chrome/common/main_function_params.h"
55 #include "chrome/common/sandbox_init_wrapper.h" 56 #include "chrome/common/sandbox_init_wrapper.h"
56 #include "ipc/ipc_switches.h" 57 #include "ipc/ipc_switches.h"
57 58
58 #if defined(OS_LINUX) 59 #if defined(OS_LINUX)
59 #include "base/nss_init.h" 60 #include "base/nss_init.h"
60 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" 61 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h"
62 #include "chrome/browser/zygote_host_linux.h"
61 #endif 63 #endif
62 64
63 #if defined(OS_MACOSX) 65 #if defined(OS_MACOSX)
64 #include "base/mac_util.h" 66 #include "base/mac_util.h"
65 #include "chrome/common/chrome_paths_internal.h" 67 #include "chrome/common/chrome_paths_internal.h"
66 #include "chrome/app/breakpad_mac.h" 68 #include "chrome/app/breakpad_mac.h"
67 #include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h" 69 #include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h"
68 #endif 70 #endif
69 71
70 #if defined(OS_POSIX) 72 #if defined(OS_POSIX)
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 base::ProcessId browser_pid; 380 base::ProcessId browser_pid;
379 if (process_type.empty()) { 381 if (process_type.empty()) {
380 browser_pid = base::GetCurrentProcId(); 382 browser_pid = base::GetCurrentProcId();
381 } else { 383 } else {
382 #if defined(OS_WIN) 384 #if defined(OS_WIN)
383 std::wstring channel_name = 385 std::wstring channel_name =
384 parsed_command_line.GetSwitchValue(switches::kProcessChannelID); 386 parsed_command_line.GetSwitchValue(switches::kProcessChannelID);
385 387
386 browser_pid = 388 browser_pid =
387 static_cast<base::ProcessId>(StringToInt(WideToASCII(channel_name))); 389 static_cast<base::ProcessId>(StringToInt(WideToASCII(channel_name)));
388 DCHECK(browser_pid != 0); 390 DCHECK_NE(browser_pid, 0);
389 #else 391 #else
390 browser_pid = base::GetCurrentProcId(); 392 browser_pid = base::GetCurrentProcId();
391 #endif 393 #endif
392 394
393 #if defined(OS_POSIX) 395 #if defined(OS_POSIX)
394 // When you hit Ctrl-C in a terminal running the browser 396 // When you hit Ctrl-C in a terminal running the browser
395 // process, a SIGINT is delivered to the entire process group. 397 // process, a SIGINT is delivered to the entire process group.
396 // When debugging the browser process via gdb, gdb catches the 398 // When debugging the browser process via gdb, gdb catches the
397 // SIGINT for the browser process (and dumps you back to the gdb 399 // SIGINT for the browser process (and dumps you back to the gdb
398 // console) but doesn't for the child processes, killing them. 400 // console) but doesn't for the child processes, killing them.
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 &autorelease_pool); 574 &autorelease_pool);
573 rv = RendererMain(main_params); 575 rv = RendererMain(main_params);
574 } else { 576 } else {
575 rv = 0; 577 rv = 0;
576 } 578 }
577 #else 579 #else
578 NOTIMPLEMENTED(); 580 NOTIMPLEMENTED();
579 #endif 581 #endif
580 } else if (process_type.empty()) { 582 } else if (process_type.empty()) {
581 #if defined(OS_LINUX) 583 #if defined(OS_LINUX)
582 // Tickle the sandbox host so it forks now. 584 const char* sandbox_binary = NULL;
583 Singleton<RenderSandboxHostLinux>().get(); 585 struct stat st;
586
587 // In Chromium branded builds, developers can set an environment variable to
588 // use the development sandbox. See
589 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment
590 if (stat("/proc/self/exe", &st) == 0 && st.st_uid == getuid())
591 sandbox_binary = getenv("CHROME_DEVEL_SANDBOX");
592
593 #if defined(LINUX_SANDBOX_PATH)
594 if (!sandbox_binary)
595 sandbox_binary = LINUX_SANDBOX_PATH;
596 #endif
597
598 std::string sandbox_cmd;
599 if (sandbox_binary)
600 sandbox_cmd = sandbox_binary;
601
602 // Tickle the sandbox host and zygote host so they fork now.
603 RenderSandboxHostLinux* shost = Singleton<RenderSandboxHostLinux>().get();
604 shost->Init(sandbox_cmd);
605 ZygoteHost* zhost = Singleton<ZygoteHost>().get();
606 zhost->Init(sandbox_cmd);
584 607
585 // We want to be sure to init NSPR on the main thread. 608 // We want to be sure to init NSPR on the main thread.
586 base::EnsureNSPRInit(); 609 base::EnsureNSPRInit();
587 610
588 g_thread_init(NULL); 611 g_thread_init(NULL);
589 // Glib type system initialization. Needed at least for gconf, 612 // Glib type system initialization. Needed at least for gconf,
590 // used in net/proxy/proxy_config_service_linux.cc. Most likely 613 // used in net/proxy/proxy_config_service_linux.cc. Most likely
591 // this is superfluous as gtk_init() ought to do this. It's 614 // this is superfluous as gtk_init() ought to do this. It's
592 // definitely harmless, so retained as a reminder of this 615 // definitely harmless, so retained as a reminder of this
593 // requirement for gconf. 616 // requirement for gconf.
594 g_type_init(); 617 g_type_init();
595 // gtk_init() can change |argc| and |argv|. 618 // gtk_init() can change |argc| and |argv|.
596 gtk_init(&argc, &argv); 619 gtk_init(&argc, &argv);
597 SetUpGLibLogHandler(); 620 SetUpGLibLogHandler();
598 #endif 621 #endif // defined(OS_LINUX)
599 622
600 ScopedOleInitializer ole_initializer; 623 ScopedOleInitializer ole_initializer;
601 rv = BrowserMain(main_params); 624 rv = BrowserMain(main_params);
602 } else { 625 } else {
603 NOTREACHED() << "Unknown process type"; 626 NOTREACHED() << "Unknown process type";
604 } 627 }
605 628
606 if (!process_type.empty()) { 629 if (!process_type.empty()) {
607 ResourceBundle::CleanupSharedInstance(); 630 ResourceBundle::CleanupSharedInstance();
608 } 631 }
609 632
610 #if defined(OS_WIN) 633 #if defined(OS_WIN)
611 #ifdef _CRTDBG_MAP_ALLOC 634 #ifdef _CRTDBG_MAP_ALLOC
612 _CrtDumpMemoryLeaks(); 635 _CrtDumpMemoryLeaks();
613 #endif // _CRTDBG_MAP_ALLOC 636 #endif // _CRTDBG_MAP_ALLOC
614 637
615 _Module.Term(); 638 _Module.Term();
616 #endif 639 #endif
617 640
618 logging::CleanupChromeLogging(); 641 logging::CleanupChromeLogging();
619 642
620 #if defined(OS_MACOSX) && defined(GOOGLE_CHROME_BUILD) 643 #if defined(OS_MACOSX) && defined(GOOGLE_CHROME_BUILD)
621 // TODO(mark): See the TODO(mark) above at InitCrashReporter. 644 // TODO(mark): See the TODO(mark) above at InitCrashReporter.
622 DestructCrashReporter(); 645 DestructCrashReporter();
623 #endif // OS_MACOSX && GOOGLE_CHROME_BUILD 646 #endif // OS_MACOSX && GOOGLE_CHROME_BUILD
624 647
625 return rv; 648 return rv;
626 } 649 }
OLDNEW
« no previous file with comments | « base/linux_util.h ('k') | chrome/browser/renderer_host/render_sandbox_host_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698