Code review issue 9002: Add paranoid logging to Inspector & Reporter

A=jeremy moskovich
R=nealsid



git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@333 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
nealsid 2009-04-23 07:56:16 +00:00
parent e438d9cc0b
commit ed1f6e754a
3 changed files with 61 additions and 12 deletions

View file

@ -88,7 +88,7 @@ kern_return_t OnDemandServer::Initialize(const char *server_command,
&service_port_);
if (kr != KERN_SUCCESS) {
//PRINT_MACH_RESULT(kr, "bootstrap_create_service() : ");
PRINT_MACH_RESULT(kr, "bootstrap_create_service() : ");
// perhaps the service has already been created - try to look it up
kr = bootstrap_look_up(bootstrap_port, (char*)service_name, &service_port_);

View file

@ -160,8 +160,15 @@ void ConfigFile::WriteFile(const SimpleStringDictionary *configurationParameters
sizeof(config_file_path_));
config_file_ = mkstemp(config_file_path_);
if (config_file_ == -1)
if (config_file_ == -1) {
DEBUGLOG(stderr,
"mkstemp(config_file_path_) == -1 (%s)\n",
strerror(errno));
return;
}
else {
DEBUGLOG(stderr, "Writing config file to (%s)\n", config_file_path_);
}
has_created_file_ = true;
@ -177,6 +184,10 @@ void ConfigFile::WriteFile(const SimpleStringDictionary *configurationParameters
SimpleStringDictionaryIterator iter(dictionary);
while ((entry = iter.Next())) {
DEBUGLOG(stderr,
"config: (%s) -> (%s)\n",
entry->GetKey(),
entry->GetValue());
result = AppendConfigString(entry->GetKey(), entry->GetValue());
if (!result)
@ -348,6 +359,7 @@ void Inspector::SetCrashTimeParameters() {
bool Inspector::InspectTask() {
// keep the task quiet while we're looking at it
task_suspend(remote_task_);
DEBUGLOG(stderr, "Suspsended Remote task\n");
NSString *minidumpDir;
@ -375,6 +387,9 @@ bool Inspector::InspectTask() {
minidumpDir = [[NSString stringWithUTF8String:minidumpDirectory]
stringByExpandingTildeInPath];
}
DEBUGLOG(stderr,
"Writing minidump to directory (%s)\n",
[minidumpDir UTF8String]);
MinidumpLocation minidumpLocation(minidumpDir);
@ -393,14 +408,18 @@ bool Inspector::InspectTask() {
NSString *minidumpPath = [NSString stringWithFormat:@"%s/%s.dmp",
minidumpLocation.GetPath(), minidumpLocation.GetID()];
DEBUGLOG(stderr,
"minidump path (%s)\n",
[minidumpPath UTF8String]);
bool result = generator.Write([minidumpPath fileSystemRepresentation]);
DEBUGLOG(stderr, "Inspector: finished writing minidump file: %s\n",
[minidumpPath fileSystemRepresentation]);
DEBUGLOG(stderr, "Wrote minidump - %s\n", result ? "OK" : "FAILED");
// let the task continue
task_resume(remote_task_);
DEBUGLOG(stderr, "Resumed remote task\n");
return result;
}

View file

@ -39,6 +39,7 @@
#import "crash_report_sender.h"
#import "common/mac/GTMLogger.h"
#define kLastSubmission @"LastSubmission"
const int kMinidumpFileLengthLimit = 800000;
@ -704,13 +705,13 @@ doCommandBySelector:(SEL)commandSelector {
const char *dest = [destString fileSystemRepresentation];
if (rename(src, dest) == 0) {
fprintf(stderr, "Breakpad Reporter: Renamed %s to %s after successful " \
"upload\n",src, dest);
GTMLoggerInfo(@"Breakpad Reporter: Renamed %s to %s after successful " \
"upload",src, dest);
}
else {
// can't rename - don't worry - it's not important for users
fprintf(stderr, "Breakpad Reporter: successful upload report ID = %s\n",
reportID );
GTMLoggerDebug(@"Breakpad Reporter: successful upload report ID = %s\n",
reportID );
}
[result release];
}
@ -749,6 +750,11 @@ doCommandBySelector:(SEL)commandSelector {
//=============================================================================
int main(int argc, const char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
#if DEBUG
// Log to stderr in debug builds.
[GTMLogger setSharedLogger:[GTMLogger standardLoggerWithStderr]];
#endif
GTMLoggerDebug(@"Reporter Launched, argc=%d", argc);
// The expectation is that there will be one argument which is the path
// to the configuration file
if (argc != 2) {
@ -758,11 +764,20 @@ int main(int argc, const char *argv[]) {
// Open the file before (potentially) switching to console user
int configFile = open(argv[1], O_RDONLY, 0600);
if (configFile == -1) {
GTMLoggerDebug(@"Couldn't open config file %s - %s",
argv[1],
strerror(errno));
}
// we want to avoid a build-up of old config files even if they
// have been incorrectly written by the framework
unlink(argv[1]);
if (configFile == -1) {
GTMLoggerDebug(@"Couldn't unlink config file %s - %s",
argv[1],
strerror(errno));
exit(1);
}
@ -770,6 +785,7 @@ int main(int argc, const char *argv[]) {
// Gather the configuration data
if (![reporter readConfigurationData]) {
GTMLoggerDebug(@"reporter readConfigurationData failed");
exit(1);
}
@ -793,23 +809,37 @@ int main(int argc, const char *argv[]) {
struct passwd *pw = getpwnam("nobody");
// If we can't get a non-root uid, don't send the report
if (!pw)
if (!pw) {
GTMLoggerDebug(@"!pw - %s", strerror(errno));
exit(0);
}
if (setgid(pw->pw_gid) == -1)
if (setgid(pw->pw_gid) == -1) {
GTMLoggerDebug(@"setgid(pw->pw_gid) == -1 - %s", strerror(errno));
exit(0);
}
if (setuid(pw->pw_uid) == -1)
if (setuid(pw->pw_uid) == -1) {
GTMLoggerDebug(@"setuid(pw->pw_uid) == -1 - %s", strerror(errno));
exit(0);
}
}
else {
GTMLoggerDebug(@"getuid() !=0 || geteuid() != 0");
}
if (okayToSend && shouldSubmitReport) {
GTMLoggerDebug(@"Sending Report");
[reporter report];
GTMLoggerDebug(@"Report Sent!");
} else {
GTMLoggerDebug(@"Not sending crash report okayToSend=%d, "\
"shouldSubmitReport=%d", okayToSend, shouldSubmitReport);
}
GTMLoggerDebug(@"Exiting with no errors");
// Cleanup
[reporter release];
[pool release];
return 0;
}