Browse Source

Adds wait option to iptables rules commands

This should prevent commands from failing if
they are unable to acquire the xtables lock.
Also gofmt'd iptables.go

Signed-off-by: bobby abbott <ttobbaybbob@gmail.com>
bobby abbott 10 years ago
parent
commit
13bf7998df
1 changed files with 7 additions and 6 deletions
  1. 7 6
      iptables/iptables.go

+ 7 - 6
iptables/iptables.go

@@ -53,7 +53,7 @@ func New() (*IPTables, error) {
 }
 
 // Exists checks if given rulespec in specified table/chain exists
-func (ipt *IPTables) Exists(table, chain string, rulespec...string) (bool, error) {
+func (ipt *IPTables) Exists(table, chain string, rulespec ...string) (bool, error) {
 	checkPresent, err := getIptablesHasCheckCommand()
 	if err != nil {
 		log.Printf("Error checking iptables version, assuming version at least 1.4.11: %v", err)
@@ -114,8 +114,8 @@ func (ipt *IPTables) Delete(table, chain string, rulespec ...string) error {
 func (ipt *IPTables) List(table, chain string) ([]string, error) {
 	var stdout, stderr bytes.Buffer
 	cmd := exec.Cmd{
-		Path: ipt.path,
-		Args: []string{ipt.path, "-t", table, "-S", chain},
+		Path:   ipt.path,
+		Args:   []string{ipt.path, "-t", table, "-S", chain},
 		Stdout: &stdout,
 		Stderr: &stderr,
 	}
@@ -158,11 +158,12 @@ func (ipt *IPTables) DeleteChain(table, chain string) error {
 	return ipt.run("-t", table, "-X", chain)
 }
 
-func (ipt *IPTables) run(args... string) error {
+func (ipt *IPTables) run(args ...string) error {
 	var stderr bytes.Buffer
+	args = append([]string{"--wait"}, args...)
 	cmd := exec.Cmd{
-		Path: ipt.path,
-		Args: append([]string{ipt.path}, args...),
+		Path:   ipt.path,
+		Args:   append([]string{ipt.path}, args...),
 		Stderr: &stderr,
 	}