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>
This commit is contained in:
parent
0921360133
commit
51bbcdb3c5
1 changed files with 12 additions and 23 deletions
|
@ -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 {
|
||||
c := &Conn{}
|
||||
|
||||
var err error
|
||||
c.sysconn, err = dbus.SystemBus()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Initialize D-Bus connection.
|
||||
func (c *Conn) initConnection() error {
|
||||
var err error
|
||||
|
||||
c.sysconn, err = dbus.SystemBus()
|
||||
if err != nil {
|
||||
return 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() {
|
||||
|
|
Loading…
Add table
Reference in a new issue