OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/crash_handler_host_linux.h" | 5 #include "chrome/browser/crash_handler_host_linux.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <sys/syscall.h> | 10 #include <sys/syscall.h> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 | 12 |
| 13 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" |
13 #include "base/eintr_wrapper.h" | 15 #include "base/eintr_wrapper.h" |
14 #include "base/file_path.h" | 16 #include "base/file_path.h" |
15 #include "base/format_macros.h" | 17 #include "base/format_macros.h" |
16 #include "base/linux_util.h" | 18 #include "base/linux_util.h" |
17 #include "base/logging.h" | 19 #include "base/logging.h" |
18 #include "base/memory/singleton.h" | 20 #include "base/memory/singleton.h" |
19 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
20 #include "base/path_service.h" | 22 #include "base/path_service.h" |
21 #include "base/rand_util.h" | 23 #include "base/rand_util.h" |
22 #include "base/string_util.h" | 24 #include "base/string_util.h" |
23 #include "base/stringprintf.h" | 25 #include "base/stringprintf.h" |
24 #include "base/task.h" | |
25 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
26 #include "breakpad/src/client/linux/handler/exception_handler.h" | 27 #include "breakpad/src/client/linux/handler/exception_handler.h" |
27 #include "breakpad/src/client/linux/minidump_writer/linux_dumper.h" | 28 #include "breakpad/src/client/linux/minidump_writer/linux_dumper.h" |
28 #include "breakpad/src/client/linux/minidump_writer/minidump_writer.h" | 29 #include "breakpad/src/client/linux/minidump_writer/minidump_writer.h" |
29 #include "chrome/app/breakpad_linux.h" | 30 #include "chrome/app/breakpad_linux.h" |
30 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
31 #include "chrome/common/env_vars.h" | 32 #include "chrome/common/env_vars.h" |
32 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
33 | 34 |
34 using content::BrowserThread; | 35 using content::BrowserThread; |
(...skipping 18 matching lines...) Expand all Loading... |
53 delete[] info->crash_url; | 54 delete[] info->crash_url; |
54 delete[] info->guid; | 55 delete[] info->guid; |
55 delete[] info->distro; | 56 delete[] info->distro; |
56 delete info; | 57 delete info; |
57 } | 58 } |
58 | 59 |
59 } // namespace | 60 } // namespace |
60 | 61 |
61 // Since classes derived from CrashHandlerHostLinux are singletons, it's only | 62 // Since classes derived from CrashHandlerHostLinux are singletons, it's only |
62 // destroyed at the end of the processes lifetime, which is greater in span than | 63 // destroyed at the end of the processes lifetime, which is greater in span than |
63 // the lifetime of the IO message loop. | 64 // the lifetime of the IO message loop. Thus, all calls to base::Bind() use |
64 DISABLE_RUNNABLE_METHOD_REFCOUNT(CrashHandlerHostLinux); | 65 // non-refcounted pointers. |
65 | 66 |
66 CrashHandlerHostLinux::CrashHandlerHostLinux() | 67 CrashHandlerHostLinux::CrashHandlerHostLinux() |
67 : shutting_down_(false) { | 68 : shutting_down_(false) { |
68 int fds[2]; | 69 int fds[2]; |
69 // We use SOCK_SEQPACKET rather than SOCK_DGRAM to prevent the process from | 70 // We use SOCK_SEQPACKET rather than SOCK_DGRAM to prevent the process from |
70 // sending datagrams to other sockets on the system. The sandbox may prevent | 71 // sending datagrams to other sockets on the system. The sandbox may prevent |
71 // the process from calling socket() to create new sockets, but it'll still | 72 // the process from calling socket() to create new sockets, but it'll still |
72 // inherit some sockets. With PF_UNIX+SOCK_DGRAM, it can call sendmsg to send | 73 // inherit some sockets. With PF_UNIX+SOCK_DGRAM, it can call sendmsg to send |
73 // a datagram to any (abstract) socket on the same system. With | 74 // a datagram to any (abstract) socket on the same system. With |
74 // SOCK_SEQPACKET, this is prevented. | 75 // SOCK_SEQPACKET, this is prevented. |
75 CHECK_EQ(socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds), 0); | 76 CHECK_EQ(socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds), 0); |
76 static const int on = 1; | 77 static const int on = 1; |
77 | 78 |
78 // Enable passcred on the server end of the socket | 79 // Enable passcred on the server end of the socket |
79 CHECK_EQ(setsockopt(fds[1], SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)), 0); | 80 CHECK_EQ(setsockopt(fds[1], SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)), 0); |
80 | 81 |
81 process_socket_ = fds[0]; | 82 process_socket_ = fds[0]; |
82 browser_socket_ = fds[1]; | 83 browser_socket_ = fds[1]; |
83 | 84 |
84 BrowserThread::PostTask( | 85 BrowserThread::PostTask( |
85 BrowserThread::IO, FROM_HERE, | 86 BrowserThread::IO, FROM_HERE, |
86 NewRunnableMethod(this, &CrashHandlerHostLinux::Init)); | 87 base::Bind(&CrashHandlerHostLinux::Init, base::Unretained(this))); |
87 } | 88 } |
88 | 89 |
89 CrashHandlerHostLinux::~CrashHandlerHostLinux() { | 90 CrashHandlerHostLinux::~CrashHandlerHostLinux() { |
90 HANDLE_EINTR(close(process_socket_)); | 91 HANDLE_EINTR(close(process_socket_)); |
91 HANDLE_EINTR(close(browser_socket_)); | 92 HANDLE_EINTR(close(browser_socket_)); |
92 } | 93 } |
93 | 94 |
94 void CrashHandlerHostLinux::Init() { | 95 void CrashHandlerHostLinux::Init() { |
95 MessageLoopForIO* ml = MessageLoopForIO::current(); | 96 MessageLoopForIO* ml = MessageLoopForIO::current(); |
96 CHECK(ml->WatchFileDescriptor( | 97 CHECK(ml->WatchFileDescriptor( |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 info->guid = guid; | 311 info->guid = guid; |
311 | 312 |
312 info->distro_length = strlen(distro); | 313 info->distro_length = strlen(distro); |
313 info->distro = distro; | 314 info->distro = distro; |
314 | 315 |
315 info->upload = (getenv(env_vars::kHeadless) == NULL); | 316 info->upload = (getenv(env_vars::kHeadless) == NULL); |
316 info->process_start_time = uptime; | 317 info->process_start_time = uptime; |
317 | 318 |
318 BrowserThread::PostTask( | 319 BrowserThread::PostTask( |
319 BrowserThread::FILE, FROM_HERE, | 320 BrowserThread::FILE, FROM_HERE, |
320 NewRunnableMethod(this, | 321 base::Bind(&CrashHandlerHostLinux::WriteDumpFile, |
321 &CrashHandlerHostLinux::WriteDumpFile, | 322 base::Unretained(this), |
322 info, | 323 info, |
323 crashing_pid, | 324 crashing_pid, |
324 crash_context, | 325 crash_context, |
325 signal_fd)); | 326 signal_fd)); |
326 } | 327 } |
327 | 328 |
328 void CrashHandlerHostLinux::WriteDumpFile(BreakpadInfo* info, | 329 void CrashHandlerHostLinux::WriteDumpFile(BreakpadInfo* info, |
329 pid_t crashing_pid, | 330 pid_t crashing_pid, |
330 char* crash_context, | 331 char* crash_context, |
331 int signal_fd) { | 332 int signal_fd) { |
332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
333 | 334 |
334 FilePath dumps_path("/tmp"); | 335 FilePath dumps_path("/tmp"); |
335 PathService::Get(base::DIR_TEMP, &dumps_path); | 336 PathService::Get(base::DIR_TEMP, &dumps_path); |
(...skipping 13 matching lines...) Expand all Loading... |
349 delete[] crash_context; | 350 delete[] crash_context; |
350 | 351 |
351 // Freed in CrashDumpTask(); | 352 // Freed in CrashDumpTask(); |
352 char* minidump_filename_str = new char[minidump_filename.length() + 1]; | 353 char* minidump_filename_str = new char[minidump_filename.length() + 1]; |
353 minidump_filename.copy(minidump_filename_str, minidump_filename.length()); | 354 minidump_filename.copy(minidump_filename_str, minidump_filename.length()); |
354 minidump_filename_str[minidump_filename.length()] = '\0'; | 355 minidump_filename_str[minidump_filename.length()] = '\0'; |
355 info->filename = minidump_filename_str; | 356 info->filename = minidump_filename_str; |
356 | 357 |
357 BrowserThread::PostTask( | 358 BrowserThread::PostTask( |
358 BrowserThread::IO, FROM_HERE, | 359 BrowserThread::IO, FROM_HERE, |
359 NewRunnableMethod(this, | 360 base::Bind(&CrashHandlerHostLinux::QueueCrashDumpTask, |
360 &CrashHandlerHostLinux::QueueCrashDumpTask, | 361 base::Unretained(this), |
361 info, | 362 info, |
362 signal_fd)); | 363 signal_fd)); |
363 } | 364 } |
364 | 365 |
365 void CrashHandlerHostLinux::QueueCrashDumpTask(BreakpadInfo* info, | 366 void CrashHandlerHostLinux::QueueCrashDumpTask(BreakpadInfo* info, |
366 int signal_fd) { | 367 int signal_fd) { |
367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
368 | 369 |
369 // Send the done signal to the process: it can exit now. | 370 // Send the done signal to the process: it can exit now. |
370 struct msghdr msg = {0}; | 371 struct msghdr msg = {0}; |
371 struct iovec done_iov; | 372 struct iovec done_iov; |
372 done_iov.iov_base = const_cast<char*>("\x42"); | 373 done_iov.iov_base = const_cast<char*>("\x42"); |
373 done_iov.iov_len = 1; | 374 done_iov.iov_len = 1; |
374 msg.msg_iov = &done_iov; | 375 msg.msg_iov = &done_iov; |
375 msg.msg_iovlen = 1; | 376 msg.msg_iovlen = 1; |
376 | 377 |
377 HANDLE_EINTR(sendmsg(signal_fd, &msg, MSG_DONTWAIT | MSG_NOSIGNAL)); | 378 HANDLE_EINTR(sendmsg(signal_fd, &msg, MSG_DONTWAIT | MSG_NOSIGNAL)); |
378 HANDLE_EINTR(close(signal_fd)); | 379 HANDLE_EINTR(close(signal_fd)); |
379 | 380 |
380 uploader_thread_->message_loop()->PostTask( | 381 uploader_thread_->message_loop()->PostTask( |
381 FROM_HERE, | 382 FROM_HERE, |
382 NewRunnableFunction(&CrashDumpTask, this, info)); | 383 base::Bind(&CrashDumpTask, base::Unretained(this), info)); |
383 } | 384 } |
384 | 385 |
385 void CrashHandlerHostLinux::WillDestroyCurrentMessageLoop() { | 386 void CrashHandlerHostLinux::WillDestroyCurrentMessageLoop() { |
386 file_descriptor_watcher_.StopWatchingFileDescriptor(); | 387 file_descriptor_watcher_.StopWatchingFileDescriptor(); |
387 | 388 |
388 // If we are quitting and there are crash dumps in the queue, turn them into | 389 // If we are quitting and there are crash dumps in the queue, turn them into |
389 // no-ops. | 390 // no-ops. |
390 shutting_down_ = true; | 391 shutting_down_ = true; |
391 uploader_thread_->Stop(); | 392 uploader_thread_->Stop(); |
392 } | 393 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 } | 468 } |
468 | 469 |
469 void RendererCrashHandlerHostLinux::SetProcessType() { | 470 void RendererCrashHandlerHostLinux::SetProcessType() { |
470 process_type_ = "renderer"; | 471 process_type_ = "renderer"; |
471 } | 472 } |
472 | 473 |
473 // static | 474 // static |
474 RendererCrashHandlerHostLinux* RendererCrashHandlerHostLinux::GetInstance() { | 475 RendererCrashHandlerHostLinux* RendererCrashHandlerHostLinux::GetInstance() { |
475 return Singleton<RendererCrashHandlerHostLinux>::get(); | 476 return Singleton<RendererCrashHandlerHostLinux>::get(); |
476 } | 477 } |
OLD | NEW |