From 112ff23e41bf51647542b2ce30c75945afb7b6aa Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Fri, 1 May 2015 13:35:54 -0700 Subject: [PATCH] Fix race in FirewalldInit It was possible that signalHandler won't start because connections is not assigned. Signed-off-by: Alexander Morozov --- iptables/firewalld.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/iptables/firewalld.go b/iptables/firewalld.go index 3087794..1c0cddb 100644 --- a/iptables/firewalld.go +++ b/iptables/firewalld.go @@ -2,9 +2,10 @@ package iptables import ( "fmt" + "strings" + "github.com/Sirupsen/logrus" "github.com/godbus/dbus" - "strings" ) type IPV string @@ -40,6 +41,9 @@ func FirewalldInit() { if err != nil { logrus.Errorf("Failed to connect to D-Bus system bus: %s", err) } + if connection != nil { + go signalHandler() + } firewalldRunning = checkRunning() } @@ -76,20 +80,17 @@ func (c *Conn) initConnection() error { c.signal = make(chan *dbus.Signal, 10) c.sysconn.Signal(c.signal) - go signalHandler() return nil } func signalHandler() { - if connection != nil { - for signal := range connection.signal { - if strings.Contains(signal.Name, "NameOwnerChanged") { - firewalldRunning = checkRunning() - dbusConnectionChanged(signal.Body) - } else if strings.Contains(signal.Name, "Reloaded") { - reloaded() - } + for signal := range connection.signal { + if strings.Contains(signal.Name, "NameOwnerChanged") { + firewalldRunning = checkRunning() + dbusConnectionChanged(signal.Body) + } else if strings.Contains(signal.Name, "Reloaded") { + reloaded() } } }