1 //
2 // Copyright (C) 2021 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 // This file is exactly the same as zucchini_main.cc, except with a few fixes
18 // that make it compatible with AOSP version of liblog
19
20 #include <iostream>
21
22 #include "base/command_line.h"
23 #include "base/logging.h"
24 #include "base/process/memory.h"
25 #include "build/build_config.h"
26 #include "main_utils.h"
27
28 #if defined(OS_WIN)
29 #include "base/win/process_startup_helper.h"
30 #endif // defined(OS_WIN)
31
32 namespace {
33
InitLogging()34 void InitLogging() {
35 logging::LoggingSettings settings;
36 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
37 // settings.log_file_path = nullptr;
38 settings.lock_log = logging::DONT_LOCK_LOG_FILE;
39 settings.delete_old = logging::APPEND_TO_OLD_LOG_FILE;
40 bool logging_res = logging::InitLogging(settings);
41 CHECK(logging_res);
42 }
43
InitErrorHandling(const base::CommandLine & command_line)44 void InitErrorHandling(const base::CommandLine &command_line) {
45 base::EnableTerminationOnHeapCorruption();
46 base::EnableTerminationOnOutOfMemory();
47 #if defined(OS_WIN)
48 base::win::RegisterInvalidParamHandler();
49 base::win::SetupCRT(command_line);
50 #endif // defined(OS_WIN)
51 }
52
53 } // namespace
54
main(int argc,const char * argv[])55 int main(int argc, const char *argv[]) {
56 // Initialize infrastructure from base.
57 base::CommandLine::Init(argc, argv);
58 const base::CommandLine &command_line =
59 *base::CommandLine::ForCurrentProcess();
60 InitLogging();
61 InitErrorHandling(command_line);
62 zucchini::status::Code status =
63 RunZucchiniCommand(command_line, std::cout, std::cerr);
64 if (!(status == zucchini::status::kStatusSuccess ||
65 status == zucchini::status::kStatusInvalidParam)) {
66 std::cerr << "Failed with code " << static_cast<int>(status) << std::endl;
67 }
68 return static_cast<int>(status);
69 }
70