Skip to content

Commit

Permalink
Merge pull request #393 from wzshiming/feat/connected
Browse files Browse the repository at this point in the history
dbus: add Connected methods to check connections status
  • Loading branch information
Luca Bruno committed Jan 24, 2022
2 parents f5a75de + 18ce832 commit 9ed442a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dbus/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ func (c *Conn) Close() {
c.sigconn.Close()
}

// Connected returns whether conn is connected
func (c *Conn) Connected() bool {
return c.sysconn.Connected() && c.sigconn.Connected()
}

// NewConnection establishes a connection to a bus using a caller-supplied function.
// This allows connecting to remote buses through a user-supplied mechanism.
// The supplied function may be called multiple times, and should return independent connections.
Expand Down
5 changes: 5 additions & 0 deletions import1/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func New() (*Conn, error) {
return c, nil
}

// Connected returns whether conn is connected
func (c *Conn) Connected() bool {
return c.conn.Connected()
}

func (c *Conn) initConnection() error {
var err error
c.conn, err = dbus.SystemBusPrivate()
Expand Down
5 changes: 5 additions & 0 deletions login1/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func (c *Conn) Close() {
}
}

// Connected returns whether conn is connected
func (c *Conn) Connected() bool {
return c.conn.Connected()
}

func (c *Conn) initConnection() error {
var err error
c.conn, err = dbus.SystemBusPrivate()
Expand Down
5 changes: 5 additions & 0 deletions machine1/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ func (c *Conn) getPath(method string, args ...interface{}) (dbus.ObjectPath, err
return path, nil
}

// Connected returns whether conn is connected
func (c *Conn) Connected() bool {
return c.conn.Connected()
}

// CreateMachine creates a new virtual machine or container with systemd-machined, generating a scope unit for it
func (c *Conn) CreateMachine(name string, id []byte, service string, class string, pid int, root_directory string, scope_properties []sd_dbus.Property) error {
return c.object.Call(dbusInterface+".CreateMachine", 0, name, id, service, class, uint32(pid), root_directory, scope_properties).Err
Expand Down

0 comments on commit 9ed442a

Please sign in to comment.