Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 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 | |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 17 | #include <sysexits.h> |
| 18 | #include <unistd.h> |
| 19 | |
Tomasz Wasilczyk | 26db5e4 | 2023-11-02 11:45:11 -0700 | [diff] [blame] | 20 | #include <filesystem> |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 21 | #include <iostream> |
| 22 | |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 23 | #include <android-base/logging.h> |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 24 | #include <android-base/properties.h> |
Yifan Hong | a5b0269 | 2021-07-22 20:06:48 -0700 | [diff] [blame] | 25 | #include <android/debug/BnAdbCallback.h> |
| 26 | #include <android/debug/IAdbManager.h> |
Yifan Hong | bd8ca57 | 2021-06-14 19:58:34 -0700 | [diff] [blame] | 27 | #include <android/os/BnServiceManager.h> |
Yifan Hong | e435882 | 2021-06-14 12:49:43 -0700 | [diff] [blame] | 28 | #include <android/os/IServiceManager.h> |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 29 | #include <binder/IServiceManager.h> |
Yifan Hong | a5b0269 | 2021-07-22 20:06:48 -0700 | [diff] [blame] | 30 | #include <binder/ProcessState.h> |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 31 | #include <binder/RpcServer.h> |
| 32 | |
Tomasz Wasilczyk | 26db5e4 | 2023-11-02 11:45:11 -0700 | [diff] [blame] | 33 | #include "file.h" |
| 34 | |
Yifan Hong | 02530ec | 2021-06-10 13:38:38 -0700 | [diff] [blame] | 35 | using android::BBinder; |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 36 | using android::defaultServiceManager; |
| 37 | using android::OK; |
| 38 | using android::RpcServer; |
Yifan Hong | 02530ec | 2021-06-10 13:38:38 -0700 | [diff] [blame] | 39 | using android::sp; |
Steven Moreland | 2372f9d | 2021-08-05 15:42:01 -0700 | [diff] [blame] | 40 | using android::status_t; |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 41 | using android::statusToString; |
| 42 | using android::String16; |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 43 | using android::base::GetBoolProperty; |
| 44 | using android::base::InitLogging; |
| 45 | using android::base::LogdLogger; |
| 46 | using android::base::LogId; |
| 47 | using android::base::LogSeverity; |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 48 | using android::base::StdioLogger; |
Yifan Hong | e435882 | 2021-06-14 12:49:43 -0700 | [diff] [blame] | 49 | using std::string_view_literals::operator""sv; |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 50 | |
| 51 | namespace { |
Yifan Hong | 9ffa66e | 2021-06-16 16:44:20 -0700 | [diff] [blame] | 52 | |
Devin Moore | f3b9c4f | 2021-08-03 15:50:13 +0000 | [diff] [blame] | 53 | const char* kLocalInetAddress = "127.0.0.1"; |
Yifan Hong | 9ffa66e | 2021-06-16 16:44:20 -0700 | [diff] [blame] | 54 | using ServiceRetriever = decltype(&android::IServiceManager::checkService); |
Yifan Hong | a5b0269 | 2021-07-22 20:06:48 -0700 | [diff] [blame] | 55 | using android::debug::IAdbManager; |
Yifan Hong | 9ffa66e | 2021-06-16 16:44:20 -0700 | [diff] [blame] | 56 | |
Tomasz Wasilczyk | 26db5e4 | 2023-11-02 11:45:11 -0700 | [diff] [blame] | 57 | int Usage(std::filesystem::path program) { |
| 58 | auto basename = program.filename(); |
Tomasz Wasilczyk | 3caae30 | 2023-10-12 20:57:02 +0000 | [diff] [blame] | 59 | // clang-format off |
| 60 | LOG(ERROR) << R"(dispatch calls to RPC service. |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 61 | Usage: |
Tomasz Wasilczyk | 3caae30 | 2023-10-12 20:57:02 +0000 | [diff] [blame] | 62 | )" << basename << R"( [-g] [-i <ip_address>] <service_name> |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 63 | <service_name>: the service to connect to. |
Tomasz Wasilczyk | 3caae30 | 2023-10-12 20:57:02 +0000 | [diff] [blame] | 64 | )" << basename << R"( [-g] manager |
Yifan Hong | e435882 | 2021-06-14 12:49:43 -0700 | [diff] [blame] | 65 | Runs an RPC-friendly service that redirects calls to servicemanager. |
| 66 | |
Yifan Hong | 9ffa66e | 2021-06-16 16:44:20 -0700 | [diff] [blame] | 67 | -g: use getService() instead of checkService(). |
Devin Moore | b48b9fc | 2023-10-06 23:16:48 +0000 | [diff] [blame] | 68 | -i: use ip_address when setting up the server instead of '127.0.0.1' |
Yifan Hong | 9ffa66e | 2021-06-16 16:44:20 -0700 | [diff] [blame] | 69 | |
Yifan Hong | e435882 | 2021-06-14 12:49:43 -0700 | [diff] [blame] | 70 | If successful, writes port number and a new line character to stdout, and |
| 71 | blocks until killed. |
| 72 | Otherwise, writes error message to stderr and exits with non-zero code. |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 73 | )"; |
Tomasz Wasilczyk | 3caae30 | 2023-10-12 20:57:02 +0000 | [diff] [blame] | 74 | // clang-format on |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 75 | return EX_USAGE; |
| 76 | } |
| 77 | |
Devin Moore | b48b9fc | 2023-10-06 23:16:48 +0000 | [diff] [blame] | 78 | int Dispatch(const char* name, const ServiceRetriever& serviceRetriever, |
| 79 | const char* ip_address = kLocalInetAddress) { |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 80 | auto sm = defaultServiceManager(); |
| 81 | if (nullptr == sm) { |
| 82 | LOG(ERROR) << "No servicemanager"; |
| 83 | return EX_SOFTWARE; |
| 84 | } |
Yifan Hong | 9ffa66e | 2021-06-16 16:44:20 -0700 | [diff] [blame] | 85 | auto binder = std::invoke(serviceRetriever, defaultServiceManager(), String16(name)); |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 86 | if (nullptr == binder) { |
| 87 | LOG(ERROR) << "No service \"" << name << "\""; |
| 88 | return EX_SOFTWARE; |
| 89 | } |
| 90 | auto rpcServer = RpcServer::make(); |
| 91 | if (nullptr == rpcServer) { |
| 92 | LOG(ERROR) << "Cannot create RpcServer"; |
| 93 | return EX_SOFTWARE; |
| 94 | } |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 95 | unsigned int port; |
Devin Moore | b48b9fc | 2023-10-06 23:16:48 +0000 | [diff] [blame] | 96 | if (status_t status = rpcServer->setupInetServer(ip_address, 0, &port); status != OK) { |
Steven Moreland | 2372f9d | 2021-08-05 15:42:01 -0700 | [diff] [blame] | 97 | LOG(ERROR) << "setupInetServer failed: " << statusToString(status); |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 98 | return EX_SOFTWARE; |
| 99 | } |
| 100 | auto socket = rpcServer->releaseServer(); |
Yifan Hong | 02530ec | 2021-06-10 13:38:38 -0700 | [diff] [blame] | 101 | auto keepAliveBinder = sp<BBinder>::make(); |
| 102 | auto status = binder->setRpcClientDebug(std::move(socket), keepAliveBinder); |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 103 | if (status != OK) { |
| 104 | LOG(ERROR) << "setRpcClientDebug failed with " << statusToString(status); |
| 105 | return EX_SOFTWARE; |
| 106 | } |
Yifan Hong | e435882 | 2021-06-14 12:49:43 -0700 | [diff] [blame] | 107 | LOG(INFO) << "Finish setting up RPC on service " << name << " on port " << port; |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 108 | |
| 109 | std::cout << port << std::endl; |
Yifan Hong | d3cb24a | 2021-06-10 17:20:57 -0700 | [diff] [blame] | 110 | |
| 111 | TEMP_FAILURE_RETRY(pause()); |
| 112 | |
| 113 | PLOG(FATAL) << "TEMP_FAILURE_RETRY(pause()) exits; this should not happen!"; |
| 114 | __builtin_unreachable(); |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Yifan Hong | bd8ca57 | 2021-06-14 19:58:34 -0700 | [diff] [blame] | 117 | // Wrapper that wraps a BpServiceManager as a BnServiceManager. |
| 118 | class ServiceManagerProxyToNative : public android::os::BnServiceManager { |
| 119 | public: |
| 120 | ServiceManagerProxyToNative(const sp<android::os::IServiceManager>& impl) : mImpl(impl) {} |
Alice Wang | 11da150 | 2024-07-25 12:03:22 +0000 | [diff] [blame] | 121 | android::binder::Status getService(const std::string&, |
| 122 | android::sp<android::IBinder>*) override { |
| 123 | // We can't send BpBinder for regular binder over RPC. |
| 124 | return android::binder::Status::fromStatusT(android::INVALID_OPERATION); |
| 125 | } |
| 126 | android::binder::Status getService2(const std::string&, android::os::Service*) override { |
Yifan Hong | bd8ca57 | 2021-06-14 19:58:34 -0700 | [diff] [blame] | 127 | // We can't send BpBinder for regular binder over RPC. |
| 128 | return android::binder::Status::fromStatusT(android::INVALID_OPERATION); |
| 129 | } |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 130 | android::binder::Status checkService(const std::string&, android::os::Service*) override { |
Yifan Hong | bd8ca57 | 2021-06-14 19:58:34 -0700 | [diff] [blame] | 131 | // We can't send BpBinder for regular binder over RPC. |
| 132 | return android::binder::Status::fromStatusT(android::INVALID_OPERATION); |
| 133 | } |
| 134 | android::binder::Status addService(const std::string&, const android::sp<android::IBinder>&, |
| 135 | bool, int32_t) override { |
| 136 | // We can't send BpBinder for RPC over regular binder. |
| 137 | return android::binder::Status::fromStatusT(android::INVALID_OPERATION); |
| 138 | } |
| 139 | android::binder::Status listServices(int32_t dumpPriority, |
| 140 | std::vector<std::string>* _aidl_return) override { |
| 141 | return mImpl->listServices(dumpPriority, _aidl_return); |
| 142 | } |
| 143 | android::binder::Status registerForNotifications( |
| 144 | const std::string&, const android::sp<android::os::IServiceCallback>&) override { |
| 145 | // We can't send BpBinder for RPC over regular binder. |
| 146 | return android::binder::Status::fromStatusT(android::INVALID_OPERATION); |
| 147 | } |
| 148 | android::binder::Status unregisterForNotifications( |
| 149 | const std::string&, const android::sp<android::os::IServiceCallback>&) override { |
| 150 | // We can't send BpBinder for RPC over regular binder. |
| 151 | return android::binder::Status::fromStatusT(android::INVALID_OPERATION); |
| 152 | } |
| 153 | android::binder::Status isDeclared(const std::string& name, bool* _aidl_return) override { |
| 154 | return mImpl->isDeclared(name, _aidl_return); |
| 155 | } |
| 156 | android::binder::Status getDeclaredInstances(const std::string& iface, |
| 157 | std::vector<std::string>* _aidl_return) override { |
| 158 | return mImpl->getDeclaredInstances(iface, _aidl_return); |
| 159 | } |
| 160 | android::binder::Status updatableViaApex(const std::string& name, |
| 161 | std::optional<std::string>* _aidl_return) override { |
| 162 | return mImpl->updatableViaApex(name, _aidl_return); |
| 163 | } |
Jooyung Han | 76944fe | 2022-10-25 17:02:45 +0900 | [diff] [blame] | 164 | android::binder::Status getUpdatableNames(const std::string& apexName, |
| 165 | std::vector<std::string>* _aidl_return) override { |
| 166 | return mImpl->getUpdatableNames(apexName, _aidl_return); |
| 167 | } |
Devin Moore | 5e4c2f1 | 2021-09-09 22:36:33 +0000 | [diff] [blame] | 168 | android::binder::Status getConnectionInfo( |
| 169 | const std::string& name, |
| 170 | std::optional<android::os::ConnectionInfo>* _aidl_return) override { |
| 171 | return mImpl->getConnectionInfo(name, _aidl_return); |
| 172 | } |
Yifan Hong | bd8ca57 | 2021-06-14 19:58:34 -0700 | [diff] [blame] | 173 | android::binder::Status registerClientCallback( |
| 174 | const std::string&, const android::sp<android::IBinder>&, |
| 175 | const android::sp<android::os::IClientCallback>&) override { |
| 176 | // We can't send BpBinder for RPC over regular binder. |
| 177 | return android::binder::Status::fromStatusT(android::INVALID_OPERATION); |
| 178 | } |
| 179 | android::binder::Status tryUnregisterService(const std::string&, |
| 180 | const android::sp<android::IBinder>&) override { |
| 181 | // We can't send BpBinder for RPC over regular binder. |
| 182 | return android::binder::Status::fromStatusT(android::INVALID_OPERATION); |
| 183 | } |
| 184 | android::binder::Status getServiceDebugInfo( |
| 185 | std::vector<android::os::ServiceDebugInfo>* _aidl_return) override { |
| 186 | return mImpl->getServiceDebugInfo(_aidl_return); |
| 187 | } |
| 188 | |
| 189 | private: |
| 190 | sp<android::os::IServiceManager> mImpl; |
| 191 | }; |
| 192 | |
Yifan Hong | e435882 | 2021-06-14 12:49:43 -0700 | [diff] [blame] | 193 | // Workaround for b/191059588. |
| 194 | // TODO(b/191059588): Once we can run RpcServer on single-threaded services, |
| 195 | // `servicedispatcher manager` should call Dispatch("manager") directly. |
Devin Moore | b48b9fc | 2023-10-06 23:16:48 +0000 | [diff] [blame] | 196 | int wrapServiceManager(const ServiceRetriever& serviceRetriever, |
| 197 | const char* ip_address = kLocalInetAddress) { |
Yifan Hong | e435882 | 2021-06-14 12:49:43 -0700 | [diff] [blame] | 198 | auto sm = defaultServiceManager(); |
| 199 | if (nullptr == sm) { |
| 200 | LOG(ERROR) << "No servicemanager"; |
| 201 | return EX_SOFTWARE; |
| 202 | } |
Yifan Hong | 9ffa66e | 2021-06-16 16:44:20 -0700 | [diff] [blame] | 203 | auto service = std::invoke(serviceRetriever, defaultServiceManager(), String16("manager")); |
Yifan Hong | e435882 | 2021-06-14 12:49:43 -0700 | [diff] [blame] | 204 | if (nullptr == service) { |
| 205 | LOG(ERROR) << "No service called `manager`"; |
| 206 | return EX_SOFTWARE; |
| 207 | } |
Yifan Hong | bd8ca57 | 2021-06-14 19:58:34 -0700 | [diff] [blame] | 208 | auto interface = android::os::IServiceManager::asInterface(service); |
| 209 | if (nullptr == interface) { |
| 210 | LOG(ERROR) << "Cannot cast service called `manager` to IServiceManager"; |
| 211 | return EX_SOFTWARE; |
| 212 | } |
| 213 | |
| 214 | // Work around restriction that doesn't allow us to send proxy over RPC. |
| 215 | interface = sp<ServiceManagerProxyToNative>::make(interface); |
| 216 | service = ServiceManagerProxyToNative::asBinder(interface); |
Yifan Hong | e435882 | 2021-06-14 12:49:43 -0700 | [diff] [blame] | 217 | |
| 218 | auto rpcServer = RpcServer::make(); |
Yifan Hong | e435882 | 2021-06-14 12:49:43 -0700 | [diff] [blame] | 219 | rpcServer->setRootObject(service); |
| 220 | unsigned int port; |
Devin Moore | b48b9fc | 2023-10-06 23:16:48 +0000 | [diff] [blame] | 221 | if (status_t status = rpcServer->setupInetServer(ip_address, 0, &port); status != OK) { |
Steven Moreland | 2372f9d | 2021-08-05 15:42:01 -0700 | [diff] [blame] | 222 | LOG(ERROR) << "Unable to set up inet server: " << statusToString(status); |
Yifan Hong | e435882 | 2021-06-14 12:49:43 -0700 | [diff] [blame] | 223 | return EX_SOFTWARE; |
| 224 | } |
| 225 | LOG(INFO) << "Finish wrapping servicemanager with RPC on port " << port; |
| 226 | std::cout << port << std::endl; |
| 227 | rpcServer->join(); |
| 228 | |
| 229 | LOG(FATAL) << "Wrapped servicemanager exits; this should not happen!"; |
| 230 | __builtin_unreachable(); |
| 231 | } |
| 232 | |
Yifan Hong | a5b0269 | 2021-07-22 20:06:48 -0700 | [diff] [blame] | 233 | class AdbCallback : public android::debug::BnAdbCallback { |
| 234 | public: |
| 235 | android::binder::Status onDebuggingChanged(bool enabled, |
| 236 | android::debug::AdbTransportType) override { |
| 237 | if (!enabled) { |
| 238 | LOG(ERROR) << "ADB debugging disabled, exiting."; |
| 239 | exit(EX_SOFTWARE); |
| 240 | } |
| 241 | return android::binder::Status::ok(); |
| 242 | } |
| 243 | }; |
| 244 | |
| 245 | void exitOnAdbDebuggingDisabled() { |
| 246 | auto adb = android::waitForService<IAdbManager>(String16("adb")); |
| 247 | CHECK(adb != nullptr) << "Unable to retrieve service adb"; |
| 248 | auto status = adb->registerCallback(sp<AdbCallback>::make()); |
| 249 | CHECK(status.isOk()) << "Unable to call IAdbManager::registerCallback: " << status; |
| 250 | } |
| 251 | |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 252 | // Log to logd. For warning and more severe messages, also log to stderr. |
| 253 | class ServiceDispatcherLogger { |
| 254 | public: |
| 255 | void operator()(LogId id, LogSeverity severity, const char* tag, const char* file, |
| 256 | unsigned int line, const char* message) { |
| 257 | mLogdLogger(id, severity, tag, file, line, message); |
| 258 | if (severity >= LogSeverity::WARNING) { |
| 259 | std::cout << std::flush; |
Tomasz Wasilczyk | 26db5e4 | 2023-11-02 11:45:11 -0700 | [diff] [blame] | 260 | auto progname = std::filesystem::path(getprogname()).filename(); |
| 261 | std::cerr << progname << ": " << message << std::endl; |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
| 265 | private: |
| 266 | LogdLogger mLogdLogger{}; |
| 267 | }; |
| 268 | |
| 269 | } // namespace |
| 270 | |
| 271 | int main(int argc, char* argv[]) { |
| 272 | InitLogging(argv, ServiceDispatcherLogger()); |
| 273 | |
| 274 | if (!GetBoolProperty("ro.debuggable", false)) { |
| 275 | LOG(ERROR) << "servicedispatcher is only allowed on debuggable builds."; |
| 276 | return EX_NOPERM; |
| 277 | } |
| 278 | LOG(WARNING) << "WARNING: servicedispatcher is debug only. Use with caution."; |
| 279 | |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 280 | int opt; |
Yifan Hong | 9ffa66e | 2021-06-16 16:44:20 -0700 | [diff] [blame] | 281 | ServiceRetriever serviceRetriever = &android::IServiceManager::checkService; |
Devin Moore | b48b9fc | 2023-10-06 23:16:48 +0000 | [diff] [blame] | 282 | char* ip_address = nullptr; |
| 283 | while (-1 != (opt = getopt(argc, argv, "gi:"))) { |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 284 | switch (opt) { |
Yifan Hong | 9ffa66e | 2021-06-16 16:44:20 -0700 | [diff] [blame] | 285 | case 'g': { |
Tomasz Wasilczyk | bb07b98 | 2023-10-11 21:25:36 +0000 | [diff] [blame] | 286 | #pragma clang diagnostic push |
| 287 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" |
Yifan Hong | 9ffa66e | 2021-06-16 16:44:20 -0700 | [diff] [blame] | 288 | serviceRetriever = &android::IServiceManager::getService; |
Tomasz Wasilczyk | bb07b98 | 2023-10-11 21:25:36 +0000 | [diff] [blame] | 289 | #pragma clang diagnostic pop |
Yifan Hong | 9ffa66e | 2021-06-16 16:44:20 -0700 | [diff] [blame] | 290 | } break; |
Devin Moore | b48b9fc | 2023-10-06 23:16:48 +0000 | [diff] [blame] | 291 | case 'i': { |
| 292 | ip_address = optarg; |
| 293 | } break; |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 294 | default: { |
| 295 | return Usage(argv[0]); |
| 296 | } |
| 297 | } |
| 298 | } |
Yifan Hong | e435882 | 2021-06-14 12:49:43 -0700 | [diff] [blame] | 299 | |
Yifan Hong | a5b0269 | 2021-07-22 20:06:48 -0700 | [diff] [blame] | 300 | android::ProcessState::self()->setThreadPoolMaxThreadCount(1); |
| 301 | android::ProcessState::self()->startThreadPool(); |
| 302 | exitOnAdbDebuggingDisabled(); |
| 303 | |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 304 | if (optind + 1 != argc) return Usage(argv[0]); |
| 305 | auto name = argv[optind]; |
| 306 | |
Yifan Hong | e435882 | 2021-06-14 12:49:43 -0700 | [diff] [blame] | 307 | if (name == "manager"sv) { |
Devin Moore | b48b9fc | 2023-10-06 23:16:48 +0000 | [diff] [blame] | 308 | if (ip_address) { |
| 309 | return wrapServiceManager(serviceRetriever, ip_address); |
| 310 | } else { |
| 311 | return wrapServiceManager(serviceRetriever); |
| 312 | } |
Yifan Hong | e435882 | 2021-06-14 12:49:43 -0700 | [diff] [blame] | 313 | } |
Devin Moore | b48b9fc | 2023-10-06 23:16:48 +0000 | [diff] [blame] | 314 | if (ip_address) { |
| 315 | return Dispatch(name, serviceRetriever, ip_address); |
| 316 | } else { |
| 317 | return Dispatch(name, serviceRetriever); |
| 318 | } |
Yifan Hong | dbf58d4 | 2021-06-03 19:21:11 -0700 | [diff] [blame] | 319 | } |