2013-11-23 12:26:47 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "common/crash_reporter/win/crash_service_main.h"
|
|
|
|
|
2013-11-24 09:35:58 +00:00
|
|
|
#include "base/at_exit.h"
|
|
|
|
#include "base/command_line.h"
|
2013-11-24 10:17:31 +00:00
|
|
|
#include "base/file_util.h"
|
2013-11-24 09:35:58 +00:00
|
|
|
#include "base/logging.h"
|
2013-11-24 12:33:26 +00:00
|
|
|
#include "base/string_util.h"
|
2013-11-24 09:35:58 +00:00
|
|
|
#include "common/crash_reporter/win/crash_service.h"
|
|
|
|
|
2013-11-23 12:26:47 +00:00
|
|
|
namespace crash_service {
|
|
|
|
|
2013-11-24 10:17:31 +00:00
|
|
|
namespace {
|
|
|
|
|
2013-11-24 12:33:26 +00:00
|
|
|
const char kApplicationName[] = "application-name";
|
2013-11-24 14:22:08 +00:00
|
|
|
|
|
|
|
const wchar_t kPipeNameFormat[] = L"\\\\.\\pipe\\$1 Crash Service";
|
2013-11-24 10:17:31 +00:00
|
|
|
const wchar_t kStandardLogFile[] = L"operation_log.txt";
|
|
|
|
|
2013-11-24 12:33:26 +00:00
|
|
|
bool GetCrashServiceDirectory(const std::wstring& application_name,
|
|
|
|
base::FilePath* dir) {
|
2013-11-24 10:17:31 +00:00
|
|
|
base::FilePath temp_dir;
|
|
|
|
if (!file_util::GetTempDir(&temp_dir))
|
|
|
|
return false;
|
2013-11-24 12:33:26 +00:00
|
|
|
temp_dir = temp_dir.Append(application_name + L" Crashes");
|
2013-11-24 10:17:31 +00:00
|
|
|
if (!file_util::PathExists(temp_dir)) {
|
|
|
|
if (!file_util::CreateDirectory(temp_dir))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*dir = temp_dir;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace.
|
|
|
|
|
2013-11-24 12:33:26 +00:00
|
|
|
int Main(const wchar_t* cmd) {
|
2013-11-24 09:35:58 +00:00
|
|
|
// Initialize all Chromium things.
|
|
|
|
base::AtExitManager exit_manager;
|
|
|
|
CommandLine::Init(0, NULL);
|
2013-11-24 12:33:26 +00:00
|
|
|
CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
|
|
|
|
|
|
|
|
// Use the application's name as pipe name and output directory.
|
|
|
|
if (!cmd_line.HasSwitch(kApplicationName)) {
|
|
|
|
LOG(ERROR) << "Application's name must be specified with --"
|
|
|
|
<< kApplicationName;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
std::wstring application_name = cmd_line.GetSwitchValueNative(
|
|
|
|
kApplicationName);
|
2013-11-24 09:35:58 +00:00
|
|
|
|
2013-11-24 10:17:31 +00:00
|
|
|
// We use/create a directory under the user's temp folder, for logging.
|
|
|
|
base::FilePath operating_dir;
|
2013-11-24 12:33:26 +00:00
|
|
|
GetCrashServiceDirectory(application_name, &operating_dir);
|
2013-11-24 10:17:31 +00:00
|
|
|
base::FilePath log_file = operating_dir.Append(kStandardLogFile);
|
2013-11-24 09:35:58 +00:00
|
|
|
|
2013-11-24 10:17:31 +00:00
|
|
|
// Logging out to a file.
|
|
|
|
logging::InitLogging(
|
|
|
|
log_file.value().c_str(),
|
|
|
|
logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG ,
|
|
|
|
logging::LOCK_LOG_FILE,
|
|
|
|
logging::DELETE_OLD_LOG_FILE,
|
|
|
|
logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
|
|
|
|
logging::SetLogItems(true, false, true, false);
|
|
|
|
|
2013-11-24 12:33:26 +00:00
|
|
|
VLOG(1) << "Session start. cmdline is [" << cmd << "]";
|
|
|
|
|
|
|
|
// Setting the crash reporter.
|
|
|
|
string16 pipe_name = ReplaceStringPlaceholders(kPipeNameFormat,
|
|
|
|
application_name,
|
|
|
|
NULL);
|
|
|
|
cmd_line.AppendSwitch("no-window");
|
|
|
|
cmd_line.AppendSwitchASCII("max-reports", "128");
|
|
|
|
cmd_line.AppendSwitchASCII("reporter", "atom-shell-crash-service");
|
|
|
|
cmd_line.AppendSwitchNative("pipe-name", pipe_name);
|
2013-11-24 09:35:58 +00:00
|
|
|
|
|
|
|
breakpad::CrashService crash_service;
|
2013-11-24 10:17:31 +00:00
|
|
|
if (!crash_service.Initialize(operating_dir, operating_dir))
|
2013-11-24 12:33:26 +00:00
|
|
|
return 2;
|
2013-11-24 09:35:58 +00:00
|
|
|
|
|
|
|
VLOG(1) << "Ready to process crash requests";
|
|
|
|
|
|
|
|
// Enter the message loop.
|
|
|
|
int retv = crash_service.ProcessingLoop();
|
|
|
|
// Time to exit.
|
|
|
|
VLOG(1) << "Session end. return code is " << retv;
|
|
|
|
return retv;
|
2013-11-23 12:26:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace crash_service
|