OSDN Git Service

Support TASKSTATS_TYPE_NULL
authorColin Cross <ccross@android.com>
Wed, 16 Sep 2015 23:28:11 +0000 (16:28 -0700)
committerColin Cross <ccross@android.com>
Wed, 16 Sep 2015 23:34:29 +0000 (23:34 +0000)
Some kernels need to pad the netlink packet with an attribute of
type TASKSTATS_TYPE_NULL.

Bug: 24142514
Change-Id: I2745537bacf936325c52a03237ac04459c605271

iotop/taskstats.cpp

index 0c397dc..34e91e0 100644 (file)
@@ -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;