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|. | |
viettrungluu
2013/02/25 23:15:06
Could you include a reference to the bug(s)?
Scott Hess - ex-Googler
2013/02/25 23:20:46
Done.
| |
48 pid_t g_pipe_pid = -1; | |
43 int g_shutdown_pipe_write_fd = -1; | 49 int g_shutdown_pipe_write_fd = -1; |
44 int g_shutdown_pipe_read_fd = -1; | 50 int g_shutdown_pipe_read_fd = -1; |
45 | 51 |
46 // Common code between SIG{HUP, INT, TERM}Handler. | 52 // Common code between SIG{HUP, INT, TERM}Handler. |
47 void GracefulShutdownHandler(int signal) { | 53 void GracefulShutdownHandler(int signal) { |
48 // Reinstall the default handler. We had one shot at graceful shutdown. | 54 // Reinstall the default handler. We had one shot at graceful shutdown. |
49 struct sigaction action; | 55 struct sigaction action; |
50 memset(&action, 0, sizeof(action)); | 56 memset(&action, 0, sizeof(action)); |
51 action.sa_handler = SIG_DFL; | 57 action.sa_handler = SIG_DFL; |
52 RAW_CHECK(sigaction(signal, &action, NULL) == 0); | 58 RAW_CHECK(sigaction(signal, &action, NULL) == 0); |
53 | 59 |
60 RAW_CHECK(g_pipe_pid == getpid()); | |
54 RAW_CHECK(g_shutdown_pipe_write_fd != -1); | 61 RAW_CHECK(g_shutdown_pipe_write_fd != -1); |
55 RAW_CHECK(g_shutdown_pipe_read_fd != -1); | 62 RAW_CHECK(g_shutdown_pipe_read_fd != -1); |
56 size_t bytes_written = 0; | 63 size_t bytes_written = 0; |
57 do { | 64 do { |
58 int rv = HANDLE_EINTR( | 65 int rv = HANDLE_EINTR( |
59 write(g_shutdown_pipe_write_fd, | 66 write(g_shutdown_pipe_write_fd, |
60 reinterpret_cast<const char*>(&signal) + bytes_written, | 67 reinterpret_cast<const char*>(&signal) + bytes_written, |
61 sizeof(signal) - bytes_written)); | 68 sizeof(signal) - bytes_written)); |
62 RAW_CHECK(rv >= 0); | 69 RAW_CHECK(rv >= 0); |
63 bytes_written += rv; | 70 bytes_written += rv; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 void ChromeBrowserMainPartsPosix::PostMainMessageLoopStart() { | 301 void ChromeBrowserMainPartsPosix::PostMainMessageLoopStart() { |
295 ChromeBrowserMainParts::PostMainMessageLoopStart(); | 302 ChromeBrowserMainParts::PostMainMessageLoopStart(); |
296 | 303 |
297 int pipefd[2]; | 304 int pipefd[2]; |
298 int ret = pipe(pipefd); | 305 int ret = pipe(pipefd); |
299 if (ret < 0) { | 306 if (ret < 0) { |
300 PLOG(DFATAL) << "Failed to create pipe"; | 307 PLOG(DFATAL) << "Failed to create pipe"; |
301 } else { | 308 } else { |
302 g_shutdown_pipe_read_fd = pipefd[0]; | 309 g_shutdown_pipe_read_fd = pipefd[0]; |
303 g_shutdown_pipe_write_fd = pipefd[1]; | 310 g_shutdown_pipe_write_fd = pipefd[1]; |
311 g_pipe_pid = getpid(); | |
viettrungluu
2013/02/25 23:15:06
Nit: You may as well initialize these in the same
Scott Hess - ex-Googler
2013/02/25 23:20:46
Done.
I was not willing to initialize the write f
| |
304 #if !defined(ADDRESS_SANITIZER) && !defined(KEEP_SHADOW_STACKS) | 312 #if !defined(ADDRESS_SANITIZER) && !defined(KEEP_SHADOW_STACKS) |
305 const size_t kShutdownDetectorThreadStackSize = PTHREAD_STACK_MIN; | 313 const size_t kShutdownDetectorThreadStackSize = PTHREAD_STACK_MIN; |
306 #else | 314 #else |
307 // ASan instrumentation and -finstrument-functions (used for keeping the | 315 // ASan instrumentation and -finstrument-functions (used for keeping the |
308 // shadow stacks) bloat the stack frames, so we need to increase the stack | 316 // shadow stacks) bloat the stack frames, so we need to increase the stack |
309 // size to avoid hitting the guard page. | 317 // size to avoid hitting the guard page. |
310 const size_t kShutdownDetectorThreadStackSize = PTHREAD_STACK_MIN * 4; | 318 const size_t kShutdownDetectorThreadStackSize = PTHREAD_STACK_MIN * 4; |
311 #endif | 319 #endif |
312 // TODO(viettrungluu,willchan): crbug.com/29675 - This currently leaks, so | 320 // TODO(viettrungluu,willchan): crbug.com/29675 - This currently leaks, so |
313 // if you change this, you'll probably need to change the suppression. | 321 // if you change this, you'll probably need to change the suppression. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 ChromeBrowserMainExtraPartsGtk::ShowMessageBox( | 363 ChromeBrowserMainExtraPartsGtk::ShowMessageBox( |
356 chrome_browser::kMissingLocaleDataMessage); | 364 chrome_browser::kMissingLocaleDataMessage); |
357 #elif defined(USE_AURA) | 365 #elif defined(USE_AURA) |
358 // TODO(port): We may want a views based message dialog here eventually, but | 366 // TODO(port): We may want a views based message dialog here eventually, but |
359 // for now, crash. | 367 // for now, crash. |
360 NOTREACHED(); | 368 NOTREACHED(); |
361 #else | 369 #else |
362 #error "Need MessageBox implementation." | 370 #error "Need MessageBox implementation." |
363 #endif | 371 #endif |
364 } | 372 } |
OLD | NEW |