blob: ba05eb61c4635034a81d922e3577b96f537f23ff [file] [log] [blame]
David Andersonc053b3b2019-01-08 18:22:07 -08001//
2// Copyright (C) 2019 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
David Andersonb3aff182019-01-11 14:37:51 -080017#include <getopt.h>
18
David Andersond614eca2019-09-09 17:57:06 -070019#include <iostream>
David Andersonb3aff182019-01-11 14:37:51 -080020#include <string>
21
David Andersonc053b3b2019-01-08 18:22:07 -080022#include <android-base/logging.h>
David Anderson4c756732019-07-12 14:18:37 -070023#include <binder/BinderService.h>
David Andersonc053b3b2019-01-08 18:22:07 -080024#include <binder/IPCThreadState.h>
25#include <binder/ProcessState.h>
David Anderson4c756732019-07-12 14:18:37 -070026#include <libgsi/libgsi.h>
David Andersond614eca2019-09-09 17:57:06 -070027#include <libgsi/libgsid.h>
David Anderson4c756732019-07-12 14:18:37 -070028
29#include "gsi_service.h"
David Andersonc053b3b2019-01-08 18:22:07 -080030
31using android::ProcessState;
32using android::sp;
David Andersonb3aff182019-01-11 14:37:51 -080033using namespace std::literals;
David Andersonc053b3b2019-01-08 18:22:07 -080034
David Andersond614eca2019-09-09 17:57:06 -070035static int DumpDeviceMapper() {
36 auto service = android::gsi::GetGsiService();
37 if (!service) {
38 std::cerr << "Could not start IGsiService.\n";
39 return 1;
40 }
41 std::string output;
42 auto status = service->dumpDeviceMapperDevices(&output);
43 if (!status.isOk()) {
44 std::cerr << "Could not dump device-mapper devices: " << status.exceptionMessage().c_str()
45 << "\n";
46 return 1;
47 }
48 std::cout << output;
49 return 0;
50}
51
David Andersonb3aff182019-01-11 14:37:51 -080052int main(int argc, char** argv) {
David Andersonc053b3b2019-01-08 18:22:07 -080053 android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM));
54
David Andersond614eca2019-09-09 17:57:06 -070055 if (argc > 1) {
56 if (argv[1] == "run-startup-tasks"s) {
57 android::gsi::GsiService::RunStartupTasks();
58 exit(0);
59 } else if (argv[1] == "dump-device-mapper"s) {
60 int rc = DumpDeviceMapper();
61 exit(rc);
62 }
David Andersonb3aff182019-01-11 14:37:51 -080063 }
64
Howard Chenf2a0a822020-02-15 17:32:02 +080065 android::gsi::GsiService::Register();
David Andersonc053b3b2019-01-08 18:22:07 -080066 {
67 sp<ProcessState> ps(ProcessState::self());
68 ps->startThreadPool();
69 ps->giveThreadPoolName();
70 }
71 android::IPCThreadState::self()->joinThreadPool();
72
73 exit(0);
74}