David Anderson | c053b3b | 2019-01-08 18:22:07 -0800 | [diff] [blame] | 1 | // |
| 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 Anderson | d614eca | 2019-09-09 17:57:06 -0700 | [diff] [blame] | 17 | #include <iostream> |
David Anderson | b3aff18 | 2019-01-11 14:37:51 -0800 | [diff] [blame] | 18 | #include <string> |
| 19 | |
David Anderson | c053b3b | 2019-01-08 18:22:07 -0800 | [diff] [blame] | 20 | #include <android-base/logging.h> |
David Anderson | 4c75673 | 2019-07-12 14:18:37 -0700 | [diff] [blame] | 21 | #include <binder/BinderService.h> |
David Anderson | c053b3b | 2019-01-08 18:22:07 -0800 | [diff] [blame] | 22 | #include <binder/IPCThreadState.h> |
| 23 | #include <binder/ProcessState.h> |
David Anderson | d614eca | 2019-09-09 17:57:06 -0700 | [diff] [blame] | 24 | #include <libgsi/libgsid.h> |
David Anderson | 4c75673 | 2019-07-12 14:18:37 -0700 | [diff] [blame] | 25 | |
| 26 | #include "gsi_service.h" |
David Anderson | c053b3b | 2019-01-08 18:22:07 -0800 | [diff] [blame] | 27 | |
| 28 | using android::ProcessState; |
| 29 | using android::sp; |
David Anderson | b3aff18 | 2019-01-11 14:37:51 -0800 | [diff] [blame] | 30 | using namespace std::literals; |
David Anderson | c053b3b | 2019-01-08 18:22:07 -0800 | [diff] [blame] | 31 | |
David Anderson | d614eca | 2019-09-09 17:57:06 -0700 | [diff] [blame] | 32 | static int DumpDeviceMapper() { |
| 33 | auto service = android::gsi::GetGsiService(); |
| 34 | if (!service) { |
| 35 | std::cerr << "Could not start IGsiService.\n"; |
| 36 | return 1; |
| 37 | } |
| 38 | std::string output; |
| 39 | auto status = service->dumpDeviceMapperDevices(&output); |
| 40 | if (!status.isOk()) { |
| 41 | std::cerr << "Could not dump device-mapper devices: " << status.exceptionMessage().c_str() |
| 42 | << "\n"; |
| 43 | return 1; |
| 44 | } |
| 45 | std::cout << output; |
| 46 | return 0; |
| 47 | } |
| 48 | |
David Anderson | b3aff18 | 2019-01-11 14:37:51 -0800 | [diff] [blame] | 49 | int main(int argc, char** argv) { |
David Anderson | c053b3b | 2019-01-08 18:22:07 -0800 | [diff] [blame] | 50 | android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM)); |
| 51 | |
Yi-Yo Chiang | f72d88a | 2021-03-22 13:45:39 +0800 | [diff] [blame] | 52 | // Create globally readable files. |
| 53 | umask(0022); |
| 54 | |
David Anderson | d614eca | 2019-09-09 17:57:06 -0700 | [diff] [blame] | 55 | 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); |
David Anderson | 73274df | 2022-01-10 02:37:33 +0000 | [diff] [blame] | 62 | } else if (argv[1] == "verify-image-maps"s) { |
| 63 | android::gsi::GsiService::VerifyImageMaps(); |
| 64 | exit(0); |
David Anderson | d614eca | 2019-09-09 17:57:06 -0700 | [diff] [blame] | 65 | } |
David Anderson | b3aff18 | 2019-01-11 14:37:51 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Howard Chen | 67a2709 | 2020-02-15 17:32:02 +0800 | [diff] [blame] | 68 | android::gsi::GsiService::Register(); |
David Anderson | c053b3b | 2019-01-08 18:22:07 -0800 | [diff] [blame] | 69 | { |
| 70 | sp<ProcessState> ps(ProcessState::self()); |
| 71 | ps->startThreadPool(); |
| 72 | ps->giveThreadPoolName(); |
| 73 | } |
| 74 | android::IPCThreadState::self()->joinThreadPool(); |
| 75 | |
| 76 | exit(0); |
| 77 | } |