From 907f95c5bda4144de54778769b7d51814b32c82a Mon Sep 17 00:00:00 2001 From: "benchan@chromium.org" Date: Thu, 23 Feb 2012 18:50:08 +0000 Subject: Modify CrashGenerator::CreateChildCrash to copy proc files. This patch is taken from the downstream version of breakpad in Chromium OS: https://gerrit.chromium.org/gerrit/15148 LinuxCoreDumperTest previously assumes the proc files of the child process created by CrashGenerator::CreateChildCrash() have the same content as its parent process, which may not be true. This CL modifies CrashGenerator to copy the proc files of the child process, created by CreateChildCrash(), before crashing that process. BUG=chromium-os:25252 TEST=Verified the following: TEST=Tested the following: 1. Build on 32-bit and 64-bit Linux with gcc 4.4.3 and gcc 4.6. 2. Build on Mac OS X 10.6.8 with gcc 4.2 and clang 3.0 (with latest gmock). 3. All unit tests pass. Review URL: https://breakpad.appspot.com/353001 git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@925 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/common/tests/file_utils.cc | 55 ++++++++++++++++++++++++++++++++++++++++++ src/common/tests/file_utils.h | 3 +++ 2 files changed, 58 insertions(+) (limited to 'src/common/tests') diff --git a/src/common/tests/file_utils.cc b/src/common/tests/file_utils.cc index 0d9b04ad..1264b078 100644 --- a/src/common/tests/file_utils.cc +++ b/src/common/tests/file_utils.cc @@ -40,6 +40,61 @@ namespace google_breakpad { +bool CopyFile(const char* from_path, const char* to_path) { + int infile = HANDLE_EINTR(open(from_path, O_RDONLY)); + if (infile < 0) { + perror("open"); + return false; + } + + int outfile = HANDLE_EINTR(creat(to_path, 0666)); + if (outfile < 0) { + perror("creat"); + if (HANDLE_EINTR(close(infile)) < 0) { + perror("close"); + } + return false; + } + + char buffer[1024]; + bool result = true; + + while (result) { + ssize_t bytes_read = HANDLE_EINTR(read(infile, buffer, sizeof(buffer))); + if (bytes_read < 0) { + perror("read"); + result = false; + break; + } + if (bytes_read == 0) + break; + ssize_t bytes_written_per_read = 0; + do { + ssize_t bytes_written_partial = HANDLE_EINTR(write( + outfile, + &buffer[bytes_written_per_read], + bytes_read - bytes_written_per_read)); + if (bytes_written_partial < 0) { + perror("write"); + result = false; + break; + } + bytes_written_per_read += bytes_written_partial; + } while (bytes_written_per_read < bytes_read); + } + + if (HANDLE_EINTR(close(infile)) == -1) { + perror("close"); + result = false; + } + if (HANDLE_EINTR(close(outfile)) == -1) { + perror("close"); + result = false; + } + + return result; +} + bool ReadFile(const char* path, void* buffer, ssize_t* buffer_size) { int fd = HANDLE_EINTR(open(path, O_RDONLY)); if (fd == -1) { diff --git a/src/common/tests/file_utils.h b/src/common/tests/file_utils.h index 52e8b009..c98a9bfa 100644 --- a/src/common/tests/file_utils.h +++ b/src/common/tests/file_utils.h @@ -35,6 +35,9 @@ namespace google_breakpad { +// Copies a file from |from_path| to |to_path|. Returns true on success. +bool CopyFile(const char* from_path, const char* to_path); + // Reads the content of a file at |path| into |buffer|. |buffer_size| specifies // the size of |buffer| in bytes and returns the number of bytes read from the // file on success. Returns true on success. -- cgit v1.2.1