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

Unified Diff: chrome/browser/browser_main.cc

Issue 431048: Merge 33046 - Posix: Catch SIGHUP/SIGINT and do a clean shutdown.... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/249/src/
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/browser_main.cc
===================================================================
--- chrome/browser/browser_main.cc (revision 33052)
+++ chrome/browser/browser_main.cc (working copy)
@@ -168,25 +168,26 @@
void SIGCHLDHandler(int signal) {
}
-// See comment in BrowserMain, where sigaction is called.
-void SIGTERMHandler(int signal) {
- DCHECK_EQ(signal, SIGTERM);
- LOG(WARNING) << "Addressing SIGTERM on " << PlatformThread::CurrentId();
+// Common code between SIG{HUP, INT, TERM}Handler.
+void GracefulShutdownHandler(int signal, const int expected_signal) {
+ DCHECK_EQ(signal, expected_signal);
+ LOG(WARNING) << "Addressing signal " << expected_signal << " on "
+ << PlatformThread::CurrentId();
bool posted = ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
NewRunnableFunction(BrowserList::CloseAllBrowsersAndExit));
- if (posted) {
- LOG(WARNING) << "Posted task to UI thread; resetting SIGTERM handler";
- }
// Reinstall the default handler. We had one shot at graceful shutdown.
struct sigaction term_action;
memset(&term_action, 0, sizeof(term_action));
term_action.sa_handler = SIG_DFL;
- CHECK(sigaction(SIGTERM, &term_action, NULL) == 0);
+ CHECK(sigaction(expected_signal, &term_action, NULL) == 0);
- if (!posted) {
+ if (posted) {
+ LOG(WARNING) << "Posted task to UI thread; resetting signal "
+ << expected_signal << " handler";
+ } else {
// Without a UI thread to post the exit task to, there aren't many
// options. Raise the signal again. The default handler will pick it up
// and cause an ungraceful exit.
@@ -208,6 +209,21 @@
}
}
+// See comment in BrowserMain, where sigaction is called.
+void SIGHUPHandler(int signal) {
+ GracefulShutdownHandler(signal, SIGHUP);
+}
+
+// See comment in BrowserMain, where sigaction is called.
+void SIGINTHandler(int signal) {
+ GracefulShutdownHandler(signal, SIGINT);
+}
+
+// See comment in BrowserMain, where sigaction is called.
+void SIGTERMHandler(int signal) {
+ GracefulShutdownHandler(signal, SIGTERM);
+}
+
// Sets the file descriptor soft limit to |max_descriptors| or the OS hard
// limit, whichever is lower.
void SetFileDescriptorLimit(unsigned int max_descriptors) {
@@ -292,6 +308,12 @@
memset(&term_action, 0, sizeof(term_action));
term_action.sa_handler = SIGTERMHandler;
CHECK(sigaction(SIGTERM, &term_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.
+ CHECK(sigaction(SIGINT, &term_action, NULL) == 0);
+ // And SIGHUP, for when the terminal disappears. On shutdown, many Linux
+ // distros send SIGHUP, SIGTERM, and then SIGKILL.
+ CHECK(sigaction(SIGHUP, &term_action, NULL) == 0);
const std::wstring fd_limit_string =
parsed_command_line.GetSwitchValue(switches::kFileDescriptorLimit);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698