diff options
-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); |