• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #include <stdlib.h>
18 
19 #include "android-base/logging.h"
20 #include "android-base/macros.h"
21 #include "android/binder_interface_utils.h"
22 #include "android/binder_process.h"
23 #include "artd.h"
24 
25 namespace art {
26 namespace artd {
27 namespace {
28 
29 constexpr int kErrorUsage = 100;
30 
ParseError(const std::string & error_msg)31 [[noreturn]] void ParseError(const std::string& error_msg) {
32   LOG(ERROR) << error_msg;
33   std::cerr << error_msg << "\n";
34   exit(kErrorUsage);
35 }
36 
ParseOptions(int argc,char ** argv)37 Options ParseOptions(int argc, char** argv) {
38   Options options;
39   for (int i = 1; i < argc; i++) {
40     std::string_view arg = argv[i];
41     if (arg == "--pre-reboot") {
42       options.is_pre_reboot = true;
43     } else {
44       ParseError("Unknown option " + std::string(arg));
45     }
46   }
47   return options;
48 }
49 
50 }  // namespace
51 }  // namespace artd
52 }  // namespace art
53 
main(int argc,char * argv[])54 int main([[maybe_unused]] int argc, char* argv[]) {
55   android::base::InitLogging(argv);
56 
57   art::artd::Options options = art::artd::ParseOptions(argc, argv);
58   if (options.is_pre_reboot) {
59     android::base::SetDefaultTag("artd_pre_reboot");
60   }
61 
62   auto artd = ndk::SharedRefBase::make<art::artd::Artd>(std::move(options));
63 
64   LOG(INFO) << "Starting artd";
65 
66   if (auto ret = artd->Start(); !ret.ok()) {
67     LOG(ERROR) << "Unable to start artd: " << ret.error();
68     exit(1);
69   }
70 
71   ABinderProcess_joinThreadPool();
72 
73   LOG(INFO) << "artd shutting down";
74 
75   return 0;
76 }
77