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

Unified Diff: chrome/browser/browser_main.cc

Issue 255036: Adding a SIGTERM handler for OS_POSIX builds. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months 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 | chrome/browser/browser_uitest.cc » ('j') | 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 27997)
+++ chrome/browser/browser_main.cc (working copy)
@@ -159,6 +159,24 @@
void SIGCHLDHandler(int signal) {
}
+// See comment below, where sigaction is called.
+void SIGTERMHandler(int signal) {
+ DCHECK_EQ(signal, SIGTERM);
+ LOG(WARNING) << "Addressing SIGTERM on " << PlatformThread::CurrentId();
+ MessageLoop* main_loop = ChromeThread::GetMessageLoop(ChromeThread::UI);
+ if (main_loop) {
+ main_loop->PostTask(FROM_HERE,
+ NewRunnableFunction(
+ BrowserList::CloseAllBrowsers, true));
+ }
+ // Reinstall the default handler. We had one shot at graceful shutdown.
+ LOG(WARNING) << "Posted task to UI thread; resetting SIGTERM handler.";
+ struct sigaction term_action;
+ memset(&term_action, 0, sizeof(term_action));
+ term_action.sa_handler = SIG_DFL;
+ CHECK(sigaction(SIGTERM, &term_action, NULL) == 0);
+}
+
// Sets the file descriptor soft limit to |max_descriptors| or the OS hard
// limit, whichever is lower.
void SetFileDescriptorLimit(unsigned int max_descriptors) {
@@ -237,6 +255,13 @@
action.sa_handler = SIGCHLDHandler;
CHECK(sigaction(SIGCHLD, &action, NULL) == 0);
+ // We need to handle SIGTERM, because that is how many POSIX-based distros ask
+ // processes to quit gracefully at shutdown time.
+ struct sigaction term_action;
+ memset(&term_action, 0, sizeof(term_action));
+ term_action.sa_handler = SIGTERMHandler;
+ CHECK(sigaction(SIGTERM, &term_action, NULL) == 0);
+
const std::wstring fd_limit_string =
parsed_command_line.GetSwitchValue(switches::kFileDescriptorLimit);
int fd_limit = 0;
« no previous file with comments | « no previous file | chrome/browser/browser_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698