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