~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to thirdparty/breakpad/client/linux/crash_generation/crash_generation_client.cc

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
30
#include <stdio.h>
 
31
#include <sys/socket.h>
 
32
#include <sys/types.h>
 
33
 
 
34
#include <algorithm>
 
35
 
 
36
#include "client/linux/crash_generation/crash_generation_client.h"
 
37
#include "common/linux/eintr_wrapper.h"
 
38
#include "common/linux/linux_libc_support.h"
 
39
#include "third_party/lss/linux_syscall_support.h"
 
40
 
 
41
namespace google_breakpad {
 
42
 
 
43
bool
 
44
CrashGenerationClient::RequestDump(const void* blob, size_t blob_size)
 
45
{
 
46
  int fds[2];
 
47
  sys_socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
 
48
  static const unsigned kControlMsgSize = CMSG_SPACE(sizeof(int));
 
49
 
 
50
  struct kernel_msghdr msg;
 
51
  my_memset(&msg, 0, sizeof(struct kernel_msghdr));
 
52
  struct kernel_iovec iov[1];
 
53
  iov[0].iov_base = const_cast<void*>(blob);
 
54
  iov[0].iov_len = blob_size;
 
55
 
 
56
  msg.msg_iov = iov;
 
57
  msg.msg_iovlen = sizeof(iov) / sizeof(iov[0]);
 
58
  char cmsg[kControlMsgSize];
 
59
  my_memset(cmsg, 0, kControlMsgSize);
 
60
  msg.msg_control = cmsg;
 
61
  msg.msg_controllen = sizeof(cmsg);
 
62
 
 
63
  struct cmsghdr* hdr = CMSG_FIRSTHDR(&msg);
 
64
  hdr->cmsg_level = SOL_SOCKET;
 
65
  hdr->cmsg_type = SCM_RIGHTS;
 
66
  hdr->cmsg_len = CMSG_LEN(sizeof(int));
 
67
  int* p = reinterpret_cast<int*>(CMSG_DATA(hdr));
 
68
  *p = fds[1];
 
69
 
 
70
  HANDLE_EINTR(sys_sendmsg(server_fd_, &msg, 0));
 
71
  sys_close(fds[1]);
 
72
 
 
73
  // wait for an ACK from the server
 
74
  char b;
 
75
  HANDLE_EINTR(sys_read(fds[0], &b, 1));
 
76
 
 
77
  return true;
 
78
}
 
79
 
 
80
//static
 
81
CrashGenerationClient*
 
82
CrashGenerationClient::TryCreate(int server_fd)
 
83
{
 
84
  if (0 > server_fd)
 
85
    return NULL;
 
86
  return new CrashGenerationClient(server_fd);
 
87
}
 
88
 
 
89
}