summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chrome_browser_main_posix.cc
diff options
context:
space:
mode:
authoroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-12 19:33:31 +0000
committeroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-12 19:33:31 +0000
commita1c2f8f87f4d4ba6b5fb1dc22ee0d46f6d1e50d9 (patch)
treef6f4677f42964d8992ca4d0815b1470dabde7123 /chrome/browser/chrome_browser_main_posix.cc
parent65e83be2d3cd6adc78efb4be30d81a6cb1b1747c (diff)
downloadchromium_src-a1c2f8f87f4d4ba6b5fb1dc22ee0d46f6d1e50d9.zip
chromium_src-a1c2f8f87f4d4ba6b5fb1dc22ee0d46f6d1e50d9.tar.gz
chromium_src-a1c2f8f87f4d4ba6b5fb1dc22ee0d46f6d1e50d9.tar.bz2
Register signal handlers after shutdown pipe is setup.
Chrome fails at RAW_CHECK(g_shutdown_pipe_write_fd != -1) if it receives signal in a window where signal handlers are registered, but shutdown pipe isn't setup yet. BUG=chromium-os:17606 TEST=autotest with session manager sending SIGTERM no longer crash Review URL: http://codereview.chromium.org/7464013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100739 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chrome_browser_main_posix.cc')
-rw-r--r--chrome/browser/chrome_browser_main_posix.cc45
1 files changed, 24 insertions, 21 deletions
diff --git a/chrome/browser/chrome_browser_main_posix.cc b/chrome/browser/chrome_browser_main_posix.cc
index 382e542..aa54aec 100644
--- a/chrome/browser/chrome_browser_main_posix.cc
+++ b/chrome/browser/chrome_browser_main_posix.cc
@@ -54,19 +54,19 @@ void GracefulShutdownHandler(int signal) {
} while (bytes_written < sizeof(signal));
}
-// See comment in |PreEarlyInitialization()|, where sigaction is called.
+// See comment in |PostMainMessageLoopStart()|, where sigaction is called.
void SIGHUPHandler(int signal) {
RAW_CHECK(signal == SIGHUP);
GracefulShutdownHandler(signal);
}
-// See comment in |PreEarlyInitialization()|, where sigaction is called.
+// See comment in |PostMainMessageLoopStart()|, where sigaction is called.
void SIGINTHandler(int signal) {
RAW_CHECK(signal == SIGINT);
GracefulShutdownHandler(signal);
}
-// See comment in |PreEarlyInitialization()|, where sigaction is called.
+// See comment in |PostMainMessageLoopStart()|, where sigaction is called.
void SIGTERMHandler(int signal) {
RAW_CHECK(signal == SIGTERM);
GracefulShutdownHandler(signal);
@@ -198,24 +198,6 @@ void ChromeBrowserMainPartsPosix::PreEarlyInitialization() {
action.sa_handler = SIGCHLDHandler;
CHECK(sigaction(SIGCHLD, &action, NULL) == 0);
- // If adding to this list of signal handlers, note the new signal probably
- // needs to be reset in child processes. See
- // base/process_util_posix.cc:LaunchProcess.
-
- // We need to handle SIGTERM, because that is how many POSIX-based distros ask
- // processes to quit gracefully at shutdown time.
- memset(&action, 0, sizeof(action));
- action.sa_handler = SIGTERMHandler;
- CHECK(sigaction(SIGTERM, &action, NULL) == 0);
- // Also handle SIGINT - when the user terminates the browser via Ctrl+C. If
- // the browser process is being debugged, GDB will catch the SIGINT first.
- action.sa_handler = SIGINTHandler;
- CHECK(sigaction(SIGINT, &action, NULL) == 0);
- // And SIGHUP, for when the terminal disappears. On shutdown, many Linux
- // distros send SIGHUP, SIGTERM, and then SIGKILL.
- action.sa_handler = SIGHUPHandler;
- CHECK(sigaction(SIGHUP, &action, NULL) == 0);
-
const std::string fd_limit_string =
parsed_command_line().GetSwitchValueASCII(
switches::kFileDescriptorLimit);
@@ -251,6 +233,27 @@ void ChromeBrowserMainPartsPosix::PostMainMessageLoopStart() {
LOG(DFATAL) << "Failed to create shutdown detector task.";
}
}
+ // Setup signal handlers for shutdown AFTER shutdown pipe is setup because
+ // it may be called right away after handler is set.
+
+ // If adding to this list of signal handlers, note the new signal probably
+ // needs to be reset in child processes. See
+ // base/process_util_posix.cc:LaunchProcess.
+
+ // We need to handle SIGTERM, because that is how many POSIX-based distros ask
+ // processes to quit gracefully at shutdown time.
+ struct sigaction action;
+ memset(&action, 0, sizeof(action));
+ action.sa_handler = SIGTERMHandler;
+ CHECK(sigaction(SIGTERM, &action, NULL) == 0);
+ // Also handle SIGINT - when the user terminates the browser via Ctrl+C. If
+ // the browser process is being debugged, GDB will catch the SIGINT first.
+ action.sa_handler = SIGINTHandler;
+ CHECK(sigaction(SIGINT, &action, NULL) == 0);
+ // And SIGHUP, for when the terminal disappears. On shutdown, many Linux
+ // distros send SIGHUP, SIGTERM, and then SIGKILL.
+ action.sa_handler = SIGHUPHandler;
+ CHECK(sigaction(SIGHUP, &action, NULL) == 0);
#if defined(TOOLKIT_USES_GTK) && !defined(OS_CHROMEOS)
printing::PrintingContextCairo::SetCreatePrintDialogFunction(