diff options
author | Colin Cross <ccross@android.com> | 2015-09-16 16:28:11 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2015-09-16 23:34:29 +0000 |
commit | 1d0defec2db01765acc8233c9bc3ddd344f423e7 (patch) | |
tree | 8db4599d38710e8bfe189fdf94d01eb44a190d59 | |
parent | 12f454e24a518d81fe42043b7142582b81694363 (diff) | |
download | extras-1d0defec2db01765acc8233c9bc3ddd344f423e7.tar.gz |
Support TASKSTATS_TYPE_NULL
Some kernels need to pad the netlink packet with an attribute of
type TASKSTATS_TYPE_NULL.
Bug: 24142514
Change-Id: I2745537bacf936325c52a03237ac04459c605271
-rw-r--r-- | iotop/taskstats.cpp | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/iotop/taskstats.cpp b/iotop/taskstats.cpp index 0c397dc5..34e91e03 100644 --- a/iotop/taskstats.cpp +++ b/iotop/taskstats.cpp @@ -89,22 +89,32 @@ static int ParseTaskStats(nl_msg* msg, void* arg) { TaskStatsRequest* taskstats_request = static_cast<TaskStatsRequest*>(arg); genlmsghdr* gnlh = static_cast<genlmsghdr*>(nlmsg_data(nlmsg_hdr(msg))); nlattr* attr = genlmsg_attrdata(gnlh, 0); + int remaining = genlmsg_attrlen(gnlh, 0); - switch (nla_type(attr)) { - case TASKSTATS_TYPE_AGGR_PID: - case TASKSTATS_TYPE_AGGR_TGID: - nlattr* nested_attr = static_cast<nlattr*>(nla_data(attr)); - taskstats stats; - pid_t ret; - - ret = ParseAggregateTaskStats(nested_attr, nla_len(attr), &stats); - if (ret < 0) { - LOG(ERROR) << "Bad AGGR_PID contents"; - } else if (ret == taskstats_request->requested_pid) { - taskstats_request->stats = stats; - } else { - LOG(WARNING) << "got taskstats for unexpected pid " << ret << - " (expected " << taskstats_request->requested_pid << ", continuing..."; + nla_for_each_attr(attr, attr, remaining, remaining) { + switch (nla_type(attr)) { + case TASKSTATS_TYPE_AGGR_PID: + case TASKSTATS_TYPE_AGGR_TGID: + { + nlattr* nested_attr = static_cast<nlattr*>(nla_data(attr)); + taskstats stats; + pid_t ret; + + ret = ParseAggregateTaskStats(nested_attr, nla_len(attr), &stats); + if (ret < 0) { + LOG(ERROR) << "Bad AGGR_PID contents"; + } else if (ret == taskstats_request->requested_pid) { + taskstats_request->stats = stats; + } else { + LOG(WARNING) << "got taskstats for unexpected pid " << ret << + " (expected " << taskstats_request->requested_pid << ", continuing..."; + } + break; + } + case TASKSTATS_TYPE_NULL: + break; + default: + LOG(ERROR) << "unexpected attribute in taskstats"; } } return NL_OK; |