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

Unified Diff: chrome/browser/browser_main.cc

Issue 269048: SIGTERM should cause the application to exit on the Mac (Closed) Base URL: svn://svn.chromium.org/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 | « chrome/browser/browser_list.cc ('k') | chrome/browser/chrome_application_mac.h » ('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 28692)
+++ chrome/browser/browser_main.cc (working copy)
@@ -155,26 +155,49 @@
}
#if defined(OS_POSIX)
-// See comment below, where sigaction is called.
+// See comment in BrowserMain, where sigaction is called.
void SIGCHLDHandler(int signal) {
}
-// See comment below, where sigaction is called.
+// See comment in BrowserMain, 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));
+ // Post the exit task to the main thread.
+ main_loop->PostTask(
+ FROM_HERE, NewRunnableFunction(BrowserList::CloseAllBrowsersAndExit));
+ LOG(WARNING) << "Posted task to UI thread; resetting SIGTERM handler";
}
+
// 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);
+
+ if (!main_loop) {
+ // 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.
+ LOG(WARNING) << "No UI thread, exiting ungracefully";
+ kill(getpid(), signal);
+
+ // The signal may be handled on another thread. Give that a chance to
+ // happen.
+ sleep(3);
+
+ // We really should be dead by now. For whatever reason, we're not. Exit
+ // immediately, with the exit status set to the signal number with bit 8
+ // set. On the systems that we care about, this exit status is what is
+ // normally used to indicate an exit by this signal's default handler.
+ // This mechanism isn't a de jure standard, but even in the worst case, it
+ // should at least result in an immediate exit.
+ LOG(WARNING) << "Still here, exiting really ungracefully";
+ _exit(signal | (1 << 7));
+ }
}
// Sets the file descriptor soft limit to |max_descriptors| or the OS hard
« no previous file with comments | « chrome/browser/browser_list.cc ('k') | chrome/browser/chrome_application_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698