blob: 3dfb7e0d455452b6cb27af17102db26e10ef497b [file] [log] [blame]
Yifan Hong443df792017-05-09 18:49:45 -07001/*
2 * Copyright (C) 2017 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 "ListCommand.h"
18
19#include <getopt.h>
20
21#include <fstream>
22#include <iomanip>
23#include <iostream>
24#include <map>
25#include <sstream>
26#include <regex>
27
Yifan Hongf31aa052018-02-02 15:17:51 -080028#include <android-base/file.h>
Yifan Hong443df792017-05-09 18:49:45 -070029#include <android-base/parseint.h>
30#include <android/hidl/manager/1.0/IServiceManager.h>
Yifan Hongfee209d2017-09-14 18:23:38 -070031#include <hidl-hash/Hash.h>
Yifan Hong443df792017-05-09 18:49:45 -070032#include <hidl-util/FQName.h>
33#include <private/android_filesystem_config.h>
34#include <sys/stat.h>
35#include <vintf/HalManifest.h>
Yifan Hongf31aa052018-02-02 15:17:51 -080036#include <vintf/parse_string.h>
Yifan Hong443df792017-05-09 18:49:45 -070037#include <vintf/parse_xml.h>
38
39#include "Lshal.h"
40#include "PipeRelay.h"
41#include "Timeout.h"
42#include "utils.h"
43
44using ::android::hardware::hidl_string;
Yifan Hong22ea7b82017-09-14 18:07:43 -070045using ::android::hardware::hidl_vec;
46using ::android::hidl::base::V1_0::DebugInfo;
47using ::android::hidl::base::V1_0::IBase;
Yifan Hong443df792017-05-09 18:49:45 -070048using ::android::hidl::manager::V1_0::IServiceManager;
49
50namespace android {
51namespace lshal {
52
Yifan Hongf31aa052018-02-02 15:17:51 -080053vintf::SchemaType toSchemaType(Partition p) {
54 return (p == Partition::SYSTEM) ? vintf::SchemaType::FRAMEWORK : vintf::SchemaType::DEVICE;
55}
56
Yifan Hong76ac14a2017-09-08 14:59:04 -070057NullableOStream<std::ostream> ListCommand::out() const {
58 return mLshal.out();
59}
60
61NullableOStream<std::ostream> ListCommand::err() const {
62 return mLshal.err();
Yifan Hong443df792017-05-09 18:49:45 -070063}
64
Yifan Hong795b6ec2017-09-13 11:25:28 -070065std::string ListCommand::GetName() {
66 return "list";
67}
68std::string ListCommand::getSimpleDescription() const {
69 return "List HALs.";
70}
71
Yifan Hong8bf73162017-09-07 18:06:13 -070072std::string ListCommand::parseCmdline(pid_t pid) const {
Yifan Hongf31aa052018-02-02 15:17:51 -080073 return android::procpartition::getCmdline(pid);
Yifan Hong443df792017-05-09 18:49:45 -070074}
75
76const std::string &ListCommand::getCmdline(pid_t pid) {
77 auto pair = mCmdlines.find(pid);
78 if (pair != mCmdlines.end()) {
79 return pair->second;
80 }
Yifan Hong8bf73162017-09-07 18:06:13 -070081 mCmdlines[pid] = parseCmdline(pid);
Yifan Hong443df792017-05-09 18:49:45 -070082 return mCmdlines[pid];
83}
84
85void ListCommand::removeDeadProcesses(Pids *pids) {
86 static const pid_t myPid = getpid();
Yifan Hong61fb7bc2017-05-12 16:33:57 -070087 pids->erase(std::remove_if(pids->begin(), pids->end(), [this](auto pid) {
Yifan Hong443df792017-05-09 18:49:45 -070088 return pid == myPid || this->getCmdline(pid).empty();
Yifan Hong61fb7bc2017-05-12 16:33:57 -070089 }), pids->end());
Yifan Hong443df792017-05-09 18:49:45 -070090}
91
Yifan Hongf31aa052018-02-02 15:17:51 -080092Partition ListCommand::getPartition(pid_t pid) {
93 auto it = mPartitions.find(pid);
94 if (it != mPartitions.end()) {
95 return it->second;
96 }
97 Partition partition = android::procpartition::getPartition(pid);
98 mPartitions.emplace(pid, partition);
99 return partition;
100}
101
102// Give sensible defaults when nothing can be inferred from runtime.
103// process: Partition inferred from executable location or cmdline.
104Partition ListCommand::resolvePartition(Partition process, const FQName& fqName) const {
105 if (fqName.inPackage("vendor") ||
106 fqName.inPackage("com")) {
107 return Partition::VENDOR;
108 }
109
110 if (fqName.inPackage("android.frameworks") ||
111 fqName.inPackage("android.system") ||
112 fqName.inPackage("android.hidl")) {
113 return Partition::SYSTEM;
114 }
115
116 // Some android.hardware HALs are served from system. Check the value from executable
117 // location / cmdline first.
118 if (fqName.inPackage("android.hardware")) {
119 if (process != Partition::UNKNOWN) {
120 return process;
121 }
122 return Partition::VENDOR;
123 }
124
125 return process;
126}
127
Yifan Hong1243dde2017-09-14 17:49:30 -0700128static bool scanBinderContext(pid_t pid,
Steven Morelandd8e20192017-05-24 11:23:08 -0700129 const std::string &contextName,
130 std::function<void(const std::string&)> eachLine) {
131 std::ifstream ifs("/d/binder/proc/" + std::to_string(pid));
Yifan Hong443df792017-05-09 18:49:45 -0700132 if (!ifs.is_open()) {
133 return false;
134 }
135
Steven Morelandd8e20192017-05-24 11:23:08 -0700136 static const std::regex kContextLine("^context (\\w+)$");
Yifan Hong443df792017-05-09 18:49:45 -0700137
Steven Morelandd8e20192017-05-24 11:23:08 -0700138 bool isDesiredContext = false;
Yifan Hong443df792017-05-09 18:49:45 -0700139 std::string line;
140 std::smatch match;
141 while(getline(ifs, line)) {
Steven Morelandd8e20192017-05-24 11:23:08 -0700142 if (std::regex_search(line, match, kContextLine)) {
143 isDesiredContext = match.str(1) == contextName;
Yifan Hong443df792017-05-09 18:49:45 -0700144 continue;
145 }
Steven Morelandd8e20192017-05-24 11:23:08 -0700146
147 if (!isDesiredContext) {
Yifan Hong443df792017-05-09 18:49:45 -0700148 continue;
149 }
Steven Morelandd8e20192017-05-24 11:23:08 -0700150
151 eachLine(line);
Yifan Hong443df792017-05-09 18:49:45 -0700152 }
153 return true;
154}
155
Steven Morelandd8e20192017-05-24 11:23:08 -0700156bool ListCommand::getPidInfo(
157 pid_t serverPid, PidInfo *pidInfo) const {
158 static const std::regex kReferencePrefix("^\\s*node \\d+:\\s+u([0-9a-f]+)\\s+c([0-9a-f]+)\\s+");
159 static const std::regex kThreadPrefix("^\\s*thread \\d+:\\s+l\\s+(\\d)(\\d)");
160
161 std::smatch match;
162 return scanBinderContext(serverPid, "hwbinder", [&](const std::string& line) {
163 if (std::regex_search(line, match, kReferencePrefix)) {
164 const std::string &ptrString = "0x" + match.str(2); // use number after c
165 uint64_t ptr;
166 if (!::android::base::ParseUint(ptrString.c_str(), &ptr)) {
167 // Should not reach here, but just be tolerant.
Yifan Hong76ac14a2017-09-08 14:59:04 -0700168 err() << "Could not parse number " << ptrString << std::endl;
Steven Morelandd8e20192017-05-24 11:23:08 -0700169 return;
170 }
171 const std::string proc = " proc ";
172 auto pos = line.rfind(proc);
173 if (pos != std::string::npos) {
174 for (const std::string &pidStr : split(line.substr(pos + proc.size()), ' ')) {
175 int32_t pid;
176 if (!::android::base::ParseInt(pidStr, &pid)) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700177 err() << "Could not parse number " << pidStr << std::endl;
Steven Morelandd8e20192017-05-24 11:23:08 -0700178 return;
179 }
180 pidInfo->refPids[ptr].push_back(pid);
181 }
182 }
183
184 return;
185 }
186
187 if (std::regex_search(line, match, kThreadPrefix)) {
188 // "1" is waiting in binder driver
189 // "2" is poll. It's impossible to tell if these are in use.
190 // and HIDL default code doesn't use it.
191 bool isInUse = match.str(1) != "1";
192 // "0" is a thread that has called into binder
193 // "1" is looper thread
194 // "2" is main looper thread
195 bool isHwbinderThread = match.str(2) != "0";
196
197 if (!isHwbinderThread) {
198 return;
199 }
200
201 if (isInUse) {
202 pidInfo->threadUsage++;
203 }
204
205 pidInfo->threadCount++;
206 return;
207 }
208
209 // not reference or thread line
210 return;
211 });
212}
213
Yifan Hong1243dde2017-09-14 17:49:30 -0700214const PidInfo* ListCommand::getPidInfoCached(pid_t serverPid) {
215 auto pair = mCachedPidInfos.insert({serverPid, PidInfo{}});
216 if (pair.second /* did insertion take place? */) {
217 if (!getPidInfo(serverPid, &pair.first->second)) {
218 return nullptr;
219 }
220 }
221 return &pair.first->second;
222}
223
Yifan Hong443df792017-05-09 18:49:45 -0700224// Must process hwbinder services first, then passthrough services.
225void ListCommand::forEachTable(const std::function<void(Table &)> &f) {
226 f(mServicesTable);
227 f(mPassthroughRefTable);
228 f(mImplementationsTable);
229}
230void ListCommand::forEachTable(const std::function<void(const Table &)> &f) const {
231 f(mServicesTable);
232 f(mPassthroughRefTable);
233 f(mImplementationsTable);
234}
235
236void ListCommand::postprocess() {
237 forEachTable([this](Table &table) {
238 if (mSortColumn) {
239 std::sort(table.begin(), table.end(), mSortColumn);
240 }
241 for (TableEntry &entry : table) {
242 entry.serverCmdline = getCmdline(entry.serverPid);
243 removeDeadProcesses(&entry.clientPids);
244 for (auto pid : entry.clientPids) {
245 entry.clientCmdlines.push_back(this->getCmdline(pid));
246 }
247 }
Yifan Hongf31aa052018-02-02 15:17:51 -0800248 for (TableEntry& entry : table) {
249 entry.partition = getPartition(entry.serverPid);
250 }
Yifan Hong443df792017-05-09 18:49:45 -0700251 });
252 // use a double for loop here because lshal doesn't care about efficiency.
253 for (TableEntry &packageEntry : mImplementationsTable) {
254 std::string packageName = packageEntry.interfaceName;
Steven Morelandd4f32b32018-03-06 14:47:58 -0800255 FQName fqPackageName;
256 if (!FQName::parse(packageName.substr(0, packageName.find("::")), &fqPackageName)) {
Yifan Hong443df792017-05-09 18:49:45 -0700257 continue;
258 }
259 for (TableEntry &interfaceEntry : mPassthroughRefTable) {
260 if (interfaceEntry.arch != ARCH_UNKNOWN) {
261 continue;
262 }
Steven Morelandd4f32b32018-03-06 14:47:58 -0800263 FQName interfaceName;
264 if (!FQName::parse(splitFirst(interfaceEntry.interfaceName, '/').first, &interfaceName)) {
Yifan Hong443df792017-05-09 18:49:45 -0700265 continue;
266 }
267 if (interfaceName.getPackageAndVersion() == fqPackageName) {
268 interfaceEntry.arch = packageEntry.arch;
269 }
270 }
271 }
Yifan Hongca3b6602017-09-07 16:44:27 -0700272
273 mServicesTable.setDescription(
274 "All binderized services (registered services through hwservicemanager)");
275 mPassthroughRefTable.setDescription(
276 "All interfaces that getService() has ever return as a passthrough interface;\n"
277 "PIDs / processes shown below might be inaccurate because the process\n"
278 "might have relinquished the interface or might have died.\n"
279 "The Server / Server CMD column can be ignored.\n"
280 "The Clients / Clients CMD column shows all process that have ever dlopen'ed \n"
281 "the library and successfully fetched the passthrough implementation.");
282 mImplementationsTable.setDescription(
Steven Moreland3d2c1e12018-03-14 10:41:13 -0700283 "All available passthrough implementations (all -impl.so files).\n"
284 "These may return subclasses through their respective HIDL_FETCH_I* functions.");
Yifan Hong443df792017-05-09 18:49:45 -0700285}
286
Yifan Hong77c87822017-06-19 15:47:39 -0700287static inline bool findAndBumpVersion(vintf::ManifestHal* hal, const vintf::Version& version) {
288 for (vintf::Version& v : hal->versions) {
289 if (v.majorVer == version.majorVer) {
290 v.minorVer = std::max(v.minorVer, version.minorVer);
291 return true;
292 }
293 }
294 return false;
295}
296
Yifan Hongca3b6602017-09-07 16:44:27 -0700297void ListCommand::dumpVintf(const NullableOStream<std::ostream>& out) const {
Yifan Hong236301c2017-06-19 12:27:08 -0700298 using vintf::operator|=;
Yifan Hongf31aa052018-02-02 15:17:51 -0800299 using vintf::operator<<;
Yifan Hong443df792017-05-09 18:49:45 -0700300
301 vintf::HalManifest manifest;
Yifan Hongf31aa052018-02-02 15:17:51 -0800302 manifest.setType(toSchemaType(mVintfPartition));
Yifan Hong443df792017-05-09 18:49:45 -0700303 forEachTable([this, &manifest] (const Table &table) {
304 for (const TableEntry &entry : table) {
305
306 std::string fqInstanceName = entry.interfaceName;
307
308 if (&table == &mImplementationsTable) {
309 // Quick hack to work around *'s
310 replaceAll(&fqInstanceName, '*', 'D');
311 }
Steven Morelandd4f32b32018-03-06 14:47:58 -0800312 auto splitFqInstanceName = splitFirst(fqInstanceName, '/');
313 FQName fqName;
314 if (!FQName::parse(splitFqInstanceName.first, &fqName)) {
315 err() << "Warning: '" << splitFqInstanceName.first
Yifan Hong443df792017-05-09 18:49:45 -0700316 << "' is not a valid FQName." << std::endl;
317 continue;
318 }
Yifan Hongf31aa052018-02-02 15:17:51 -0800319
320 if (fqName.package() == gIBaseFqName.package()) {
321 continue; // always remove IBase from manifest
322 }
323
324 Partition partition = resolvePartition(entry.partition, fqName);
325
326 if (partition == Partition::UNKNOWN) {
327 err() << "Warning: Cannot guess the partition of instance " << fqInstanceName
328 << ". It is removed from the generated manifest." << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700329 continue;
330 }
Yifan Hongf31aa052018-02-02 15:17:51 -0800331
332 if (partition != mVintfPartition) {
333 continue; // strip out instances that is in a different partition.
334 }
335
Yifan Hong443df792017-05-09 18:49:45 -0700336 std::string interfaceName =
337 &table == &mImplementationsTable ? "" : fqName.name();
338 std::string instanceName =
Steven Morelandd4f32b32018-03-06 14:47:58 -0800339 &table == &mImplementationsTable ? "" : splitFqInstanceName.second;
Yifan Hong443df792017-05-09 18:49:45 -0700340
341 vintf::Version version{fqName.getPackageMajorVersion(),
342 fqName.getPackageMinorVersion()};
343 vintf::Transport transport;
344 vintf::Arch arch;
345 if (entry.transport == "hwbinder") {
346 transport = vintf::Transport::HWBINDER;
347 arch = vintf::Arch::ARCH_EMPTY;
348 } else if (entry.transport == "passthrough") {
349 transport = vintf::Transport::PASSTHROUGH;
350 switch (entry.arch) {
351 case lshal::ARCH32:
352 arch = vintf::Arch::ARCH_32; break;
353 case lshal::ARCH64:
354 arch = vintf::Arch::ARCH_64; break;
355 case lshal::ARCH_BOTH:
356 arch = vintf::Arch::ARCH_32_64; break;
357 case lshal::ARCH_UNKNOWN: // fallthrough
358 default:
Yifan Hong76ac14a2017-09-08 14:59:04 -0700359 err() << "Warning: '" << fqName.package()
Yifan Hong443df792017-05-09 18:49:45 -0700360 << "' doesn't have bitness info, assuming 32+64." << std::endl;
361 arch = vintf::Arch::ARCH_32_64;
362 }
363 } else {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700364 err() << "Warning: '" << entry.transport << "' is not a valid transport." << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700365 continue;
366 }
367
368 bool done = false;
369 for (vintf::ManifestHal *hal : manifest.getHals(fqName.package())) {
370 if (hal->transport() != transport) {
371 if (transport != vintf::Transport::PASSTHROUGH) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700372 err() << "Fatal: should not reach here. Generated result may be wrong for '"
Yifan Hong236301c2017-06-19 12:27:08 -0700373 << hal->name << "'."
Yifan Hong443df792017-05-09 18:49:45 -0700374 << std::endl;
375 }
376 done = true;
377 break;
378 }
Yifan Hong77c87822017-06-19 15:47:39 -0700379 if (findAndBumpVersion(hal, version)) {
Yifan Hong443df792017-05-09 18:49:45 -0700380 if (&table != &mImplementationsTable) {
381 hal->interfaces[interfaceName].name = interfaceName;
382 hal->interfaces[interfaceName].instances.insert(instanceName);
383 }
Yifan Hong236301c2017-06-19 12:27:08 -0700384 hal->transportArch.arch |= arch;
Yifan Hong443df792017-05-09 18:49:45 -0700385 done = true;
386 break;
387 }
388 }
389 if (done) {
390 continue; // to next TableEntry
391 }
392 decltype(vintf::ManifestHal::interfaces) interfaces;
393 if (&table != &mImplementationsTable) {
394 interfaces[interfaceName].name = interfaceName;
395 interfaces[interfaceName].instances.insert(instanceName);
396 }
397 if (!manifest.add(vintf::ManifestHal{
Yifan Honga63a16b2018-03-13 14:03:03 -0700398 vintf::HalFormat::HIDL,
399 std::string{fqName.package()},
400 {version},
401 {transport, arch},
402 std::move(interfaces)})) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700403 err() << "Warning: cannot add hal '" << fqInstanceName << "'" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700404 }
405 }
406 });
Yifan Hongf31aa052018-02-02 15:17:51 -0800407 out << "<!-- " << std::endl
408 << " This is a skeleton " << manifest.type() << " manifest. Notes: " << std::endl
409 << INIT_VINTF_NOTES
410 << "-->" << std::endl;
Yifan Hongacc12122018-01-25 10:49:39 -0800411 out << vintf::gHalManifestConverter(manifest, vintf::SerializeFlag::HALS_ONLY);
Yifan Hong443df792017-05-09 18:49:45 -0700412}
413
Yifan Hongf31aa052018-02-02 15:17:51 -0800414std::string ListCommand::INIT_VINTF_NOTES{
415 " 1. If a HAL is supported in both hwbinder and passthrough transport, \n"
416 " only hwbinder is shown.\n"
417 " 2. It is likely that HALs in passthrough transport does not have\n"
418 " <interface> declared; users will have to write them by hand.\n"
419 " 3. A HAL with lower minor version can be overridden by a HAL with\n"
420 " higher minor version if they have the same name and major version.\n"
421};
422
Yifan Hong443df792017-05-09 18:49:45 -0700423static Architecture fromBaseArchitecture(::android::hidl::base::V1_0::DebugInfo::Architecture a) {
424 switch (a) {
425 case ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_64BIT:
426 return ARCH64;
427 case ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_32BIT:
428 return ARCH32;
429 case ::android::hidl::base::V1_0::DebugInfo::Architecture::UNKNOWN: // fallthrough
430 default:
431 return ARCH_UNKNOWN;
432 }
433}
434
Yifan Hongca3b6602017-09-07 16:44:27 -0700435void ListCommand::dumpTable(const NullableOStream<std::ostream>& out) const {
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700436 if (mNeat) {
Yifan Hongd4a77e82017-09-06 19:40:24 -0700437 MergedTable({&mServicesTable, &mPassthroughRefTable, &mImplementationsTable})
Yifan Hongca3b6602017-09-07 16:44:27 -0700438 .createTextTable().dump(out.buf());
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700439 return;
440 }
441
Yifan Hongca3b6602017-09-07 16:44:27 -0700442 forEachTable([this, &out](const Table &table) {
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700443
Yifan Hongd4a77e82017-09-06 19:40:24 -0700444 // We're only interested in dumping debug info for already
445 // instantiated services. There's little value in dumping the
446 // debug info for a service we create on the fly, so we only operate
447 // on the "mServicesTable".
448 std::function<std::string(const std::string&)> emitDebugInfo = nullptr;
449 if (mEmitDebugInfo && &table == &mServicesTable) {
450 emitDebugInfo = [this](const auto& iName) {
Yifan Hongca3b6602017-09-07 16:44:27 -0700451 std::stringstream ss;
Yifan Hongd4a77e82017-09-06 19:40:24 -0700452 auto pair = splitFirst(iName, '/');
Steven Moreland5f328892018-01-18 14:38:07 -0800453 mLshal.emitDebugInfo(pair.first, pair.second, {},
454 false /* excludesParentInstances */, ss,
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700455 NullableOStream<std::ostream>(nullptr));
Yifan Hongca3b6602017-09-07 16:44:27 -0700456 return ss.str();
Yifan Hongd4a77e82017-09-06 19:40:24 -0700457 };
Yifan Hong443df792017-05-09 18:49:45 -0700458 }
Yifan Hongca3b6602017-09-07 16:44:27 -0700459 table.createTextTable(mNeat, emitDebugInfo).dump(out.buf());
460 out << std::endl;
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700461 });
Yifan Hong443df792017-05-09 18:49:45 -0700462}
463
Yifan Hongca3b6602017-09-07 16:44:27 -0700464Status ListCommand::dump() {
465 auto dump = mVintf ? &ListCommand::dumpVintf : &ListCommand::dumpTable;
466
467 if (mFileOutputPath.empty()) {
468 (*this.*dump)(out());
469 return OK;
Yifan Hong443df792017-05-09 18:49:45 -0700470 }
Yifan Hongca3b6602017-09-07 16:44:27 -0700471
472 std::ofstream fileOutput(mFileOutputPath);
473 if (!fileOutput.is_open()) {
474 err() << "Could not open file '" << mFileOutputPath << "'." << std::endl;
475 return IO_ERROR;
476 }
477 chown(mFileOutputPath.c_str(), AID_SHELL, AID_SHELL);
478
479 (*this.*dump)(NullableOStream<std::ostream>(fileOutput));
480
481 fileOutput.flush();
482 fileOutput.close();
483 return OK;
Yifan Hong443df792017-05-09 18:49:45 -0700484}
485
486void ListCommand::putEntry(TableEntrySource source, TableEntry &&entry) {
487 Table *table = nullptr;
488 switch (source) {
489 case HWSERVICEMANAGER_LIST :
490 table = &mServicesTable; break;
491 case PTSERVICEMANAGER_REG_CLIENT :
492 table = &mPassthroughRefTable; break;
493 case LIST_DLLIB :
494 table = &mImplementationsTable; break;
495 default:
Yifan Hong76ac14a2017-09-08 14:59:04 -0700496 err() << "Error: Unknown source of entry " << source << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700497 }
498 if (table) {
Yifan Hongd4a77e82017-09-06 19:40:24 -0700499 table->add(std::forward<TableEntry>(entry));
Yifan Hong443df792017-05-09 18:49:45 -0700500 }
501}
502
503Status ListCommand::fetchAllLibraries(const sp<IServiceManager> &manager) {
504 using namespace ::android::hardware;
505 using namespace ::android::hidl::manager::V1_0;
506 using namespace ::android::hidl::base::V1_0;
Yifan Hongf2d557b2017-05-24 19:45:02 -0700507 using std::literals::chrono_literals::operator""s;
508 auto ret = timeoutIPC(2s, manager, &IServiceManager::debugDump, [&] (const auto &infos) {
Yifan Hong443df792017-05-09 18:49:45 -0700509 std::map<std::string, TableEntry> entries;
510 for (const auto &info : infos) {
511 std::string interfaceName = std::string{info.interfaceName.c_str()} + "/" +
512 std::string{info.instanceName.c_str()};
513 entries.emplace(interfaceName, TableEntry{
514 .interfaceName = interfaceName,
515 .transport = "passthrough",
Yifan Hongf2d557b2017-05-24 19:45:02 -0700516 .clientPids = info.clientPids,
Yifan Hong443df792017-05-09 18:49:45 -0700517 }).first->second.arch |= fromBaseArchitecture(info.arch);
518 }
519 for (auto &&pair : entries) {
520 putEntry(LIST_DLLIB, std::move(pair.second));
521 }
522 });
523 if (!ret.isOk()) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700524 err() << "Error: Failed to call list on getPassthroughServiceManager(): "
Yifan Hong443df792017-05-09 18:49:45 -0700525 << ret.description() << std::endl;
526 return DUMP_ALL_LIBS_ERROR;
527 }
528 return OK;
529}
530
531Status ListCommand::fetchPassthrough(const sp<IServiceManager> &manager) {
532 using namespace ::android::hardware;
533 using namespace ::android::hardware::details;
534 using namespace ::android::hidl::manager::V1_0;
535 using namespace ::android::hidl::base::V1_0;
536 auto ret = timeoutIPC(manager, &IServiceManager::debugDump, [&] (const auto &infos) {
537 for (const auto &info : infos) {
538 if (info.clientPids.size() <= 0) {
539 continue;
540 }
541 putEntry(PTSERVICEMANAGER_REG_CLIENT, {
542 .interfaceName =
543 std::string{info.interfaceName.c_str()} + "/" +
544 std::string{info.instanceName.c_str()},
545 .transport = "passthrough",
546 .serverPid = info.clientPids.size() == 1 ? info.clientPids[0] : NO_PID,
Yifan Hong443df792017-05-09 18:49:45 -0700547 .clientPids = info.clientPids,
548 .arch = fromBaseArchitecture(info.arch)
549 });
550 }
551 });
552 if (!ret.isOk()) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700553 err() << "Error: Failed to call debugDump on defaultServiceManager(): "
Yifan Hong443df792017-05-09 18:49:45 -0700554 << ret.description() << std::endl;
555 return DUMP_PASSTHROUGH_ERROR;
556 }
557 return OK;
558}
559
560Status ListCommand::fetchBinderized(const sp<IServiceManager> &manager) {
Yifan Hong443df792017-05-09 18:49:45 -0700561 const std::string mode = "hwbinder";
562
563 hidl_vec<hidl_string> fqInstanceNames;
564 // copying out for timeoutIPC
565 auto listRet = timeoutIPC(manager, &IServiceManager::list, [&] (const auto &names) {
566 fqInstanceNames = names;
567 });
568 if (!listRet.isOk()) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700569 err() << "Error: Failed to list services for " << mode << ": "
Yifan Hong443df792017-05-09 18:49:45 -0700570 << listRet.description() << std::endl;
571 return DUMP_BINDERIZED_ERROR;
572 }
573
574 Status status = OK;
Yifan Hong22ea7b82017-09-14 18:07:43 -0700575 std::map<std::string, TableEntry> allTableEntries;
Yifan Hong443df792017-05-09 18:49:45 -0700576 for (const auto &fqInstanceName : fqInstanceNames) {
Yifan Hong22ea7b82017-09-14 18:07:43 -0700577 // create entry and default assign all fields.
578 TableEntry& entry = allTableEntries[fqInstanceName];
579 entry.interfaceName = fqInstanceName;
580 entry.transport = mode;
581
582 status |= fetchBinderizedEntry(manager, &entry);
583 }
584
585 for (auto& pair : allTableEntries) {
586 putEntry(HWSERVICEMANAGER_LIST, std::move(pair.second));
587 }
588 return status;
589}
590
591Status ListCommand::fetchBinderizedEntry(const sp<IServiceManager> &manager,
592 TableEntry *entry) {
593 Status status = OK;
594 const auto handleError = [&](Status additionalError, const std::string& msg) {
595 err() << "Warning: Skipping \"" << entry->interfaceName << "\": " << msg << std::endl;
596 status |= DUMP_BINDERIZED_ERROR | additionalError;
597 };
598
599 const auto pair = splitFirst(entry->interfaceName, '/');
600 const auto &serviceName = pair.first;
601 const auto &instanceName = pair.second;
602 auto getRet = timeoutIPC(manager, &IServiceManager::get, serviceName, instanceName);
603 if (!getRet.isOk()) {
604 handleError(TRANSACTION_ERROR,
605 "cannot be fetched from service manager:" + getRet.description());
606 return status;
607 }
608 sp<IBase> service = getRet;
609 if (service == nullptr) {
610 handleError(NO_INTERFACE, "cannot be fetched from service manager (null)");
611 return status;
612 }
613
614 // getDebugInfo
615 do {
616 DebugInfo debugInfo;
617 auto debugRet = timeoutIPC(service, &IBase::getDebugInfo, [&] (const auto &received) {
618 debugInfo = received;
Yifan Hong443df792017-05-09 18:49:45 -0700619 });
620 if (!debugRet.isOk()) {
Yifan Hong22ea7b82017-09-14 18:07:43 -0700621 handleError(TRANSACTION_ERROR,
622 "debugging information cannot be retrieved: " + debugRet.description());
623 break; // skip getPidInfo
Yifan Hong443df792017-05-09 18:49:45 -0700624 }
Steven Morelandd8e20192017-05-24 11:23:08 -0700625
Yifan Hong22ea7b82017-09-14 18:07:43 -0700626 entry->serverPid = debugInfo.pid;
627 entry->serverObjectAddress = debugInfo.ptr;
628 entry->arch = fromBaseArchitecture(debugInfo.arch);
Steven Morelandd8e20192017-05-24 11:23:08 -0700629
Yifan Hong22ea7b82017-09-14 18:07:43 -0700630 if (debugInfo.pid != NO_PID) {
631 const PidInfo* pidInfo = getPidInfoCached(debugInfo.pid);
632 if (pidInfo == nullptr) {
633 handleError(IO_ERROR,
634 "no information for PID " + std::to_string(debugInfo.pid) +
635 ", are you root?");
636 break;
637 }
638 if (debugInfo.ptr != NO_PTR) {
639 auto it = pidInfo->refPids.find(debugInfo.ptr);
640 if (it != pidInfo->refPids.end()) {
641 entry->clientPids = it->second;
642 }
643 }
644 entry->threadUsage = pidInfo->threadUsage;
645 entry->threadCount = pidInfo->threadCount;
646 }
647 } while (0);
Yifan Hongfee209d2017-09-14 18:23:38 -0700648
649 // hash
650 do {
651 ssize_t hashIndex = -1;
652 auto ifaceChainRet = timeoutIPC(service, &IBase::interfaceChain, [&] (const auto& c) {
653 for (size_t i = 0; i < c.size(); ++i) {
654 if (serviceName == c[i]) {
655 hashIndex = static_cast<ssize_t>(i);
656 break;
657 }
658 }
659 });
660 if (!ifaceChainRet.isOk()) {
661 handleError(TRANSACTION_ERROR,
662 "interfaceChain fails: " + ifaceChainRet.description());
663 break; // skip getHashChain
664 }
665 if (hashIndex < 0) {
666 handleError(BAD_IMPL, "Interface name does not exist in interfaceChain.");
667 break; // skip getHashChain
668 }
669 auto hashRet = timeoutIPC(service, &IBase::getHashChain, [&] (const auto& hashChain) {
670 if (static_cast<size_t>(hashIndex) >= hashChain.size()) {
671 handleError(BAD_IMPL,
672 "interfaceChain indicates position " + std::to_string(hashIndex) +
673 " but getHashChain returns " + std::to_string(hashChain.size()) +
674 " hashes");
675 return;
676 }
677
678 auto&& hashArray = hashChain[hashIndex];
679 std::vector<uint8_t> hashVec{hashArray.data(), hashArray.data() + hashArray.size()};
680 entry->hash = Hash::hexString(hashVec);
681 });
682 if (!hashRet.isOk()) {
683 handleError(TRANSACTION_ERROR, "getHashChain failed: " + hashRet.description());
684 }
685 } while (0);
Yifan Hong443df792017-05-09 18:49:45 -0700686 return status;
687}
688
689Status ListCommand::fetch() {
690 Status status = OK;
Yifan Hong9881df92017-05-10 14:33:05 -0700691 auto bManager = mLshal.serviceManager();
Yifan Hong443df792017-05-09 18:49:45 -0700692 if (bManager == nullptr) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700693 err() << "Failed to get defaultServiceManager()!" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700694 status |= NO_BINDERIZED_MANAGER;
695 } else {
696 status |= fetchBinderized(bManager);
697 // Passthrough PIDs are registered to the binderized manager as well.
698 status |= fetchPassthrough(bManager);
699 }
700
Yifan Hong9881df92017-05-10 14:33:05 -0700701 auto pManager = mLshal.passthroughManager();
Yifan Hong443df792017-05-09 18:49:45 -0700702 if (pManager == nullptr) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700703 err() << "Failed to get getPassthroughServiceManager()!" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700704 status |= NO_PASSTHROUGH_MANAGER;
705 } else {
706 status |= fetchAllLibraries(pManager);
707 }
708 return status;
709}
710
Yifan Honga6b93f02017-09-13 16:53:37 -0700711void ListCommand::registerAllOptions() {
712 int v = mOptions.size();
713 // A list of acceptable command line options
714 // key: value returned by getopt_long
715 // long options with short alternatives
716 mOptions.push_back({'h', "help", no_argument, v++, [](ListCommand*, const char*) {
717 return USAGE;
718 }, ""});
719 mOptions.push_back({'i', "interface", no_argument, v++, [](ListCommand* thiz, const char*) {
720 thiz->mSelectedColumns.push_back(TableColumnType::INTERFACE_NAME);
721 return OK;
722 }, "print the instance name column"});
Yifan Hongfee209d2017-09-14 18:23:38 -0700723 mOptions.push_back({'l', "released", no_argument, v++, [](ListCommand* thiz, const char*) {
724 thiz->mSelectedColumns.push_back(TableColumnType::RELEASED);
725 return OK;
726 }, "print the 'is released?' column\n(Y=released, empty=unreleased or unknown)"});
Yifan Honga6b93f02017-09-13 16:53:37 -0700727 mOptions.push_back({'t', "transport", no_argument, v++, [](ListCommand* thiz, const char*) {
728 thiz->mSelectedColumns.push_back(TableColumnType::TRANSPORT);
729 return OK;
730 }, "print the transport mode column"});
731 mOptions.push_back({'r', "arch", no_argument, v++, [](ListCommand* thiz, const char*) {
732 thiz->mSelectedColumns.push_back(TableColumnType::ARCH);
733 return OK;
734 }, "print the bitness column"});
Yifan Hongfee209d2017-09-14 18:23:38 -0700735 mOptions.push_back({'s', "hash", no_argument, v++, [](ListCommand* thiz, const char*) {
736 thiz->mSelectedColumns.push_back(TableColumnType::HASH);
737 return OK;
738 }, "print hash of the interface"});
Yifan Honga6b93f02017-09-13 16:53:37 -0700739 mOptions.push_back({'p', "pid", no_argument, v++, [](ListCommand* thiz, const char*) {
740 thiz->mSelectedColumns.push_back(TableColumnType::SERVER_PID);
741 return OK;
742 }, "print the server PID, or server cmdline if -m is set"});
743 mOptions.push_back({'a', "address", no_argument, v++, [](ListCommand* thiz, const char*) {
744 thiz->mSelectedColumns.push_back(TableColumnType::SERVER_ADDR);
745 return OK;
746 }, "print the server object address column"});
747 mOptions.push_back({'c', "clients", no_argument, v++, [](ListCommand* thiz, const char*) {
748 thiz->mSelectedColumns.push_back(TableColumnType::CLIENT_PIDS);
749 return OK;
750 }, "print the client PIDs, or client cmdlines if -m is set"});
751 mOptions.push_back({'e', "threads", no_argument, v++, [](ListCommand* thiz, const char*) {
752 thiz->mSelectedColumns.push_back(TableColumnType::THREADS);
753 return OK;
754 }, "print currently used/available threads\n(note, available threads created lazily)"});
755 mOptions.push_back({'m', "cmdline", no_argument, v++, [](ListCommand* thiz, const char*) {
756 thiz->mEnableCmdlines = true;
757 return OK;
758 }, "print cmdline instead of PIDs"});
759 mOptions.push_back({'d', "debug", optional_argument, v++, [](ListCommand* thiz, const char* arg) {
760 thiz->mEmitDebugInfo = true;
761 if (arg) thiz->mFileOutputPath = arg;
762 return OK;
763 }, "Emit debug info from\nIBase::debug with empty options. Cannot be used with --neat.\n"
764 "Writes to specified file if 'arg' is provided, otherwise stdout."});
765
766 // long options without short alternatives
767 mOptions.push_back({'\0', "init-vintf", no_argument, v++, [](ListCommand* thiz, const char* arg) {
768 thiz->mVintf = true;
Yifan Hongf31aa052018-02-02 15:17:51 -0800769 if (thiz->mVintfPartition == Partition::UNKNOWN)
770 thiz->mVintfPartition = Partition::VENDOR;
Yifan Honga6b93f02017-09-13 16:53:37 -0700771 if (arg) thiz->mFileOutputPath = arg;
772 return OK;
773 }, "form a skeleton HAL manifest to specified file,\nor stdout if no file specified."});
Yifan Hongf31aa052018-02-02 15:17:51 -0800774 mOptions.push_back({'\0', "init-vintf-partition", required_argument, v++, [](ListCommand* thiz, const char* arg) {
775 if (!arg) return USAGE;
776 thiz->mVintfPartition = android::procpartition::parsePartition(arg);
777 if (thiz->mVintfPartition == Partition::UNKNOWN) return USAGE;
778 return OK;
779 }, "Specify the partition of the HAL manifest\ngenerated by --init-vintf.\n"
780 "Valid values are 'system', 'vendor', and 'odm'. Default is 'vendor'."});
Yifan Honga6b93f02017-09-13 16:53:37 -0700781 mOptions.push_back({'\0', "sort", required_argument, v++, [](ListCommand* thiz, const char* arg) {
782 if (strcmp(arg, "interface") == 0 || strcmp(arg, "i") == 0) {
783 thiz->mSortColumn = TableEntry::sortByInterfaceName;
784 } else if (strcmp(arg, "pid") == 0 || strcmp(arg, "p") == 0) {
785 thiz->mSortColumn = TableEntry::sortByServerPid;
786 } else {
787 thiz->err() << "Unrecognized sorting column: " << arg << std::endl;
788 return USAGE;
789 }
790 return OK;
791 }, "sort by a column. 'arg' can be (i|interface) or (p|pid)."});
792 mOptions.push_back({'\0', "neat", no_argument, v++, [](ListCommand* thiz, const char*) {
793 thiz->mNeat = true;
794 return OK;
795 }, "output is machine parsable (no explanatory text).\nCannot be used with --debug."});
796}
797
798// Create 'longopts' argument to getopt_long. Caller is responsible for maintaining
799// the lifetime of "options" during the usage of the returned array.
800static std::unique_ptr<struct option[]> getLongOptions(
801 const ListCommand::RegisteredOptions& options,
802 int* longOptFlag) {
803 std::unique_ptr<struct option[]> ret{new struct option[options.size() + 1]};
804 int i = 0;
805 for (const auto& e : options) {
806 ret[i].name = e.longOption.c_str();
807 ret[i].has_arg = e.hasArg;
808 ret[i].flag = longOptFlag;
809 ret[i].val = e.val;
810
811 i++;
812 }
813 // getopt_long last option has all zeros
814 ret[i].name = NULL;
815 ret[i].has_arg = 0;
816 ret[i].flag = NULL;
817 ret[i].val = 0;
818
819 return ret;
820}
821
822// Create 'optstring' argument to getopt_long.
823static std::string getShortOptions(const ListCommand::RegisteredOptions& options) {
824 std::stringstream ss;
825 for (const auto& e : options) {
826 if (e.shortOption != '\0') {
827 ss << e.shortOption;
828 }
829 }
830 return ss.str();
831}
832
Yifan Honga8bedc62017-09-08 18:00:31 -0700833Status ListCommand::parseArgs(const Arg &arg) {
Yifan Hong443df792017-05-09 18:49:45 -0700834
Yifan Honga6b93f02017-09-13 16:53:37 -0700835 if (mOptions.empty()) {
836 registerAllOptions();
837 }
838 int longOptFlag;
839 std::unique_ptr<struct option[]> longOptions = getLongOptions(mOptions, &longOptFlag);
840 std::string shortOptions = getShortOptions(mOptions);
Yifan Hongd4a77e82017-09-06 19:40:24 -0700841
Yifan Honga8bedc62017-09-08 18:00:31 -0700842 // suppress output to std::err for unknown options
843 opterr = 0;
844
Yifan Hong443df792017-05-09 18:49:45 -0700845 int optionIndex;
846 int c;
847 // Lshal::parseArgs has set optind to the next option to parse
848 for (;;) {
Yifan Hong443df792017-05-09 18:49:45 -0700849 c = getopt_long(arg.argc, arg.argv,
Yifan Honga6b93f02017-09-13 16:53:37 -0700850 shortOptions.c_str(), longOptions.get(), &optionIndex);
Yifan Hong443df792017-05-09 18:49:45 -0700851 if (c == -1) {
852 break;
853 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700854 const RegisteredOption* found = nullptr;
855 if (c == 0) {
856 // see long option
857 for (const auto& e : mOptions) {
858 if (longOptFlag == e.val) found = &e;
Yifan Hong443df792017-05-09 18:49:45 -0700859 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700860 } else {
861 // see short option
862 for (const auto& e : mOptions) {
863 if (c == e.shortOption) found = &e;
864 }
Yifan Hong443df792017-05-09 18:49:45 -0700865 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700866
867 if (found == nullptr) {
868 // see unrecognized options
Yifan Honga8bedc62017-09-08 18:00:31 -0700869 err() << "unrecognized option `" << arg.argv[optind - 1] << "'" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700870 return USAGE;
871 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700872
873 Status status = found->op(this, optarg);
874 if (status != OK) {
875 return status;
876 }
Yifan Hong443df792017-05-09 18:49:45 -0700877 }
878 if (optind < arg.argc) {
879 // see non option
Yifan Honga8bedc62017-09-08 18:00:31 -0700880 err() << "unrecognized option `" << arg.argv[optind] << "'" << std::endl;
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700881 return USAGE;
882 }
883
884 if (mNeat && mEmitDebugInfo) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700885 err() << "Error: --neat should not be used with --debug." << std::endl;
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700886 return USAGE;
Yifan Hong443df792017-05-09 18:49:45 -0700887 }
888
Yifan Honga6b93f02017-09-13 16:53:37 -0700889 if (mSelectedColumns.empty()) {
Yifan Hongfee209d2017-09-14 18:23:38 -0700890 mSelectedColumns = {TableColumnType::RELEASED,
891 TableColumnType::INTERFACE_NAME, TableColumnType::THREADS,
Yifan Hong05494a52017-08-29 18:50:00 -0700892 TableColumnType::SERVER_PID, TableColumnType::CLIENT_PIDS};
Yifan Hong443df792017-05-09 18:49:45 -0700893 }
Yifan Hongd4a77e82017-09-06 19:40:24 -0700894
Yifan Honga6b93f02017-09-13 16:53:37 -0700895 if (mEnableCmdlines) {
896 for (size_t i = 0; i < mSelectedColumns.size(); ++i) {
897 if (mSelectedColumns[i] == TableColumnType::SERVER_PID) {
898 mSelectedColumns[i] = TableColumnType::SERVER_CMD;
Yifan Hongd4a77e82017-09-06 19:40:24 -0700899 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700900 if (mSelectedColumns[i] == TableColumnType::CLIENT_PIDS) {
901 mSelectedColumns[i] = TableColumnType::CLIENT_CMDS;
Yifan Hongd4a77e82017-09-06 19:40:24 -0700902 }
903 }
904 }
905
Yifan Honga6b93f02017-09-13 16:53:37 -0700906 forEachTable([this] (Table& table) {
907 table.setSelectedColumns(this->mSelectedColumns);
Yifan Hongd4a77e82017-09-06 19:40:24 -0700908 });
909
Yifan Hong443df792017-05-09 18:49:45 -0700910 return OK;
911}
912
Yifan Honga8bedc62017-09-08 18:00:31 -0700913Status ListCommand::main(const Arg &arg) {
914 Status status = parseArgs(arg);
Yifan Hong443df792017-05-09 18:49:45 -0700915 if (status != OK) {
916 return status;
917 }
918 status = fetch();
919 postprocess();
Yifan Hongca3b6602017-09-07 16:44:27 -0700920 status |= dump();
Yifan Hong443df792017-05-09 18:49:45 -0700921 return status;
922}
923
Yifan Honga6b93f02017-09-13 16:53:37 -0700924static std::vector<std::string> splitString(const std::string &s, char c) {
925 std::vector<std::string> components;
926
927 size_t startPos = 0;
928 size_t matchPos;
929 while ((matchPos = s.find(c, startPos)) != std::string::npos) {
930 components.push_back(s.substr(startPos, matchPos - startPos));
931 startPos = matchPos + 1;
932 }
933
934 if (startPos <= s.length()) {
935 components.push_back(s.substr(startPos));
936 }
937 return components;
938}
939
940const std::string& ListCommand::RegisteredOption::getHelpMessageForArgument() const {
941 static const std::string empty{};
942 static const std::string optional{"[=<arg>]"};
943 static const std::string required{"=<arg>"};
944
945 if (hasArg == optional_argument) {
946 return optional;
947 }
948 if (hasArg == required_argument) {
949 return required;
950 }
951 return empty;
952}
953
Yifan Honga8bedc62017-09-08 18:00:31 -0700954void ListCommand::usage() const {
955
Yifan Honga6b93f02017-09-13 16:53:37 -0700956 err() << "list:" << std::endl
957 << " lshal" << std::endl
958 << " lshal list" << std::endl
Yifan Hongfee209d2017-09-14 18:23:38 -0700959 << " List all hals with default ordering and columns (`lshal list -riepc`)" << std::endl
Yifan Honga6b93f02017-09-13 16:53:37 -0700960 << " lshal list [-h|--help]" << std::endl
961 << " -h, --help: Print help message for list (`lshal help list`)" << std::endl
962 << " lshal [list] [OPTIONS...]" << std::endl;
963 for (const auto& e : mOptions) {
964 if (e.help.empty()) {
965 continue;
966 }
967 err() << " ";
968 if (e.shortOption != '\0')
969 err() << "-" << e.shortOption << e.getHelpMessageForArgument();
970 if (e.shortOption != '\0' && !e.longOption.empty())
971 err() << ", ";
972 if (!e.longOption.empty())
973 err() << "--" << e.longOption << e.getHelpMessageForArgument();
974 err() << ": ";
975 std::vector<std::string> lines = splitString(e.help, '\n');
976 for (const auto& line : lines) {
977 if (&line != &lines.front())
978 err() << " ";
979 err() << line << std::endl;
980 }
981 }
Yifan Honga8bedc62017-09-08 18:00:31 -0700982}
983
Yifan Hong443df792017-05-09 18:49:45 -0700984} // namespace lshal
985} // namespace android
Yifan Hong05494a52017-08-29 18:50:00 -0700986