diff options
author | Colin Cross <ccross@android.com> | 2017-10-20 10:17:35 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2017-10-20 10:17:35 -0700 |
commit | 5dff53fdd56f41414c9cef2ed3f5e904f9307f49 (patch) | |
tree | 8a8ded3e7b1e223adf62b04bf3d674af3a49bea0 /iotop | |
parent | 0bc040a8cbe7faf96138afab80119f2a9492fee0 (diff) | |
download | extras-5dff53fdd56f41414c9cef2ed3f5e904f9307f49.tar.gz |
Don't abort on errors
LOG(FATAL) triggers an abort which produces an unhelpful stack
trace in logcat. Use LOG(ERROR) and propagate the failure to
a normal task exit.
Bug: 68040531
Test: manual
Change-Id: Iaaa0c3406c637d985065cbe58a8a160b72e1f6da
Diffstat (limited to 'iotop')
-rw-r--r-- | iotop/iotop.cpp | 11 | ||||
-rw-r--r-- | iotop/taskstats.cpp | 9 |
2 files changed, 13 insertions, 7 deletions
diff --git a/iotop/iotop.cpp b/iotop/iotop.cpp index e2582e85..a292bcfe 100644 --- a/iotop/iotop.cpp +++ b/iotop/iotop.cpp @@ -144,7 +144,7 @@ int main(int argc, char* argv[]) { if (sorter == nullptr) { LOG(ERROR) << "Invalid sort column \"" << optarg << "\""; usage(argv[0]); - return(EXIT_FAILURE); + return EXIT_FAILURE; } break; } @@ -153,7 +153,7 @@ int main(int argc, char* argv[]) { break; case '?': usage(argv[0]); - return(EXIT_FAILURE); + return EXIT_FAILURE; default: abort(); } @@ -162,7 +162,9 @@ int main(int argc, char* argv[]) { std::map<pid_t, std::vector<pid_t>> tgid_map; TaskstatsSocket taskstats_socket; - taskstats_socket.Open(); + if (!taskstats_socket.Open()) { + return EXIT_FAILURE; + } std::unordered_map<pid_t, TaskStatistics> pid_stats; std::unordered_map<pid_t, TaskStatistics> tgid_stats; @@ -174,7 +176,8 @@ int main(int argc, char* argv[]) { while (true) { stats.clear(); if (!TaskList::Scan(tgid_map)) { - LOG(FATAL) << "failed to scan tasks"; + LOG(ERROR) << "failed to scan tasks"; + return EXIT_FAILURE; } for (auto& tgid_it : tgid_map) { pid_t tgid = tgid_it.first; diff --git a/iotop/taskstats.cpp b/iotop/taskstats.cpp index 60c933d1..d8027572 100644 --- a/iotop/taskstats.cpp +++ b/iotop/taskstats.cpp @@ -32,17 +32,20 @@ bool TaskstatsSocket::Open() { std::unique_ptr<nl_sock, decltype(&nl_socket_free)> nl( nl_socket_alloc(), nl_socket_free); if (!nl.get()) { - LOG(FATAL) << "Failed to allocate netlink socket"; + LOG(ERROR) << "Failed to allocate netlink socket"; + return false; } int ret = genl_connect(nl.get()); if (ret < 0) { - LOG(FATAL) << nl_geterror(ret) << std::endl << "Unable to open netlink socket (are you root?)"; + LOG(ERROR) << nl_geterror(ret) << std::endl << "Unable to open netlink socket (are you root?)"; + return false; } int family_id = genl_ctrl_resolve(nl.get(), TASKSTATS_GENL_NAME); if (family_id < 0) { - LOG(FATAL) << nl_geterror(family_id) << std::endl << "Unable to determine taskstats family id (does your kernel support taskstats?)"; + LOG(ERROR) << nl_geterror(family_id) << std::endl << "Unable to determine taskstats family id (does your kernel support taskstats?)"; + return false; } nl_ = std::move(nl); |