1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <iostream>
6 
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/process/memory.h"
10 #include "build/build_config.h"
11 #include "components/zucchini/main_utils.h"
12 
13 #if defined(OS_WIN)
14 #include "base/win/process_startup_helper.h"
15 #endif  // defined(OS_WIN)
16 
17 namespace {
18 
InitLogging()19 void InitLogging() {
20   logging::LoggingSettings settings;
21   settings.logging_dest =
22       logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR;
23   settings.log_file_path = nullptr;
24   settings.lock_log = logging::DONT_LOCK_LOG_FILE;
25   settings.delete_old = logging::APPEND_TO_OLD_LOG_FILE;
26   bool logging_res = logging::InitLogging(settings);
27   CHECK(logging_res);
28 }
29 
InitErrorHandling(const base::CommandLine & command_line)30 void InitErrorHandling(const base::CommandLine& command_line) {
31   base::EnableTerminationOnHeapCorruption();
32   base::EnableTerminationOnOutOfMemory();
33 #if defined(OS_WIN)
34   base::win::RegisterInvalidParamHandler();
35   base::win::SetupCRT(command_line);
36 #endif  // defined(OS_WIN)
37 }
38 
39 }  // namespace
40 
main(int argc,const char * argv[])41 int main(int argc, const char* argv[]) {
42   // Initialize infrastructure from base.
43   base::CommandLine::Init(argc, argv);
44   const base::CommandLine& command_line =
45       *base::CommandLine::ForCurrentProcess();
46   InitLogging();
47   InitErrorHandling(command_line);
48   zucchini::status::Code status =
49       RunZucchiniCommand(command_line, std::cout, std::cerr);
50   if (!(status == zucchini::status::kStatusSuccess ||
51         status == zucchini::status::kStatusInvalidParam)) {
52     std::cerr << "Failed with code " << static_cast<int>(status) << std::endl;
53   }
54   return static_cast<int>(status);
55 }
56