OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/renderer_host/render_crash_handler_host_linux.h" | 5 #include "chrome/browser/renderer_host/render_crash_handler_host_linux.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
11 #include <sys/types.h> | 11 #include <sys/types.h> |
12 #include <sys/uio.h> | 12 #include <sys/uio.h> |
13 #include <stdlib.h> | |
14 #include <unistd.h> | 13 #include <unistd.h> |
15 | 14 |
16 #include <string> | 15 #include <string> |
17 #include <vector> | 16 #include <vector> |
18 | 17 |
19 #include "base/eintr_wrapper.h" | 18 #include "base/eintr_wrapper.h" |
20 #include "base/file_path.h" | |
21 #include "base/format_macros.h" | 19 #include "base/format_macros.h" |
22 #include "base/logging.h" | 20 #include "base/logging.h" |
23 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
24 #include "base/path_service.h" | |
25 #include "base/rand_util.h" | 22 #include "base/rand_util.h" |
26 #include "base/string_util.h" | 23 #include "base/string_util.h" |
27 #include "breakpad/linux/exception_handler.h" | 24 #include "breakpad/linux/exception_handler.h" |
28 #include "breakpad/linux/linux_dumper.h" | 25 #include "breakpad/linux/linux_dumper.h" |
29 #include "breakpad/linux/minidump_writer.h" | 26 #include "breakpad/linux/minidump_writer.h" |
30 #include "chrome/app/breakpad_linux.h" | 27 #include "chrome/app/breakpad_linux.h" |
31 #include "chrome/browser/chrome_thread.h" | 28 #include "chrome/browser/chrome_thread.h" |
32 #include "chrome/common/chrome_paths.h" | |
33 | 29 |
34 // expected prefix of the target of the /proc/self/fd/%d link for a socket | 30 // expected prefix of the target of the /proc/self/fd/%d link for a socket |
35 static const char kSocketLinkPrefix[] = "socket:["; | 31 static const char kSocketLinkPrefix[] = "socket:["; |
36 | 32 |
37 // Parse a symlink in /proc/pid/fd/$x and return the inode number of the | 33 // Parse a symlink in /proc/pid/fd/$x and return the inode number of the |
38 // socket. | 34 // socket. |
39 // inode_out: (output) set to the inode number on success | 35 // inode_out: (output) set to the inode number on success |
40 // path: e.g. /proc/1234/fd/5 (must be a UNIX domain socket descriptor) | 36 // path: e.g. /proc/1234/fd/5 (must be a UNIX domain socket descriptor) |
41 // log: if true, log messages about failure details | 37 // log: if true, log messages about failure details |
42 static bool ProcPathGetInode(uint64_t* inode_out, const char* path, | 38 static bool ProcPathGetInode(uint64_t* inode_out, const char* path, |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 return; | 296 return; |
301 } | 297 } |
302 | 298 |
303 if (!FindProcessHoldingSocket(&crashing_pid, inode_number - 1)) { | 299 if (!FindProcessHoldingSocket(&crashing_pid, inode_number - 1)) { |
304 LOG(WARNING) << "Failed to find process holding other end of crash reply " | 300 LOG(WARNING) << "Failed to find process holding other end of crash reply " |
305 "socket"; | 301 "socket"; |
306 HANDLE_EINTR(close(signal_fd)); | 302 HANDLE_EINTR(close(signal_fd)); |
307 return; | 303 return; |
308 } | 304 } |
309 | 305 |
310 bool upload = true; | |
311 FilePath dumps_path("/tmp"); | |
312 if (getenv("CHROME_HEADLESS")) { | |
313 upload = false; | |
314 PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path); | |
315 } | |
316 const uint64 rand = base::RandUint64(); | 306 const uint64 rand = base::RandUint64(); |
317 const std::string minidump_filename = | 307 const std::string minidump_filename = |
318 StringPrintf("%s/chromium-renderer-minidump-%016" PRIx64 ".dmp", | 308 StringPrintf("/tmp/chromium-renderer-minidump-%016" PRIx64 ".dmp", rand); |
319 dumps_path.value().c_str(), rand); | |
320 if (!google_breakpad::WriteMinidump(minidump_filename.c_str(), | 309 if (!google_breakpad::WriteMinidump(minidump_filename.c_str(), |
321 crashing_pid, crash_context, | 310 crashing_pid, crash_context, |
322 kCrashContextSize)) { | 311 kCrashContextSize)) { |
323 LOG(ERROR) << "Failed to write crash dump for pid " << crashing_pid; | 312 LOG(ERROR) << "Failed to write crash dump for pid " << crashing_pid; |
324 HANDLE_EINTR(close(signal_fd)); | 313 HANDLE_EINTR(close(signal_fd)); |
325 } | 314 } |
326 | 315 |
327 // Send the done signal to the renderer: it can exit now. | 316 // Send the done signal to the renderer: it can exit now. |
328 memset(&msg, 0, sizeof(msg)); | 317 memset(&msg, 0, sizeof(msg)); |
329 struct iovec done_iov; | 318 struct iovec done_iov; |
330 done_iov.iov_base = const_cast<char*>("\x42"); | 319 done_iov.iov_base = const_cast<char*>("\x42"); |
331 done_iov.iov_len = 1; | 320 done_iov.iov_len = 1; |
332 msg.msg_iov = &done_iov; | 321 msg.msg_iov = &done_iov; |
333 msg.msg_iovlen = 1; | 322 msg.msg_iovlen = 1; |
334 | 323 |
335 HANDLE_EINTR(sendmsg(signal_fd, &msg, MSG_DONTWAIT | MSG_NOSIGNAL)); | 324 HANDLE_EINTR(sendmsg(signal_fd, &msg, MSG_DONTWAIT | MSG_NOSIGNAL)); |
336 HANDLE_EINTR(close(signal_fd)); | 325 HANDLE_EINTR(close(signal_fd)); |
337 | 326 |
338 BreakpadInfo info; | 327 BreakpadInfo info; |
339 info.filename = minidump_filename.c_str(); | 328 info.filename = minidump_filename.c_str(); |
340 info.process_type = "renderer"; | 329 info.process_type = "renderer"; |
341 info.process_type_length = 8; | 330 info.process_type_length = 8; |
342 info.crash_url = crash_url; | 331 info.crash_url = crash_url; |
343 info.crash_url_length = strlen(crash_url); | 332 info.crash_url_length = strlen(crash_url); |
344 info.guid = guid; | 333 info.guid = guid; |
345 info.guid_length = strlen(guid); | 334 info.guid_length = strlen(guid); |
346 info.distro = distro; | 335 info.distro = distro; |
347 info.distro_length = strlen(distro); | 336 info.distro_length = strlen(distro); |
348 info.upload = upload; | 337 UploadCrashDump(info); |
349 HandleCrashDump(info); | |
350 } | 338 } |
351 | 339 |
352 void RenderCrashHandlerHostLinux::WillDestroyCurrentMessageLoop() { | 340 void RenderCrashHandlerHostLinux::WillDestroyCurrentMessageLoop() { |
353 file_descriptor_watcher_.StopWatchingFileDescriptor(); | 341 file_descriptor_watcher_.StopWatchingFileDescriptor(); |
354 } | 342 } |
OLD | NEW |