| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "services/service_manager/embedder/main.h" | 5 #include "services/service_manager/embedder/main.h" |
| 6 | 6 |
| 7 #include "base/allocator/features.h" | 7 #include "base/allocator/features.h" |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 MainDelegate* const main_delegate_; | 102 MainDelegate* const main_delegate_; |
| 103 | 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(ServiceProcessLauncherDelegateImpl); | 104 DISALLOW_COPY_AND_ASSIGN(ServiceProcessLauncherDelegateImpl); |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 107 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
| 108 | 108 |
| 109 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE. | 109 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE. |
| 110 void SetupSignalHandlers() { | 110 void SetupSignalHandlers() { |
| 111 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 112 switches::kDisableInProcessStackTraces)) { |
| 113 // Don't interfere with sanitizer signal handlers. |
| 114 return; |
| 115 } |
| 116 |
| 111 // Sanitise our signal handling state. Signals that were ignored by our | 117 // Sanitise our signal handling state. Signals that were ignored by our |
| 112 // parent will also be ignored by us. We also inherit our parent's sigmask. | 118 // parent will also be ignored by us. We also inherit our parent's sigmask. |
| 113 sigset_t empty_signal_set; | 119 sigset_t empty_signal_set; |
| 114 CHECK_EQ(0, sigemptyset(&empty_signal_set)); | 120 CHECK_EQ(0, sigemptyset(&empty_signal_set)); |
| 115 CHECK_EQ(0, sigprocmask(SIG_SETMASK, &empty_signal_set, NULL)); | 121 CHECK_EQ(0, sigprocmask(SIG_SETMASK, &empty_signal_set, NULL)); |
| 116 | 122 |
| 117 struct sigaction sigact; | 123 struct sigaction sigact; |
| 118 memset(&sigact, 0, sizeof(sigact)); | 124 memset(&sigact, 0, sizeof(sigact)); |
| 119 sigact.sa_handler = SIG_DFL; | 125 sigact.sa_handler = SIG_DFL; |
| 120 static const int signals_to_reset[] = { | 126 static const int signals_to_reset[] = { |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 #if defined(OS_MACOSX) && BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 336 #if defined(OS_MACOSX) && BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) |
| 331 base::allocator::InitializeAllocatorShim(); | 337 base::allocator::InitializeAllocatorShim(); |
| 332 #endif | 338 #endif |
| 333 base::EnableTerminationOnOutOfMemory(); | 339 base::EnableTerminationOnOutOfMemory(); |
| 334 | 340 |
| 335 #if defined(OS_WIN) | 341 #if defined(OS_WIN) |
| 336 base::win::RegisterInvalidParamHandler(); | 342 base::win::RegisterInvalidParamHandler(); |
| 337 ui::win::CreateATLModuleIfNeeded(); | 343 ui::win::CreateATLModuleIfNeeded(); |
| 338 #endif // defined(OS_WIN) | 344 #endif // defined(OS_WIN) |
| 339 | 345 |
| 340 // On Android setlocale() is not supported, and we don't override the signal | |
| 341 // handlers so we can get a stack trace when crashing. | |
| 342 #if defined(OS_POSIX) && !defined(OS_ANDROID) | |
| 343 // Set C library locale to make sure CommandLine can parse argument values in | |
| 344 // the correct encoding. | |
| 345 setlocale(LC_ALL, ""); | |
| 346 | |
| 347 SetupSignalHandlers(); | |
| 348 #endif | |
| 349 | |
| 350 #if !defined(OS_ANDROID) | 346 #if !defined(OS_ANDROID) |
| 351 // On Android, the command line is initialized when library is loaded. | 347 // On Android, the command line is initialized when library is loaded. |
| 352 int argc = 0; | 348 int argc = 0; |
| 353 const char** argv = nullptr; | 349 const char** argv = nullptr; |
| 354 | 350 |
| 355 #if defined(OS_POSIX) | 351 #if defined(OS_POSIX) |
| 356 // argc/argv are ignored on Windows; see command_line.h for details. | 352 // argc/argv are ignored on Windows; see command_line.h for details. |
| 357 argc = params.argc; | 353 argc = params.argc; |
| 358 argv = params.argv; | 354 argv = params.argv; |
| 359 #endif | 355 #endif |
| 360 | 356 |
| 361 base::CommandLine::Init(argc, argv); | 357 base::CommandLine::Init(argc, argv); |
| 362 | 358 |
| 363 #if defined(OS_POSIX) | 359 #if defined(OS_POSIX) |
| 364 PopulateFDsFromCommandLine(); | 360 PopulateFDsFromCommandLine(); |
| 365 #endif | 361 #endif |
| 366 | 362 |
| 367 base::EnableTerminationOnHeapCorruption(); | 363 base::EnableTerminationOnHeapCorruption(); |
| 368 | 364 |
| 369 SetProcessTitleFromCommandLine(argv); | 365 SetProcessTitleFromCommandLine(argv); |
| 370 #endif // !defined(OS_ANDROID) | 366 #endif // !defined(OS_ANDROID) |
| 371 | 367 |
| 368 // On Android setlocale() is not supported, and we don't override the signal |
| 369 // handlers so we can get a stack trace when crashing. |
| 370 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
| 371 // Set C library locale to make sure CommandLine can parse argument values in |
| 372 // the correct encoding. |
| 373 setlocale(LC_ALL, ""); |
| 374 |
| 375 SetupSignalHandlers(); |
| 376 #endif |
| 377 |
| 372 const auto& command_line = *base::CommandLine::ForCurrentProcess(); | 378 const auto& command_line = *base::CommandLine::ForCurrentProcess(); |
| 373 | 379 |
| 374 #if defined(OS_WIN) | 380 #if defined(OS_WIN) |
| 375 base::win::SetupCRT(command_line); | 381 base::win::SetupCRT(command_line); |
| 376 #endif | 382 #endif |
| 377 | 383 |
| 378 MainDelegate::InitializeParams init_params; | 384 MainDelegate::InitializeParams init_params; |
| 379 | 385 |
| 380 #if defined(OS_MACOSX) | 386 #if defined(OS_MACOSX) |
| 381 // We need this pool for all the objects created before we get to the event | 387 // We need this pool for all the objects created before we get to the event |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 autorelease_pool.reset(); | 472 autorelease_pool.reset(); |
| 467 #endif | 473 #endif |
| 468 | 474 |
| 469 if (process_type == ProcessType::kEmbedder) | 475 if (process_type == ProcessType::kEmbedder) |
| 470 delegate->ShutDownEmbedderProcess(); | 476 delegate->ShutDownEmbedderProcess(); |
| 471 | 477 |
| 472 return exit_code; | 478 return exit_code; |
| 473 } | 479 } |
| 474 | 480 |
| 475 } // namespace service_manager | 481 } // namespace service_manager |
| OLD | NEW |