| 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 "chrome/browser/chrome_browser_main_posix.h" | 5 #include "chrome/browser/chrome_browser_main_posix.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 #include <pthread.h> | 9 #include <pthread.h> |
| 10 #include <signal.h> | 10 #include <signal.h> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 using content::BrowserThread; | 35 using content::BrowserThread; |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 // See comment in |PreEarlyInitialization()|, where sigaction is called. | 39 // See comment in |PreEarlyInitialization()|, where sigaction is called. |
| 40 void SIGCHLDHandler(int signal) { | 40 void SIGCHLDHandler(int signal) { |
| 41 } | 41 } |
| 42 | 42 |
| 43 // The OSX fork() implementation can crash in the child process before |
| 44 // fork() returns. In that case, the shutdown pipe will still be |
| 45 // shared with the parent process. To prevent child crashes from |
| 46 // causing parent shutdowns, |g_pipe_pid| is the pid for the process |
| 47 // which registered |g_shutdown_pipe_write_fd|. |
| 48 // See <http://crbug.com/175341>. |
| 49 pid_t g_pipe_pid = -1; |
| 43 int g_shutdown_pipe_write_fd = -1; | 50 int g_shutdown_pipe_write_fd = -1; |
| 44 int g_shutdown_pipe_read_fd = -1; | 51 int g_shutdown_pipe_read_fd = -1; |
| 45 | 52 |
| 46 // Common code between SIG{HUP, INT, TERM}Handler. | 53 // Common code between SIG{HUP, INT, TERM}Handler. |
| 47 void GracefulShutdownHandler(int signal) { | 54 void GracefulShutdownHandler(int signal) { |
| 48 // Reinstall the default handler. We had one shot at graceful shutdown. | 55 // Reinstall the default handler. We had one shot at graceful shutdown. |
| 49 struct sigaction action; | 56 struct sigaction action; |
| 50 memset(&action, 0, sizeof(action)); | 57 memset(&action, 0, sizeof(action)); |
| 51 action.sa_handler = SIG_DFL; | 58 action.sa_handler = SIG_DFL; |
| 52 RAW_CHECK(sigaction(signal, &action, NULL) == 0); | 59 RAW_CHECK(sigaction(signal, &action, NULL) == 0); |
| 53 | 60 |
| 61 RAW_CHECK(g_pipe_pid == getpid()); |
| 54 RAW_CHECK(g_shutdown_pipe_write_fd != -1); | 62 RAW_CHECK(g_shutdown_pipe_write_fd != -1); |
| 55 RAW_CHECK(g_shutdown_pipe_read_fd != -1); | 63 RAW_CHECK(g_shutdown_pipe_read_fd != -1); |
| 56 size_t bytes_written = 0; | 64 size_t bytes_written = 0; |
| 57 do { | 65 do { |
| 58 int rv = HANDLE_EINTR( | 66 int rv = HANDLE_EINTR( |
| 59 write(g_shutdown_pipe_write_fd, | 67 write(g_shutdown_pipe_write_fd, |
| 60 reinterpret_cast<const char*>(&signal) + bytes_written, | 68 reinterpret_cast<const char*>(&signal) + bytes_written, |
| 61 sizeof(signal) - bytes_written)); | 69 sizeof(signal) - bytes_written)); |
| 62 RAW_CHECK(rv >= 0); | 70 RAW_CHECK(rv >= 0); |
| 63 bytes_written += rv; | 71 bytes_written += rv; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 } | 300 } |
| 293 | 301 |
| 294 void ChromeBrowserMainPartsPosix::PostMainMessageLoopStart() { | 302 void ChromeBrowserMainPartsPosix::PostMainMessageLoopStart() { |
| 295 ChromeBrowserMainParts::PostMainMessageLoopStart(); | 303 ChromeBrowserMainParts::PostMainMessageLoopStart(); |
| 296 | 304 |
| 297 int pipefd[2]; | 305 int pipefd[2]; |
| 298 int ret = pipe(pipefd); | 306 int ret = pipe(pipefd); |
| 299 if (ret < 0) { | 307 if (ret < 0) { |
| 300 PLOG(DFATAL) << "Failed to create pipe"; | 308 PLOG(DFATAL) << "Failed to create pipe"; |
| 301 } else { | 309 } else { |
| 310 g_pipe_pid = getpid(); |
| 302 g_shutdown_pipe_read_fd = pipefd[0]; | 311 g_shutdown_pipe_read_fd = pipefd[0]; |
| 303 g_shutdown_pipe_write_fd = pipefd[1]; | 312 g_shutdown_pipe_write_fd = pipefd[1]; |
| 304 #if !defined(ADDRESS_SANITIZER) && !defined(KEEP_SHADOW_STACKS) | 313 #if !defined(ADDRESS_SANITIZER) && !defined(KEEP_SHADOW_STACKS) |
| 305 const size_t kShutdownDetectorThreadStackSize = PTHREAD_STACK_MIN; | 314 const size_t kShutdownDetectorThreadStackSize = PTHREAD_STACK_MIN; |
| 306 #else | 315 #else |
| 307 // ASan instrumentation and -finstrument-functions (used for keeping the | 316 // ASan instrumentation and -finstrument-functions (used for keeping the |
| 308 // shadow stacks) bloat the stack frames, so we need to increase the stack | 317 // shadow stacks) bloat the stack frames, so we need to increase the stack |
| 309 // size to avoid hitting the guard page. | 318 // size to avoid hitting the guard page. |
| 310 const size_t kShutdownDetectorThreadStackSize = PTHREAD_STACK_MIN * 4; | 319 const size_t kShutdownDetectorThreadStackSize = PTHREAD_STACK_MIN * 4; |
| 311 #endif | 320 #endif |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 ChromeBrowserMainExtraPartsGtk::ShowMessageBox( | 364 ChromeBrowserMainExtraPartsGtk::ShowMessageBox( |
| 356 chrome_browser::kMissingLocaleDataMessage); | 365 chrome_browser::kMissingLocaleDataMessage); |
| 357 #elif defined(USE_AURA) | 366 #elif defined(USE_AURA) |
| 358 // TODO(port): We may want a views based message dialog here eventually, but | 367 // TODO(port): We may want a views based message dialog here eventually, but |
| 359 // for now, crash. | 368 // for now, crash. |
| 360 NOTREACHED(); | 369 NOTREACHED(); |
| 361 #else | 370 #else |
| 362 #error "Need MessageBox implementation." | 371 #error "Need MessageBox implementation." |
| 363 #endif | 372 #endif |
| 364 } | 373 } |
| OLD | NEW |