summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2020-07-21 17:47:32 +0000
committerSteven Moreland <smoreland@google.com>2020-07-24 17:39:53 +0000
commit6c21855928047d4f89300dacdc3aa896f3515a27 (patch)
treee3c3bbf680a570950f707b5b3f9777d09bdd23a5
parent959cafd37e5c05e27d144b61c23524ff4c4e1dfe (diff)
downloadplatform_system_libhidl-android11-gsi.tar.gz
platform_system_libhidl-android11-gsi.tar.bz2
platform_system_libhidl-android11-gsi.zip
tryRegistrationImpl: better error checkingandroid11-gsi
ifstream is_open does not check for errors, so we use ifstream operator bool instead, and we use it more frequently than strictly needed. Also, the functions here are added to attribute noinline, so that stacktraces will be more useful. Test: boot and check names are fixed up in `ps -A -o comm` Bug: 161271113 Change-Id: Ia451fa1b06c49def0fe8b3a3558af83fff18ec96 Merged-In: Ia451fa1b06c49def0fe8b3a3558af83fff18ec96
-rw-r--r--transport/ServiceManagement.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp
index d7faa6db..7de5c787 100644
--- a/transport/ServiceManagement.cpp
+++ b/transport/ServiceManagement.cpp
@@ -87,7 +87,7 @@ static void waitForHwServiceManager() {
static std::string binaryName() {
std::ifstream ifs("/proc/self/cmdline");
std::string cmdline;
- if (!ifs.is_open()) {
+ if (!ifs) {
return "";
}
ifs >> cmdline;
@@ -106,7 +106,7 @@ static std::string packageWithoutVersion(const std::string& packageAndVersion) {
return packageAndVersion.substr(0, at);
}
-static void tryShortenProcessName(const std::string& descriptor) {
+__attribute__((noinline)) static void tryShortenProcessName(const std::string& descriptor) {
const static std::string kTasks = "/proc/self/task/";
// make sure that this binary name is in the same package
@@ -135,17 +135,17 @@ static void tryShortenProcessName(const std::string& descriptor) {
if (dp->d_name[0] == '.') continue;
std::fstream fs(kTasks + dp->d_name + "/comm");
- if (!fs.is_open()) {
+ if (!fs) {
ALOGI("Could not rename process, failed read comm for %s.", dp->d_name);
continue;
}
std::string oldComm;
- fs >> oldComm;
+ if (!(fs >> oldComm)) continue;
// don't rename if it already has an explicit name
if (base::StartsWith(descriptor, oldComm)) {
- fs.seekg(0, fs.beg);
+ if (!fs.seekg(0, fs.beg)) continue;
fs << newName;
}
}
@@ -157,7 +157,7 @@ namespace details {
* Returns the age of the current process by reading /proc/self/stat and comparing starttime to the
* current time. This is useful for measuring how long it took a HAL to register itself.
*/
-static long getProcessAgeMs() {
+__attribute__((noinline)) static long getProcessAgeMs() {
constexpr const int PROCFS_STAT_STARTTIME_INDEX = 21;
std::string content;
android::base::ReadFileToString("/proc/self/stat", &content, false);