Prechádzať zdrojové kódy

libnetwork/iptables: merge Conn.initConnection into newConnection

initConnection was effectively just part of the constructor; ot was not
used elsewhere. Merge the two functions to simplify things a bit.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 rokov pred
rodič
commit
51bbcdb3c5
1 zmenil súbory, kde vykonal 9 pridanie a 20 odobranie
  1. 9 20
      libnetwork/iptables/firewalld.go

+ 9 - 20
libnetwork/iptables/firewalld.go

@@ -87,40 +87,29 @@ func FirewalldInit() error {
 	return nil
 }
 
-// New() establishes a connection to the system bus.
+// newConnection establishes a connection to the system bus.
 func newConnection() (*Conn, error) {
-	c := new(Conn)
-	if err := c.initConnection(); err != nil {
-		return nil, err
-	}
-
-	return c, nil
-}
+	c := &Conn{}
 
-// Initialize D-Bus connection.
-func (c *Conn) initConnection() error {
 	var err error
-
 	c.sysconn, err = dbus.SystemBus()
 	if err != nil {
-		return err
+		return nil, err
 	}
 
 	// This never fails, even if the service is not running atm.
-	c.sysObj = c.sysconn.Object(dbusInterface, dbus.ObjectPath(dbusPath))
-	c.sysConfObj = c.sysconn.Object(dbusInterface, dbus.ObjectPath(dbusConfigPath))
-	rule := fmt.Sprintf("type='signal',path='%s',interface='%s',sender='%s',member='Reloaded'",
-		dbusPath, dbusInterface, dbusInterface)
+	c.sysObj = c.sysconn.Object(dbusInterface, dbusPath)
+	c.sysConfObj = c.sysconn.Object(dbusInterface, dbusConfigPath)
+
+	rule := fmt.Sprintf("type='signal',path='%s',interface='%s',sender='%s',member='Reloaded'", dbusPath, dbusInterface, dbusInterface)
 	c.sysconn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule)
 
-	rule = fmt.Sprintf("type='signal',interface='org.freedesktop.DBus',member='NameOwnerChanged',path='/org/freedesktop/DBus',sender='org.freedesktop.DBus',arg0='%s'",
-		dbusInterface)
+	rule = fmt.Sprintf("type='signal',interface='org.freedesktop.DBus',member='NameOwnerChanged',path='/org/freedesktop/DBus',sender='org.freedesktop.DBus',arg0='%s'", dbusInterface)
 	c.sysconn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule)
 
 	c.signal = make(chan *dbus.Signal, 10)
 	c.sysconn.Signal(c.signal)
-
-	return nil
+	return c, nil
 }
 
 func signalHandler() {