Browse code

Add check for iptables xlock support Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)

Michael Crosby authored on 2014/05/24 06:18:50
Showing 1 changed files
... ...
@@ -20,6 +20,7 @@ const (
20 20
 var (
21 21
 	ErrIptablesNotFound = errors.New("Iptables not found")
22 22
 	nat                 = []string{"-t", "nat"}
23
+	supportsXlock       = false
23 24
 )
24 25
 
25 26
 type Chain struct {
... ...
@@ -27,6 +28,10 @@ type Chain struct {
27 27
 	Bridge string
28 28
 }
29 29
 
30
+func init() {
31
+	supportsXlock = exec.Command("iptables", "--wait", "-L", "-n").Run() == nil
32
+}
33
+
30 34
 func NewChain(name, bridge string) (*Chain, error) {
31 35
 	if output, err := Raw("-t", "nat", "-N", name); err != nil {
32 36
 		return nil, err
... ...
@@ -147,12 +152,19 @@ func Raw(args ...string) ([]byte, error) {
147 147
 	if err != nil {
148 148
 		return nil, ErrIptablesNotFound
149 149
 	}
150
+
151
+	if supportsXlock {
152
+		args = append([]string{"--wait"}, args...)
153
+	}
154
+
150 155
 	if os.Getenv("DEBUG") != "" {
151 156
 		fmt.Printf("[DEBUG] [iptables]: %s, %v\n", path, args)
152 157
 	}
153
-	output, err := exec.Command(path, append([]string{"--wait"}, args...)...).CombinedOutput()
158
+
159
+	output, err := exec.Command(path, args...).CombinedOutput()
154 160
 	if err != nil {
155 161
 		return nil, fmt.Errorf("iptables failed: iptables %v: %s (%s)", strings.Join(args, " "), output, err)
156 162
 	}
163
+
157 164
 	return output, err
158 165
 }