LCOV - code coverage report
Current view: directory - toolkit/crashreporter/google-breakpad/src/client/linux/crash_generation - crash_generation_client.cc (source / functions) Found Hit Coverage
Test: app.info Lines: 24 3 12.5 %
Date: 2012-06-02 Functions: 2 1 50.0 %

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

Generated by: LCOV version 1.7