[email protected] | 7cb6beb8 | 2012-02-15 23:13:07 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 5 | #include "chrome/browser/chrome_browser_main_posix.h" |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 6 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 7 | #include <errno.h> |
[email protected] | 50795a0 | 2011-05-09 20:11:01 | [diff] [blame] | 8 | #include <limits.h> |
[email protected] | 7cb6beb8 | 2012-02-15 23:13:07 | [diff] [blame] | 9 | #include <pthread.h> |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 10 | #include <signal.h> |
| 11 | #include <sys/resource.h> |
[email protected] | 50795a0 | 2011-05-09 20:11:01 | [diff] [blame] | 12 | #include <unistd.h> |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 13 | |
[email protected] | 5cc4c42 | 2011-02-19 00:09:22 | [diff] [blame] | 14 | #include <string> |
| 15 | |
[email protected] | 97f3ac63 | 2011-10-19 20:09:56 | [diff] [blame] | 16 | #include "base/bind.h" |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 17 | #include "base/command_line.h" |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 18 | #include "base/logging.h" |
[email protected] | 2025d00 | 2012-11-14 20:54:35 | [diff] [blame] | 19 | #include "base/posix/eintr_wrapper.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 20 | #include "base/strings/string_number_conversions.h" |
[email protected] | fdf40f3e | 2013-07-11 23:55:46 | [diff] [blame] | 21 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 22 | #include "chrome/browser/lifetime/application_lifetime.h" |
[email protected] | 7e6f9f7 | 2013-02-06 19:59:37 | [diff] [blame] | 23 | #include "chrome/browser/sessions/session_restore.h" |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 24 | #include "chrome/common/chrome_switches.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 25 | #include "content/public/browser/browser_thread.h" |
[email protected] | 7e6f9f7 | 2013-02-06 19:59:37 | [diff] [blame] | 26 | #include "content/public/browser/notification_observer.h" |
| 27 | #include "content/public/browser/notification_registrar.h" |
| 28 | #include "content/public/browser/notification_service.h" |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 29 | |
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 30 | #if defined(TOOLKIT_GTK) |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 31 | #include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h" |
[email protected] | 1e54c1c | 2013-08-12 17:16:05 | [diff] [blame] | 32 | |
| 33 | #if defined(ENABLE_PRINTING) |
| 34 | #include "chrome/browser/printing/print_dialog_gtk.h" |
| 35 | #endif // defined(ENABLE_PRINTING) |
| 36 | #endif // defined(TOOLKIT_GTK) |
[email protected] | 5cc4c42 | 2011-02-19 00:09:22 | [diff] [blame] | 37 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 38 | using content::BrowserThread; |
| 39 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 40 | namespace { |
| 41 | |
| 42 | // See comment in |PreEarlyInitialization()|, where sigaction is called. |
| 43 | void SIGCHLDHandler(int signal) { |
| 44 | } |
| 45 | |
[email protected] | c2f5a83 | 2013-02-27 00:53:01 | [diff] [blame] | 46 | // The OSX fork() implementation can crash in the child process before |
| 47 | // fork() returns. In that case, the shutdown pipe will still be |
| 48 | // shared with the parent process. To prevent child crashes from |
| 49 | // causing parent shutdowns, |g_pipe_pid| is the pid for the process |
| 50 | // which registered |g_shutdown_pipe_write_fd|. |
| 51 | // See <http://crbug.com/175341>. |
| 52 | pid_t g_pipe_pid = -1; |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 53 | int g_shutdown_pipe_write_fd = -1; |
| 54 | int g_shutdown_pipe_read_fd = -1; |
| 55 | |
| 56 | // Common code between SIG{HUP, INT, TERM}Handler. |
| 57 | void GracefulShutdownHandler(int signal) { |
| 58 | // Reinstall the default handler. We had one shot at graceful shutdown. |
| 59 | struct sigaction action; |
| 60 | memset(&action, 0, sizeof(action)); |
| 61 | action.sa_handler = SIG_DFL; |
| 62 | RAW_CHECK(sigaction(signal, &action, NULL) == 0); |
| 63 | |
[email protected] | c2f5a83 | 2013-02-27 00:53:01 | [diff] [blame] | 64 | RAW_CHECK(g_pipe_pid == getpid()); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 65 | RAW_CHECK(g_shutdown_pipe_write_fd != -1); |
| 66 | RAW_CHECK(g_shutdown_pipe_read_fd != -1); |
| 67 | size_t bytes_written = 0; |
| 68 | do { |
| 69 | int rv = HANDLE_EINTR( |
| 70 | write(g_shutdown_pipe_write_fd, |
| 71 | reinterpret_cast<const char*>(&signal) + bytes_written, |
| 72 | sizeof(signal) - bytes_written)); |
| 73 | RAW_CHECK(rv >= 0); |
| 74 | bytes_written += rv; |
| 75 | } while (bytes_written < sizeof(signal)); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 76 | } |
| 77 | |
[email protected] | a1c2f8f | 2011-09-12 19:33:31 | [diff] [blame] | 78 | // See comment in |PostMainMessageLoopStart()|, where sigaction is called. |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 79 | void SIGHUPHandler(int signal) { |
| 80 | RAW_CHECK(signal == SIGHUP); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 81 | GracefulShutdownHandler(signal); |
| 82 | } |
| 83 | |
[email protected] | a1c2f8f | 2011-09-12 19:33:31 | [diff] [blame] | 84 | // See comment in |PostMainMessageLoopStart()|, where sigaction is called. |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 85 | void SIGINTHandler(int signal) { |
| 86 | RAW_CHECK(signal == SIGINT); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 87 | GracefulShutdownHandler(signal); |
| 88 | } |
| 89 | |
[email protected] | a1c2f8f | 2011-09-12 19:33:31 | [diff] [blame] | 90 | // See comment in |PostMainMessageLoopStart()|, where sigaction is called. |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 91 | void SIGTERMHandler(int signal) { |
| 92 | RAW_CHECK(signal == SIGTERM); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 93 | GracefulShutdownHandler(signal); |
| 94 | } |
| 95 | |
[email protected] | 7e6f9f7 | 2013-02-06 19:59:37 | [diff] [blame] | 96 | // ExitHandler takes care of servicing an exit (from a signal) at the |
| 97 | // appropriate time. Specifically if we get an exit and have not finished |
| 98 | // session restore we delay the exit. To do otherwise means we're exiting part |
| 99 | // way through startup which causes all sorts of problems. |
| 100 | class ExitHandler : public content::NotificationObserver { |
| 101 | public: |
| 102 | // Invokes exit when appropriate. |
| 103 | static void ExitWhenPossibleOnUIThread(); |
| 104 | |
| 105 | // Overridden from content::NotificationObserver: |
| 106 | virtual void Observe(int type, |
| 107 | const content::NotificationSource& source, |
| 108 | const content::NotificationDetails& details) OVERRIDE; |
| 109 | |
| 110 | private: |
| 111 | ExitHandler(); |
| 112 | virtual ~ExitHandler(); |
| 113 | |
| 114 | // Does the appropriate call to Exit. |
| 115 | static void Exit(); |
| 116 | |
| 117 | content::NotificationRegistrar registrar_; |
| 118 | |
| 119 | DISALLOW_COPY_AND_ASSIGN(ExitHandler); |
| 120 | }; |
| 121 | |
| 122 | // static |
| 123 | void ExitHandler::ExitWhenPossibleOnUIThread() { |
| 124 | DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 125 | if (SessionRestore::IsRestoringSynchronously()) { |
| 126 | // ExitHandler takes care of deleting itself. |
| 127 | new ExitHandler(); |
| 128 | } else { |
| 129 | Exit(); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | void ExitHandler::Observe(int type, |
| 134 | const content::NotificationSource& source, |
| 135 | const content::NotificationDetails& details) { |
| 136 | if (!SessionRestore::IsRestoringSynchronously()) { |
| 137 | // At this point the message loop may not be running (meaning we haven't |
| 138 | // gotten through browser startup, but are close). Post the task to at which |
| 139 | // point the message loop is running. |
| 140 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 141 | base::Bind(&ExitHandler::Exit)); |
| 142 | delete this; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | ExitHandler::ExitHandler() { |
| 147 | registrar_.Add( |
| 148 | this, chrome::NOTIFICATION_SESSION_RESTORE_DONE, |
| 149 | content::NotificationService::AllBrowserContextsAndSources()); |
| 150 | } |
| 151 | |
| 152 | ExitHandler::~ExitHandler() { |
| 153 | } |
| 154 | |
| 155 | // static |
| 156 | void ExitHandler::Exit() { |
| 157 | #if defined(OS_CHROMEOS) |
| 158 | // On ChromeOS, exiting on signal should be always clean. |
[email protected] | 0c98ab65 | 2013-02-18 00:39:37 | [diff] [blame] | 159 | chrome::ExitCleanly(); |
[email protected] | 7e6f9f7 | 2013-02-06 19:59:37 | [diff] [blame] | 160 | #else |
[email protected] | 0c98ab65 | 2013-02-18 00:39:37 | [diff] [blame] | 161 | chrome::AttemptExit(); |
[email protected] | 7e6f9f7 | 2013-02-06 19:59:37 | [diff] [blame] | 162 | #endif |
| 163 | } |
| 164 | |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 165 | class ShutdownDetector : public base::PlatformThread::Delegate { |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 166 | public: |
| 167 | explicit ShutdownDetector(int shutdown_fd); |
| 168 | |
[email protected] | b94584a | 2013-02-07 03:02:08 | [diff] [blame] | 169 | virtual void ThreadMain() OVERRIDE; |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 170 | |
| 171 | private: |
| 172 | const int shutdown_fd_; |
| 173 | |
| 174 | DISALLOW_COPY_AND_ASSIGN(ShutdownDetector); |
| 175 | }; |
| 176 | |
| 177 | ShutdownDetector::ShutdownDetector(int shutdown_fd) |
| 178 | : shutdown_fd_(shutdown_fd) { |
| 179 | CHECK_NE(shutdown_fd_, -1); |
| 180 | } |
| 181 | |
[email protected] | 50795a0 | 2011-05-09 20:11:01 | [diff] [blame] | 182 | // These functions are used to help us diagnose crash dumps that happen |
| 183 | // during the shutdown process. |
| 184 | NOINLINE void ShutdownFDReadError() { |
| 185 | // Ensure function isn't optimized away. |
| 186 | asm(""); |
| 187 | sleep(UINT_MAX); |
| 188 | } |
| 189 | |
| 190 | NOINLINE void ShutdownFDClosedError() { |
| 191 | // Ensure function isn't optimized away. |
| 192 | asm(""); |
| 193 | sleep(UINT_MAX); |
| 194 | } |
| 195 | |
[email protected] | 2421393 | 2011-10-25 18:29:33 | [diff] [blame] | 196 | NOINLINE void ExitPosted() { |
[email protected] | 50795a0 | 2011-05-09 20:11:01 | [diff] [blame] | 197 | // Ensure function isn't optimized away. |
| 198 | asm(""); |
| 199 | sleep(UINT_MAX); |
| 200 | } |
| 201 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 202 | void ShutdownDetector::ThreadMain() { |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 203 | base::PlatformThread::SetName("CrShutdownDetector"); |
[email protected] | fa9bf438 | 2010-07-23 19:40:05 | [diff] [blame] | 204 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 205 | int signal; |
| 206 | size_t bytes_read = 0; |
| 207 | ssize_t ret; |
| 208 | do { |
| 209 | ret = HANDLE_EINTR( |
| 210 | read(shutdown_fd_, |
| 211 | reinterpret_cast<char*>(&signal) + bytes_read, |
| 212 | sizeof(signal) - bytes_read)); |
| 213 | if (ret < 0) { |
| 214 | NOTREACHED() << "Unexpected error: " << strerror(errno); |
[email protected] | 50795a0 | 2011-05-09 20:11:01 | [diff] [blame] | 215 | ShutdownFDReadError(); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 216 | break; |
| 217 | } else if (ret == 0) { |
| 218 | NOTREACHED() << "Unexpected closure of shutdown pipe."; |
[email protected] | 50795a0 | 2011-05-09 20:11:01 | [diff] [blame] | 219 | ShutdownFDClosedError(); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 220 | break; |
| 221 | } |
| 222 | bytes_read += ret; |
| 223 | } while (bytes_read < sizeof(signal)); |
[email protected] | 8e96e50 | 2010-10-21 20:57:12 | [diff] [blame] | 224 | VLOG(1) << "Handling shutdown for signal " << signal << "."; |
[email protected] | 7e6f9f7 | 2013-02-06 19:59:37 | [diff] [blame] | 225 | base::Closure task = base::Bind(&ExitHandler::ExitWhenPossibleOnUIThread); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 226 | |
[email protected] | bc63a07 | 2011-06-28 21:12:57 | [diff] [blame] | 227 | if (!BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task)) { |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 228 | // Without a UI thread to post the exit task to, there aren't many |
| 229 | // options. Raise the signal again. The default handler will pick it up |
| 230 | // and cause an ungraceful exit. |
| 231 | RAW_LOG(WARNING, "No UI thread, exiting ungracefully."); |
| 232 | kill(getpid(), signal); |
| 233 | |
| 234 | // The signal may be handled on another thread. Give that a chance to |
| 235 | // happen. |
| 236 | sleep(3); |
| 237 | |
| 238 | // We really should be dead by now. For whatever reason, we're not. Exit |
| 239 | // immediately, with the exit status set to the signal number with bit 8 |
| 240 | // set. On the systems that we care about, this exit status is what is |
| 241 | // normally used to indicate an exit by this signal's default handler. |
| 242 | // This mechanism isn't a de jure standard, but even in the worst case, it |
| 243 | // should at least result in an immediate exit. |
| 244 | RAW_LOG(WARNING, "Still here, exiting really ungracefully."); |
| 245 | _exit(signal | (1 << 7)); |
| 246 | } |
[email protected] | 2421393 | 2011-10-25 18:29:33 | [diff] [blame] | 247 | ExitPosted(); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | // Sets the file descriptor soft limit to |max_descriptors| or the OS hard |
| 251 | // limit, whichever is lower. |
| 252 | void SetFileDescriptorLimit(unsigned int max_descriptors) { |
| 253 | struct rlimit limits; |
| 254 | if (getrlimit(RLIMIT_NOFILE, &limits) == 0) { |
| 255 | unsigned int new_limit = max_descriptors; |
| 256 | if (limits.rlim_max > 0 && limits.rlim_max < max_descriptors) { |
| 257 | new_limit = limits.rlim_max; |
| 258 | } |
| 259 | limits.rlim_cur = new_limit; |
| 260 | if (setrlimit(RLIMIT_NOFILE, &limits) != 0) { |
| 261 | PLOG(INFO) << "Failed to set file descriptor limit"; |
| 262 | } |
| 263 | } else { |
| 264 | PLOG(INFO) << "Failed to get file descriptor limit"; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | } // namespace |
| 269 | |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 270 | // ChromeBrowserMainPartsPosix ------------------------------------------------- |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 271 | |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 272 | ChromeBrowserMainPartsPosix::ChromeBrowserMainPartsPosix( |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 273 | const content::MainFunctionParams& parameters) |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 274 | : ChromeBrowserMainParts(parameters) { |
| 275 | } |
| 276 | |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 277 | void ChromeBrowserMainPartsPosix::PreEarlyInitialization() { |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 278 | ChromeBrowserMainParts::PreEarlyInitialization(); |
| 279 | |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 280 | // We need to accept SIGCHLD, even though our handler is a no-op because |
| 281 | // otherwise we cannot wait on children. (According to POSIX 2001.) |
| 282 | struct sigaction action; |
| 283 | memset(&action, 0, sizeof(action)); |
| 284 | action.sa_handler = SIGCHLDHandler; |
| 285 | CHECK(sigaction(SIGCHLD, &action, NULL) == 0); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 286 | |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 287 | const std::string fd_limit_string = |
| 288 | parsed_command_line().GetSwitchValueASCII( |
| 289 | switches::kFileDescriptorLimit); |
| 290 | int fd_limit = 0; |
| 291 | if (!fd_limit_string.empty()) { |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 292 | base::StringToInt(fd_limit_string, &fd_limit); |
[email protected] | c1275ae | 2010-07-12 17:40:49 | [diff] [blame] | 293 | } |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 294 | #if defined(OS_MACOSX) |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 295 | // We use quite a few file descriptors for our IPC, and the default limit on |
| 296 | // the Mac is low (256), so bump it up if there is no explicit override. |
| 297 | if (fd_limit == 0) { |
| 298 | fd_limit = 1024; |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 299 | } |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 300 | #endif // OS_MACOSX |
| 301 | if (fd_limit > 0) |
| 302 | SetFileDescriptorLimit(fd_limit); |
| 303 | } |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 304 | |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 305 | void ChromeBrowserMainPartsPosix::PostMainMessageLoopStart() { |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 306 | ChromeBrowserMainParts::PostMainMessageLoopStart(); |
| 307 | |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 308 | int pipefd[2]; |
| 309 | int ret = pipe(pipefd); |
| 310 | if (ret < 0) { |
| 311 | PLOG(DFATAL) << "Failed to create pipe"; |
| 312 | } else { |
[email protected] | c2f5a83 | 2013-02-27 00:53:01 | [diff] [blame] | 313 | g_pipe_pid = getpid(); |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 314 | g_shutdown_pipe_read_fd = pipefd[0]; |
| 315 | g_shutdown_pipe_write_fd = pipefd[1]; |
[email protected] | 77e7d8c | 2013-01-25 15:40:28 | [diff] [blame] | 316 | #if !defined(ADDRESS_SANITIZER) && !defined(KEEP_SHADOW_STACKS) |
[email protected] | 7cb6beb8 | 2012-02-15 23:13:07 | [diff] [blame] | 317 | const size_t kShutdownDetectorThreadStackSize = PTHREAD_STACK_MIN; |
[email protected] | 5a4a7ab | 2012-04-05 07:11:12 | [diff] [blame] | 318 | #else |
[email protected] | 77e7d8c | 2013-01-25 15:40:28 | [diff] [blame] | 319 | // ASan instrumentation and -finstrument-functions (used for keeping the |
| 320 | // shadow stacks) bloat the stack frames, so we need to increase the stack |
[email protected] | 5a4a7ab | 2012-04-05 07:11:12 | [diff] [blame] | 321 | // size to avoid hitting the guard page. |
| 322 | const size_t kShutdownDetectorThreadStackSize = PTHREAD_STACK_MIN * 4; |
| 323 | #endif |
[email protected] | 5e63416 | 2010-07-27 17:37:38 | [diff] [blame] | 324 | // TODO(viettrungluu,willchan): crbug.com/29675 - This currently leaks, so |
| 325 | // if you change this, you'll probably need to change the suppression. |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 326 | if (!base::PlatformThread::CreateNonJoinable( |
| 327 | kShutdownDetectorThreadStackSize, |
| 328 | new ShutdownDetector(g_shutdown_pipe_read_fd))) { |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 329 | LOG(DFATAL) << "Failed to create shutdown detector task."; |
| 330 | } |
| 331 | } |
[email protected] | a1c2f8f | 2011-09-12 19:33:31 | [diff] [blame] | 332 | // Setup signal handlers for shutdown AFTER shutdown pipe is setup because |
| 333 | // it may be called right away after handler is set. |
| 334 | |
| 335 | // If adding to this list of signal handlers, note the new signal probably |
| 336 | // needs to be reset in child processes. See |
| 337 | // base/process_util_posix.cc:LaunchProcess. |
| 338 | |
| 339 | // We need to handle SIGTERM, because that is how many POSIX-based distros ask |
| 340 | // processes to quit gracefully at shutdown time. |
| 341 | struct sigaction action; |
| 342 | memset(&action, 0, sizeof(action)); |
| 343 | action.sa_handler = SIGTERMHandler; |
| 344 | CHECK(sigaction(SIGTERM, &action, NULL) == 0); |
| 345 | // Also handle SIGINT - when the user terminates the browser via Ctrl+C. If |
| 346 | // the browser process is being debugged, GDB will catch the SIGINT first. |
| 347 | action.sa_handler = SIGINTHandler; |
| 348 | CHECK(sigaction(SIGINT, &action, NULL) == 0); |
| 349 | // And SIGHUP, for when the terminal disappears. On shutdown, many Linux |
| 350 | // distros send SIGHUP, SIGTERM, and then SIGKILL. |
| 351 | action.sa_handler = SIGHUPHandler; |
| 352 | CHECK(sigaction(SIGHUP, &action, NULL) == 0); |
[email protected] | 5cc4c42 | 2011-02-19 00:09:22 | [diff] [blame] | 353 | |
[email protected] | 1e54c1c | 2013-08-12 17:16:05 | [diff] [blame] | 354 | #if defined(TOOLKIT_GTK) && defined(ENABLE_PRINTING) |
[email protected] | ea5e81d9 | 2011-11-08 18:45:15 | [diff] [blame] | 355 | printing::PrintingContextGtk::SetCreatePrintDialogFunction( |
[email protected] | eaa389e | 2011-04-11 04:58:20 | [diff] [blame] | 356 | &PrintDialogGtk::CreatePrintDialog); |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 357 | #endif |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 358 | } |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 359 | |
| 360 | void ChromeBrowserMainPartsPosix::ShowMissingLocaleMessageBox() { |
| 361 | #if defined(OS_CHROMEOS) |
| 362 | NOTREACHED(); // Should not ever happen on ChromeOS. |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 363 | #elif defined(OS_MACOSX) |
| 364 | // Not called on Mac because we load the locale files differently. |
| 365 | NOTREACHED(); |
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 366 | #elif defined(TOOLKIT_GTK) |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 367 | ChromeBrowserMainExtraPartsGtk::ShowMessageBox( |
| 368 | chrome_browser::kMissingLocaleDataMessage); |
[email protected] | 95721f6 | 2012-03-29 03:24:37 | [diff] [blame] | 369 | #elif defined(USE_AURA) |
| 370 | // TODO(port): We may want a views based message dialog here eventually, but |
| 371 | // for now, crash. |
| 372 | NOTREACHED(); |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 373 | #else |
| 374 | #error "Need MessageBox implementation." |
| 375 | #endif |
| 376 | } |