Fix race in FirewalldInit

It was possible that signalHandler won't start because connections is
not assigned.

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
Alexander Morozov 2015-05-01 13:35:54 -07:00
parent d3d6eed2b3
commit 112ff23e41

View file

@ -2,9 +2,10 @@ package iptables
import ( import (
"fmt" "fmt"
"strings"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/godbus/dbus" "github.com/godbus/dbus"
"strings"
) )
type IPV string type IPV string
@ -40,6 +41,9 @@ func FirewalldInit() {
if err != nil { if err != nil {
logrus.Errorf("Failed to connect to D-Bus system bus: %s", err) logrus.Errorf("Failed to connect to D-Bus system bus: %s", err)
} }
if connection != nil {
go signalHandler()
}
firewalldRunning = checkRunning() firewalldRunning = checkRunning()
} }
@ -76,20 +80,17 @@ func (c *Conn) initConnection() error {
c.signal = make(chan *dbus.Signal, 10) c.signal = make(chan *dbus.Signal, 10)
c.sysconn.Signal(c.signal) c.sysconn.Signal(c.signal)
go signalHandler()
return nil return nil
} }
func signalHandler() { func signalHandler() {
if connection != nil { for signal := range connection.signal {
for signal := range connection.signal { if strings.Contains(signal.Name, "NameOwnerChanged") {
if strings.Contains(signal.Name, "NameOwnerChanged") { firewalldRunning = checkRunning()
firewalldRunning = checkRunning() dbusConnectionChanged(signal.Body)
dbusConnectionChanged(signal.Body) } else if strings.Contains(signal.Name, "Reloaded") {
} else if strings.Contains(signal.Name, "Reloaded") { reloaded()
reloaded()
}
} }
} }
} }