mirror of
https://git.suyu.dev/suyu/breakpad.git
synced 2026-03-25 08:02:58 +00:00
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
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user