OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/breakpad/browser/crash_handler_host_linux.h" | 5 #include "components/breakpad/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> |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 101 |
102 process_socket_ = fds[0]; | 102 process_socket_ = fds[0]; |
103 browser_socket_ = fds[1]; | 103 browser_socket_ = fds[1]; |
104 | 104 |
105 BrowserThread::PostTask( | 105 BrowserThread::PostTask( |
106 BrowserThread::IO, FROM_HERE, | 106 BrowserThread::IO, FROM_HERE, |
107 base::Bind(&CrashHandlerHostLinux::Init, base::Unretained(this))); | 107 base::Bind(&CrashHandlerHostLinux::Init, base::Unretained(this))); |
108 } | 108 } |
109 | 109 |
110 CrashHandlerHostLinux::~CrashHandlerHostLinux() { | 110 CrashHandlerHostLinux::~CrashHandlerHostLinux() { |
111 (void) HANDLE_EINTR(close(process_socket_)); | 111 close(process_socket_); |
112 (void) HANDLE_EINTR(close(browser_socket_)); | 112 close(browser_socket_); |
113 } | 113 } |
114 | 114 |
115 void CrashHandlerHostLinux::StartUploaderThread() { | 115 void CrashHandlerHostLinux::StartUploaderThread() { |
116 uploader_thread_.reset( | 116 uploader_thread_.reset( |
117 new base::Thread(std::string(process_type_ + "_crash_uploader").c_str())); | 117 new base::Thread(std::string(process_type_ + "_crash_uploader").c_str())); |
118 uploader_thread_->Start(); | 118 uploader_thread_->Start(); |
119 } | 119 } |
120 | 120 |
121 void CrashHandlerHostLinux::Init() { | 121 void CrashHandlerHostLinux::Init() { |
122 base::MessageLoopForIO* ml = base::MessageLoopForIO::current(); | 122 base::MessageLoopForIO* ml = base::MessageLoopForIO::current(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 const unsigned len = hdr->cmsg_len - | 229 const unsigned len = hdr->cmsg_len - |
230 (((uint8_t*)CMSG_DATA(hdr)) - (uint8_t*)hdr); | 230 (((uint8_t*)CMSG_DATA(hdr)) - (uint8_t*)hdr); |
231 DCHECK_EQ(len % sizeof(int), 0u); | 231 DCHECK_EQ(len % sizeof(int), 0u); |
232 const unsigned num_fds = len / sizeof(int); | 232 const unsigned num_fds = len / sizeof(int); |
233 if (num_fds != 2) { | 233 if (num_fds != 2) { |
234 // A nasty process could try and send us too many descriptors and | 234 // A nasty process could try and send us too many descriptors and |
235 // force a leak. | 235 // force a leak. |
236 LOG(ERROR) << "Death signal contained wrong number of descriptors;" | 236 LOG(ERROR) << "Death signal contained wrong number of descriptors;" |
237 << " num_fds:" << num_fds; | 237 << " num_fds:" << num_fds; |
238 for (unsigned i = 0; i < num_fds; ++i) | 238 for (unsigned i = 0; i < num_fds; ++i) |
239 (void) HANDLE_EINTR(close(reinterpret_cast<int*>(CMSG_DATA(hdr))[i])); | 239 close(reinterpret_cast<int*>(CMSG_DATA(hdr))[i]); |
240 return; | 240 return; |
241 } else { | 241 } else { |
242 partner_fd = reinterpret_cast<int*>(CMSG_DATA(hdr))[0]; | 242 partner_fd = reinterpret_cast<int*>(CMSG_DATA(hdr))[0]; |
243 signal_fd = reinterpret_cast<int*>(CMSG_DATA(hdr))[1]; | 243 signal_fd = reinterpret_cast<int*>(CMSG_DATA(hdr))[1]; |
244 } | 244 } |
245 } else if (hdr->cmsg_type == SCM_CREDENTIALS) { | 245 } else if (hdr->cmsg_type == SCM_CREDENTIALS) { |
246 const struct ucred *cred = | 246 const struct ucred *cred = |
247 reinterpret_cast<struct ucred*>(CMSG_DATA(hdr)); | 247 reinterpret_cast<struct ucred*>(CMSG_DATA(hdr)); |
248 crashing_pid = cred->pid; | 248 crashing_pid = cred->pid; |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
252 if (crashing_pid == -1 || partner_fd == -1 || signal_fd == -1) { | 252 if (crashing_pid == -1 || partner_fd == -1 || signal_fd == -1) { |
253 LOG(ERROR) << "Death signal message didn't contain all expected control" | 253 LOG(ERROR) << "Death signal message didn't contain all expected control" |
254 << " messages"; | 254 << " messages"; |
255 if (partner_fd >= 0) | 255 if (partner_fd >= 0) |
256 (void) HANDLE_EINTR(close(partner_fd)); | 256 close(partner_fd); |
257 if (signal_fd >= 0) | 257 if (signal_fd >= 0) |
258 (void) HANDLE_EINTR(close(signal_fd)); | 258 close(signal_fd); |
259 return; | 259 return; |
260 } | 260 } |
261 | 261 |
262 // Kernel bug workaround (broken in 2.6.30 and 2.6.32, working in 2.6.38). | 262 // Kernel bug workaround (broken in 2.6.30 and 2.6.32, working in 2.6.38). |
263 // The kernel doesn't translate PIDs in SCM_CREDENTIALS across PID | 263 // The kernel doesn't translate PIDs in SCM_CREDENTIALS across PID |
264 // namespaces. Thus |crashing_pid| might be garbage from our point of view. | 264 // namespaces. Thus |crashing_pid| might be garbage from our point of view. |
265 // In the future we can remove this workaround, but we have to wait a couple | 265 // In the future we can remove this workaround, but we have to wait a couple |
266 // of years to be sure that it's worked its way out into the world. | 266 // of years to be sure that it's worked its way out into the world. |
267 // TODO(thestig) Remove the workaround when Ubuntu Lucid is deprecated. | 267 // TODO(thestig) Remove the workaround when Ubuntu Lucid is deprecated. |
268 | 268 |
269 // The crashing process closes its copy of the signal_fd immediately after | 269 // The crashing process closes its copy of the signal_fd immediately after |
270 // calling sendmsg(). We can thus not reliably look for with with | 270 // calling sendmsg(). We can thus not reliably look for with with |
271 // FindProcessHoldingSocket(). But by necessity, it has to keep the | 271 // FindProcessHoldingSocket(). But by necessity, it has to keep the |
272 // partner_fd open until the crashdump is complete. | 272 // partner_fd open until the crashdump is complete. |
273 ino_t inode_number; | 273 ino_t inode_number; |
274 if (!base::FileDescriptorGetInode(&inode_number, partner_fd)) { | 274 if (!base::FileDescriptorGetInode(&inode_number, partner_fd)) { |
275 LOG(WARNING) << "Failed to get inode number for passed socket"; | 275 LOG(WARNING) << "Failed to get inode number for passed socket"; |
276 (void) HANDLE_EINTR(close(partner_fd)); | 276 close(partner_fd); |
277 (void) HANDLE_EINTR(close(signal_fd)); | 277 close(signal_fd); |
278 return; | 278 return; |
279 } | 279 } |
280 (void) HANDLE_EINTR(close(partner_fd)); | 280 close(partner_fd); |
281 | 281 |
282 pid_t actual_crashing_pid = -1; | 282 pid_t actual_crashing_pid = -1; |
283 if (!base::FindProcessHoldingSocket(&actual_crashing_pid, inode_number)) { | 283 if (!base::FindProcessHoldingSocket(&actual_crashing_pid, inode_number)) { |
284 LOG(WARNING) << "Failed to find process holding other end of crash reply " | 284 LOG(WARNING) << "Failed to find process holding other end of crash reply " |
285 "socket"; | 285 "socket"; |
286 (void) HANDLE_EINTR(close(signal_fd)); | 286 close(signal_fd); |
287 return; | 287 return; |
288 } | 288 } |
289 | 289 |
290 crashing_pid = actual_crashing_pid; | 290 crashing_pid = actual_crashing_pid; |
291 | 291 |
292 // The crashing TID set inside the compromised context via | 292 // The crashing TID set inside the compromised context via |
293 // sys_gettid() in ExceptionHandler::HandleSignal might be wrong (if | 293 // sys_gettid() in ExceptionHandler::HandleSignal might be wrong (if |
294 // the kernel supports PID namespacing) and may need to be | 294 // the kernel supports PID namespacing) and may need to be |
295 // translated. | 295 // translated. |
296 // | 296 // |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 | 435 |
436 // Send the done signal to the process: it can exit now. | 436 // Send the done signal to the process: it can exit now. |
437 struct msghdr msg = {0}; | 437 struct msghdr msg = {0}; |
438 struct iovec done_iov; | 438 struct iovec done_iov; |
439 done_iov.iov_base = const_cast<char*>("\x42"); | 439 done_iov.iov_base = const_cast<char*>("\x42"); |
440 done_iov.iov_len = 1; | 440 done_iov.iov_len = 1; |
441 msg.msg_iov = &done_iov; | 441 msg.msg_iov = &done_iov; |
442 msg.msg_iovlen = 1; | 442 msg.msg_iovlen = 1; |
443 | 443 |
444 (void) HANDLE_EINTR(sendmsg(signal_fd, &msg, MSG_DONTWAIT | MSG_NOSIGNAL)); | 444 (void) HANDLE_EINTR(sendmsg(signal_fd, &msg, MSG_DONTWAIT | MSG_NOSIGNAL)); |
445 (void) HANDLE_EINTR(close(signal_fd)); | 445 close(signal_fd); |
446 | 446 |
447 uploader_thread_->message_loop()->PostTask( | 447 uploader_thread_->message_loop()->PostTask( |
448 FROM_HERE, | 448 FROM_HERE, |
449 base::Bind(&CrashDumpTask, base::Unretained(this), info)); | 449 base::Bind(&CrashDumpTask, base::Unretained(this), info)); |
450 } | 450 } |
451 | 451 |
452 void CrashHandlerHostLinux::WillDestroyCurrentMessageLoop() { | 452 void CrashHandlerHostLinux::WillDestroyCurrentMessageLoop() { |
453 file_descriptor_watcher_.StopWatchingFileDescriptor(); | 453 file_descriptor_watcher_.StopWatchingFileDescriptor(); |
454 | 454 |
455 // If we are quitting and there are crash dumps in the queue, turn them into | 455 // If we are quitting and there are crash dumps in the queue, turn them into |
456 // no-ops. | 456 // no-ops. |
457 shutting_down_ = true; | 457 shutting_down_ = true; |
458 uploader_thread_->Stop(); | 458 uploader_thread_->Stop(); |
459 } | 459 } |
460 | 460 |
461 bool CrashHandlerHostLinux::IsShuttingDown() const { | 461 bool CrashHandlerHostLinux::IsShuttingDown() const { |
462 return shutting_down_; | 462 return shutting_down_; |
463 } | 463 } |
464 | 464 |
465 } // namespace breakpad | 465 } // namespace breakpad |
OLD | NEW |