OSDN Git Service

netd: BandwidthController: return extra info on gettetherstats failure
authorJP Abgrall <jpa@google.com>
Sat, 12 Nov 2011 04:36:16 +0000 (20:36 -0800)
committerJP Abgrall <jpa@google.com>
Thu, 17 Nov 2011 21:07:40 +0000 (13:07 -0800)
Use the error message string to report the raw parsed data in case of
failure.

Bug:5543131
Change-Id: If9f3bcea09fd3ab8a506955d8153b3430bfd239c

BandwidthController.cpp
BandwidthController.h
CommandListener.cpp

index bb088a9..09601af 100644 (file)
@@ -920,7 +920,8 @@ int BandwidthController::removeCostlyAlert(const char *costName, int64_t *alertB
  *        0        0 ACCEPT     all  --  wlan0  rmnet0  0.0.0.0/0            0.0.0.0/0
  *
  */
-int BandwidthController::parseForwardChainStats(TetherStats &stats, FILE *fp) {
+int BandwidthController::parseForwardChainStats(TetherStats &stats, FILE *fp,
+                                                std::string &extraProcessingInfo) {
     int res;
     char lineBuffer[MAX_IPT_OUTPUT_LINE_LEN];
     char iface0[MAX_IPT_OUTPUT_LINE_LEN];
@@ -937,6 +938,8 @@ int BandwidthController::parseForwardChainStats(TetherStats &stats, FILE *fp) {
                 &packets, &bytes, iface0, iface1, rest);
         ALOGV("parse res=%d iface0=<%s> iface1=<%s> pkts=%lld bytes=%lld rest=<%s> orig line=<%s>", res,
              iface0, iface1, packets, bytes, rest, buffPtr);
+        extraProcessingInfo += buffPtr;
+
         if (res != 5) {
             continue;
         }
@@ -962,7 +965,7 @@ char *BandwidthController::TetherStats::getStatsLine(void) {
     return msg;
 }
 
-int BandwidthController::getTetherStats(TetherStats &stats) {
+int BandwidthController::getTetherStats(TetherStats &stats, std::string &extraProcessingInfo) {
     int res;
     std::string fullCmd;
     FILE *iptOutput;
@@ -985,9 +988,10 @@ int BandwidthController::getTetherStats(TetherStats &stats) {
     iptOutput = popen(fullCmd.c_str(), "r");
     if (!iptOutput) {
             LOGE("Failed to run %s err=%s", fullCmd.c_str(), strerror(errno));
+            extraProcessingInfo += "Failed to run iptables.";
         return -1;
     }
-    res = parseForwardChainStats(stats, iptOutput);
+    res = parseForwardChainStats(stats, iptOutput, extraProcessingInfo);
     pclose(iptOutput);
 
     /* Currently NatController doesn't do ipv6 tethering, so we are done. */
index 861c63e..1aa19e5 100644 (file)
@@ -75,7 +75,7 @@ public:
      * stats should have ifaceIn and ifaceOut initialized.
      * Byte counts should be left to the default (-1).
      */
-    int getTetherStats(TetherStats &stats);
+    int getTetherStats(TetherStats &stats, std::string &extraProcessingInfo);
 
 protected:
     class QuotaInfo {
@@ -122,8 +122,10 @@ protected:
     /*
      * stats should have ifaceIn and ifaceOut initialized.
      * fp should be a file to the FORWARD rules of iptables.
+     * extraProcessingInfo: contains raw parsed data, and error info.
      */
-    static int parseForwardChainStats(TetherStats &stats, FILE *fp);
+    static int parseForwardChainStats(TetherStats &stats, FILE *fp,
+                                     std::string &extraProcessingInfo);
 
     /*------------------*/
 
index 40328ee..d1c9ebd 100644 (file)
@@ -1154,6 +1154,7 @@ int CommandListener::BandwidthControlCmd::runCommand(SocketClient *cli, int argc
     }
     if (!strcmp(argv[1], "gettetherstats") || !strcmp(argv[1], "gts")) {
         BandwidthController::TetherStats tetherStats;
+        std::string extraProcessingInfo = "";
         if (argc != 4) {
             sendGenericSyntaxError(cli, "gettetherstats <interface0> <interface1>");
             return 0;
@@ -1161,9 +1162,10 @@ int CommandListener::BandwidthControlCmd::runCommand(SocketClient *cli, int argc
 
         tetherStats.ifaceIn = argv[2];
         tetherStats.ifaceOut = argv[3];
-        int rc = sBandwidthCtrl->getTetherStats(tetherStats);
+        int rc = sBandwidthCtrl->getTetherStats(tetherStats, extraProcessingInfo);
         if (rc) {
-            sendGenericOpFailed(cli, "Failed to get tethering stats");
+                extraProcessingInfo.insert(0, "Failed to get tethering stats.\n");
+                sendGenericOpFailed(cli, extraProcessingInfo.c_str());
             return 0;
         }