netd: BandwidthController: return extra info on gettetherstats failure
Use the error message string to report the raw parsed data in case of
failure.
Bug:5543131
Change-Id: If9f3bcea09fd3ab8a506955d8153b3430bfd239c
diff --git a/BandwidthController.cpp b/BandwidthController.cpp
index bb088a9..09601af 100644
--- a/BandwidthController.cpp
+++ b/BandwidthController.cpp
@@ -920,7 +920,8 @@
* 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 @@
&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 @@
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 @@
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. */
diff --git a/BandwidthController.h b/BandwidthController.h
index 861c63e..1aa19e5 100644
--- a/BandwidthController.h
+++ b/BandwidthController.h
@@ -75,7 +75,7 @@
* 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 @@
/*
* 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);
/*------------------*/
diff --git a/CommandListener.cpp b/CommandListener.cpp
index 40328ee..d1c9ebd 100644
--- a/CommandListener.cpp
+++ b/CommandListener.cpp
@@ -1154,6 +1154,7 @@
}
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 @@
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;
}