/thirdparty/breakpad/client/linux/crash_generation/crash_generation_client.cc

http://github.com/tomahawk-player/tomahawk · C++ · 89 lines · 46 code · 13 blank · 30 comment · 1 complexity · 09f452ae8973aa1a8d727a81a0a0fd39 MD5 · raw file

  1. // Copyright (c) 2010 Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. #include <stdio.h>
  30. #include <sys/socket.h>
  31. #include <sys/types.h>
  32. #include <algorithm>
  33. #include "client/linux/crash_generation/crash_generation_client.h"
  34. #include "common/linux/eintr_wrapper.h"
  35. #include "common/linux/linux_libc_support.h"
  36. #include "third_party/lss/linux_syscall_support.h"
  37. namespace google_breakpad {
  38. bool
  39. CrashGenerationClient::RequestDump(const void* blob, size_t blob_size)
  40. {
  41. int fds[2];
  42. sys_socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
  43. static const unsigned kControlMsgSize = CMSG_SPACE(sizeof(int));
  44. struct kernel_msghdr msg;
  45. my_memset(&msg, 0, sizeof(struct kernel_msghdr));
  46. struct kernel_iovec iov[1];
  47. iov[0].iov_base = const_cast<void*>(blob);
  48. iov[0].iov_len = blob_size;
  49. msg.msg_iov = iov;
  50. msg.msg_iovlen = sizeof(iov) / sizeof(iov[0]);
  51. char cmsg[kControlMsgSize];
  52. my_memset(cmsg, 0, kControlMsgSize);
  53. msg.msg_control = cmsg;
  54. msg.msg_controllen = sizeof(cmsg);
  55. struct cmsghdr* hdr = CMSG_FIRSTHDR(&msg);
  56. hdr->cmsg_level = SOL_SOCKET;
  57. hdr->cmsg_type = SCM_RIGHTS;
  58. hdr->cmsg_len = CMSG_LEN(sizeof(int));
  59. int* p = reinterpret_cast<int*>(CMSG_DATA(hdr));
  60. *p = fds[1];
  61. HANDLE_EINTR(sys_sendmsg(server_fd_, &msg, 0));
  62. sys_close(fds[1]);
  63. // wait for an ACK from the server
  64. char b;
  65. HANDLE_EINTR(sys_read(fds[0], &b, 1));
  66. return true;
  67. }
  68. //static
  69. CrashGenerationClient*
  70. CrashGenerationClient::TryCreate(int server_fd)
  71. {
  72. if (0 > server_fd)
  73. return NULL;
  74. return new CrashGenerationClient(server_fd);
  75. }
  76. }