nwfilter: improved logging during driver initialization

Improve the logging during driver initialization when testing the command
line tools.
This commit is contained in:
Stefan Berger 2012-02-16 18:56:39 -05:00 committed by Stefan Berger
parent 18942b9bea
commit 1c310eaf30

View File

@ -4036,6 +4036,7 @@ static int
ebiptablesDriverInit(bool privileged) ebiptablesDriverInit(bool privileged)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
char *errmsg = NULL;
if (!privileged) if (!privileged)
return 0; return 0;
@ -4056,8 +4057,13 @@ ebiptablesDriverInit(bool privileged)
"%s", "%s",
CMD_STOPONERR(1)); CMD_STOPONERR(1));
if (ebiptablesExecCLI(&buf, NULL, NULL) < 0) if (ebiptablesExecCLI(&buf, NULL, &errmsg) < 0) {
VIR_FREE(ebtables_cmd_path); VIR_FREE(ebtables_cmd_path);
VIR_ERROR(_("Testing of ebtables command failed: %s"),
errmsg);
}
} else {
VIR_WARN("Could not find 'ebtables' executable");
} }
iptables_cmd_path = virFindFileInPath("iptables"); iptables_cmd_path = virFindFileInPath("iptables");
@ -4070,8 +4076,13 @@ ebiptablesDriverInit(bool privileged)
"%s", "%s",
CMD_STOPONERR(1)); CMD_STOPONERR(1));
if (ebiptablesExecCLI(&buf, NULL, NULL) < 0) if (ebiptablesExecCLI(&buf, NULL, &errmsg) < 0) {
VIR_FREE(iptables_cmd_path); VIR_FREE(iptables_cmd_path);
VIR_ERROR(_("Testing of iptables command failed: %s"),
errmsg);
}
} else {
VIR_WARN("Could not find 'iptables' executable");
} }
ip6tables_cmd_path = virFindFileInPath("ip6tables"); ip6tables_cmd_path = virFindFileInPath("ip6tables");
@ -4084,25 +4095,28 @@ ebiptablesDriverInit(bool privileged)
"%s", "%s",
CMD_STOPONERR(1)); CMD_STOPONERR(1));
if (ebiptablesExecCLI(&buf, NULL, NULL) < 0) if (ebiptablesExecCLI(&buf, NULL, &errmsg) < 0) {
VIR_FREE(ip6tables_cmd_path); VIR_FREE(ip6tables_cmd_path);
VIR_ERROR(_("Testing of ip6tables command failed: %s"),
errmsg);
}
} else {
VIR_WARN("Could not find 'ip6tables' executable");
} }
/* ip(6)tables support needs gawk & grep, ebtables doesn't */ /* ip(6)tables support needs gawk & grep, ebtables doesn't */
if ((iptables_cmd_path != NULL || ip6tables_cmd_path != NULL) && if ((iptables_cmd_path != NULL || ip6tables_cmd_path != NULL) &&
(!grep_cmd_path || !gawk_cmd_path)) { (!grep_cmd_path || !gawk_cmd_path)) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", VIR_ERROR(_("essential tools to support ip(6)tables "
_("essential tools to support ip(6)tables " "firewalls could not be located"));
"firewalls could not be located"));
VIR_FREE(iptables_cmd_path); VIR_FREE(iptables_cmd_path);
VIR_FREE(ip6tables_cmd_path); VIR_FREE(ip6tables_cmd_path);
} }
VIR_FREE(errmsg);
if (!ebtables_cmd_path && !iptables_cmd_path && !ip6tables_cmd_path) { if (!ebtables_cmd_path && !iptables_cmd_path && !ip6tables_cmd_path) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", VIR_ERROR(_("firewall tools were not found or cannot be used"));
_("firewall tools were not found or "
"cannot be used"));
ebiptablesDriverShutdown(); ebiptablesDriverShutdown();
return -ENOTSUP; return -ENOTSUP;
} }