summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmds/dumpstate/DumpstateInternal.cpp24
-rw-r--r--cmds/dumpstate/dumpstate.cpp9
-rw-r--r--cmds/lshal/ListCommand.cpp10
3 files changed, 30 insertions, 13 deletions
diff --git a/cmds/dumpstate/DumpstateInternal.cpp b/cmds/dumpstate/DumpstateInternal.cpp
index 83e30a22ff..819d5b91f5 100644
--- a/cmds/dumpstate/DumpstateInternal.cpp
+++ b/cmds/dumpstate/DumpstateInternal.cpp
@@ -98,13 +98,25 @@ bool DropRootUser() {
capheader.version = _LINUX_CAPABILITY_VERSION_3;
capheader.pid = 0;
- capdata[CAP_TO_INDEX(CAP_SYSLOG)].permitted = CAP_TO_MASK(CAP_SYSLOG);
- capdata[CAP_TO_INDEX(CAP_SYSLOG)].effective = CAP_TO_MASK(CAP_SYSLOG);
- capdata[0].inheritable = 0;
- capdata[1].inheritable = 0;
+ if (capget(&capheader, &capdata[0]) != 0) {
+ MYLOGE("capget failed: %s\n", strerror(errno));
+ return false;
+ }
+
+ const uint32_t cap_syslog_mask = CAP_TO_MASK(CAP_SYSLOG);
+ const uint32_t cap_syslog_index = CAP_TO_INDEX(CAP_SYSLOG);
+ bool has_cap_syslog = (capdata[cap_syslog_index].effective & cap_syslog_mask) != 0;
+
+ memset(&capdata, 0, sizeof(capdata));
+ if (has_cap_syslog) {
+ // Only attempt to keep CAP_SYSLOG if it was present to begin with.
+ capdata[cap_syslog_index].permitted |= cap_syslog_mask;
+ capdata[cap_syslog_index].effective |= cap_syslog_mask;
+ }
- if (capset(&capheader, &capdata[0]) < 0) {
- MYLOGE("capset failed: %s\n", strerror(errno));
+ if (capset(&capheader, &capdata[0]) != 0) {
+ MYLOGE("capset({%#x, %#x}) failed: %s\n", capdata[0].effective,
+ capdata[1].effective, strerror(errno));
return false;
}
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 371533c4db..10f252fb7e 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -176,6 +176,11 @@ static std::vector<DumpData>* GetDumpFds(const std::string& dir_path,
std::unique_ptr<std::vector<DumpData>> dump_data(new std::vector<DumpData>());
std::unique_ptr<DIR, decltype(&closedir)> dump_dir(opendir(dir_path.c_str()), closedir);
+ if (dump_dir == nullptr) {
+ MYLOGW("Unable to open directory %s: %s\n", dir_path.c_str(), strerror(errno));
+ return dump_data.release();
+ }
+
struct dirent* entry = nullptr;
while ((entry = readdir(dump_dir.get()))) {
if (entry->d_type != DT_REG) {
@@ -191,13 +196,13 @@ static std::vector<DumpData>* GetDumpFds(const std::string& dir_path,
android::base::unique_fd fd(
TEMP_FAILURE_RETRY(open(abs_path.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK)));
if (fd == -1) {
- MYLOGW("Unable to open dump file: %s %s\n", abs_path.c_str(), strerror(errno));
+ MYLOGW("Unable to open dump file %s: %s\n", abs_path.c_str(), strerror(errno));
break;
}
struct stat st = {};
if (fstat(fd, &st) == -1) {
- MYLOGW("Unable to stat dump file: %s %s\n", abs_path.c_str(), strerror(errno));
+ MYLOGW("Unable to stat dump file %s: %s\n", abs_path.c_str(), strerror(errno));
continue;
}
diff --git a/cmds/lshal/ListCommand.cpp b/cmds/lshal/ListCommand.cpp
index 67110c49db..39fddc5a33 100644
--- a/cmds/lshal/ListCommand.cpp
+++ b/cmds/lshal/ListCommand.cpp
@@ -395,11 +395,11 @@ void ListCommand::dumpVintf(const NullableOStream<std::ostream>& out) const {
interfaces[interfaceName].instances.insert(instanceName);
}
if (!manifest.add(vintf::ManifestHal{
- .format = vintf::HalFormat::HIDL,
- .name = fqName.package(),
- .versions = {version},
- .transportArch = {transport, arch},
- .interfaces = interfaces})) {
+ vintf::HalFormat::HIDL,
+ std::string{fqName.package()},
+ {version},
+ {transport, arch},
+ std::move(interfaces)})) {
err() << "Warning: cannot add hal '" << fqInstanceName << "'" << std::endl;
}
}