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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/browser_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/browser_main.h" 5 #include "chrome/browser/browser_main.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 #elif defined(OS_POSIX) 152 #elif defined(OS_POSIX)
153 MessageLoopForUI::current()->Run(); 153 MessageLoopForUI::current()->Run();
154 #endif 154 #endif
155 } 155 }
156 156
157 #if defined(OS_POSIX) 157 #if defined(OS_POSIX)
158 // See comment below, where sigaction is called. 158 // See comment below, where sigaction is called.
159 void SIGCHLDHandler(int signal) { 159 void SIGCHLDHandler(int signal) {
160 } 160 }
161 161
162 // See comment below, where sigaction is called.
163 void SIGTERMHandler(int signal) {
164 DCHECK_EQ(signal, SIGTERM);
165 LOG(WARNING) << "Addressing SIGTERM on " << PlatformThread::CurrentId();
166 MessageLoop* main_loop = ChromeThread::GetMessageLoop(ChromeThread::UI);
167 if (main_loop) {
168 main_loop->PostTask(FROM_HERE,
169 NewRunnableFunction(
170 BrowserList::CloseAllBrowsers, true));
171 }
172 // Reinstall the default handler. We had one shot at graceful shutdown.
173 LOG(WARNING) << "Posted task to UI thread; resetting SIGTERM handler.";
174 struct sigaction term_action;
175 memset(&term_action, 0, sizeof(term_action));
176 term_action.sa_handler = SIG_DFL;
177 CHECK(sigaction(SIGTERM, &term_action, NULL) == 0);
178 }
179
162 // Sets the file descriptor soft limit to |max_descriptors| or the OS hard 180 // Sets the file descriptor soft limit to |max_descriptors| or the OS hard
163 // limit, whichever is lower. 181 // limit, whichever is lower.
164 void SetFileDescriptorLimit(unsigned int max_descriptors) { 182 void SetFileDescriptorLimit(unsigned int max_descriptors) {
165 struct rlimit limits; 183 struct rlimit limits;
166 if (getrlimit(RLIMIT_NOFILE, &limits) == 0) { 184 if (getrlimit(RLIMIT_NOFILE, &limits) == 0) {
167 unsigned int new_limit = max_descriptors; 185 unsigned int new_limit = max_descriptors;
168 if (limits.rlim_max > 0 && limits.rlim_max < max_descriptors) { 186 if (limits.rlim_max > 0 && limits.rlim_max < max_descriptors) {
169 new_limit = limits.rlim_max; 187 new_limit = limits.rlim_max;
170 } 188 }
171 limits.rlim_cur = new_limit; 189 limits.rlim_cur = new_limit;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 #endif 248 #endif
231 249
232 #if defined(OS_POSIX) 250 #if defined(OS_POSIX)
233 // We need to accept SIGCHLD, even though our handler is a no-op because 251 // We need to accept SIGCHLD, even though our handler is a no-op because
234 // otherwise we cannot wait on children. (According to POSIX 2001.) 252 // otherwise we cannot wait on children. (According to POSIX 2001.)
235 struct sigaction action; 253 struct sigaction action;
236 memset(&action, 0, sizeof(action)); 254 memset(&action, 0, sizeof(action));
237 action.sa_handler = SIGCHLDHandler; 255 action.sa_handler = SIGCHLDHandler;
238 CHECK(sigaction(SIGCHLD, &action, NULL) == 0); 256 CHECK(sigaction(SIGCHLD, &action, NULL) == 0);
239 257
258 // We need to handle SIGTERM, because that is how many POSIX-based distros ask
259 // processes to quit gracefully at shutdown time.
260 struct sigaction term_action;
261 memset(&term_action, 0, sizeof(term_action));
262 term_action.sa_handler = SIGTERMHandler;
263 CHECK(sigaction(SIGTERM, &term_action, NULL) == 0);
264
240 const std::wstring fd_limit_string = 265 const std::wstring fd_limit_string =
241 parsed_command_line.GetSwitchValue(switches::kFileDescriptorLimit); 266 parsed_command_line.GetSwitchValue(switches::kFileDescriptorLimit);
242 int fd_limit = 0; 267 int fd_limit = 0;
243 if (!fd_limit_string.empty()) { 268 if (!fd_limit_string.empty()) {
244 StringToInt(WideToUTF16Hack(fd_limit_string), &fd_limit); 269 StringToInt(WideToUTF16Hack(fd_limit_string), &fd_limit);
245 } 270 }
246 #if defined(OS_MACOSX) 271 #if defined(OS_MACOSX)
247 // We use quite a few file descriptors for our IPC, and the default limit on 272 // We use quite a few file descriptors for our IPC, and the default limit on
248 // the Mac is low (256), so bump it up if there is no explicit override. 273 // the Mac is low (256), so bump it up if there is no explicit override.
249 if (fd_limit == 0) { 274 if (fd_limit == 0) {
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 if (metrics) 866 if (metrics)
842 metrics->Stop(); 867 metrics->Stop();
843 868
844 // browser_shutdown takes care of deleting browser_process, so we need to 869 // browser_shutdown takes care of deleting browser_process, so we need to
845 // release it. 870 // release it.
846 browser_process.release(); 871 browser_process.release();
847 browser_shutdown::Shutdown(); 872 browser_shutdown::Shutdown();
848 873
849 return result_code; 874 return result_code;
850 } 875 }
OLDNEW
« 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