Improve IptablesRestoreController error logging.
- Switch tag from /system/bin/netd to IptablesController for
consistency.
- When a command fails, include the command that caused the error
in addition to the error itself.
Example output:
02-03 16:35:01.044 17129 17129 E IptablesRestoreController: iptables error:
02-03 16:35:01.044 17129 17129 E IptablesRestoreController: ------- COMMAND -------
02-03 16:35:01.044 17129 17129 E IptablesRestoreController: *filter
02-03 16:35:01.044 17129 17129 E IptablesRestoreController: :natctrl_tether_counters -
02-03 16:35:01.044 17129 17129 E IptablesRestoreController: badbadbadbad
02-03 16:35:01.044 17129 17129 E IptablesRestoreController: COMMIT
02-03 16:35:01.044 17129 17129 E IptablesRestoreController:
02-03 16:35:01.044 17129 17129 E IptablesRestoreController: ------- ERROR -------
02-03 16:35:01.044 17129 17129 E IptablesRestoreController: Bad argument `badbadbadbad'
02-03 16:35:01.044 17129 17129 E IptablesRestoreController: Error occurred at line: 112
02-03 16:35:01.044 17129 17129 E IptablesRestoreController: Try `ip6tables-restore -h' or 'ip6tables-restore --help' for more information.
02-03 16:35:01.044 17129 17129 E IptablesRestoreController: ----------------------
Test: added an invalid command to NatController, observed above log messages
Bug: 32323979
Change-Id: I0c1c37464f5b19c64d6e043aef8704285df4c508
diff --git a/server/IptablesRestoreController.h b/server/IptablesRestoreController.h
index f7ae292..a9b18e0 100644
--- a/server/IptablesRestoreController.h
+++ b/server/IptablesRestoreController.h
@@ -61,10 +61,12 @@
static std::string fixCommandString(const std::string& command);
- bool drainAndWaitForAck(const std::unique_ptr<IptablesProcess> &process, std::string *output);
+ static bool drainAndWaitForAck(const std::unique_ptr<IptablesProcess> &process,
+ const std::string& command,
+ std::string *output);
static void maybeLogStderr(const std::unique_ptr<IptablesProcess> &process,
- const char* buf, const ssize_t numBytes);
+ const std::string& command);
// Guards calls to execute().
std::mutex mLock;