Skip to content

Commit 9ed442a

Browse files
author
Luca Bruno
authored
Merge pull request #393 from wzshiming/feat/connected
dbus: add Connected methods to check connections status
2 parents f5a75de + 18ce832 commit 9ed442a

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

dbus/dbus.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ func (c *Conn) Close() {
176176
c.sigconn.Close()
177177
}
178178

179+
// Connected returns whether conn is connected
180+
func (c *Conn) Connected() bool {
181+
return c.sysconn.Connected() && c.sigconn.Connected()
182+
}
183+
179184
// NewConnection establishes a connection to a bus using a caller-supplied function.
180185
// This allows connecting to remote buses through a user-supplied mechanism.
181186
// The supplied function may be called multiple times, and should return independent connections.

import1/dbus.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ func New() (*Conn, error) {
6464
return c, nil
6565
}
6666

67+
// Connected returns whether conn is connected
68+
func (c *Conn) Connected() bool {
69+
return c.conn.Connected()
70+
}
71+
6772
func (c *Conn) initConnection() error {
6873
var err error
6974
c.conn, err = dbus.SystemBusPrivate()

login1/dbus.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ func (c *Conn) Close() {
5858
}
5959
}
6060

61+
// Connected returns whether conn is connected
62+
func (c *Conn) Connected() bool {
63+
return c.conn.Connected()
64+
}
65+
6166
func (c *Conn) initConnection() error {
6267
var err error
6368
c.conn, err = dbus.SystemBusPrivate()

machine1/dbus.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ func (c *Conn) getPath(method string, args ...interface{}) (dbus.ObjectPath, err
112112
return path, nil
113113
}
114114

115+
// Connected returns whether conn is connected
116+
func (c *Conn) Connected() bool {
117+
return c.conn.Connected()
118+
}
119+
115120
// CreateMachine creates a new virtual machine or container with systemd-machined, generating a scope unit for it
116121
func (c *Conn) CreateMachine(name string, id []byte, service string, class string, pid int, root_directory string, scope_properties []sd_dbus.Property) error {
117122
return c.object.Call(dbusInterface+".CreateMachine", 0, name, id, service, class, uint32(pid), root_directory, scope_properties).Err

0 commit comments

Comments
 (0)