Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 committed Aug 31, 2022
1 parent aa064ac commit 5020cdb
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions login1/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

const (
dbusDest = "org.freedesktop.login1"
dbusInterface = "org.freedesktop.login1.Manager"
dbusManagerInterface = "org.freedesktop.login1.Manager"
dbusSessionInterface = "org.freedesktop.login1.Session"
dbusUserInterface = "org.freedesktop.login1.User"
dbusPath = "/org/freedesktop/login1"
Expand Down Expand Up @@ -168,7 +168,7 @@ func userFromInterfaces(user []interface{}) (*User, error) {
// GetActiveSession may be used to get the session object path for the current active session
func (c *Conn) GetActiveSession() (dbus.ObjectPath, error) {
var seat0Path dbus.ObjectPath
if err := c.object.Call(dbusInterface+".GetSeat", 0, "seat0").Store(&seat0Path); err != nil {
if err := c.object.Call(dbusManagerInterface+".GetSeat", 0, "seat0").Store(&seat0Path); err != nil {
return "", err
}

Expand Down Expand Up @@ -244,7 +244,7 @@ func (c *Conn) GetSessionDisplay(sessionPath dbus.ObjectPath) (string, error) {
// GetSession may be used to get the session object path for the session with the specified ID.
func (c *Conn) GetSession(id string) (dbus.ObjectPath, error) {
var out interface{}
if err := c.object.Call(dbusInterface+".GetSession", 0, id).Store(&out); err != nil {
if err := c.object.Call(dbusManagerInterface+".GetSession", 0, id).Store(&out); err != nil {
return "", err
}

Expand All @@ -259,7 +259,7 @@ func (c *Conn) GetSession(id string) (dbus.ObjectPath, error) {
// ListSessions returns an array with all current sessions.
func (c *Conn) ListSessions() ([]Session, error) {
out := [][]interface{}{}
if err := c.object.Call(dbusInterface+".ListSessions", 0).Store(&out); err != nil {
if err := c.object.Call(dbusManagerInterface+".ListSessions", 0).Store(&out); err != nil {
return nil, err
}

Expand All @@ -277,7 +277,7 @@ func (c *Conn) ListSessions() ([]Session, error) {
// ListUsers returns an array with all currently logged in users.
func (c *Conn) ListUsers() ([]User, error) {
out := [][]interface{}{}
if err := c.object.Call(dbusInterface+".ListUsers", 0).Store(&out); err != nil {
if err := c.object.Call(dbusManagerInterface+".ListUsers", 0).Store(&out); err != nil {
return nil, err
}

Expand All @@ -298,7 +298,7 @@ func (c *Conn) GetSessionPropertiesContext(ctx context.Context, sessionPath dbus
}

// GetSessionPropertyContext takes a session path and a property name and returns the property value.
func (c *Conn) GetSessionPropertyContext(ctx context.Context, sessionPath dbus.ObjectPath, property string) (dbus.Variant, error) {
func (c *Conn) GetSessionPropertyContext(ctx context.Context, sessionPath dbus.ObjectPath, property string) (*dbus.Variant, error) {
return c.getProperty(ctx, sessionPath, dbusSessionInterface, property)
}

Expand All @@ -308,40 +308,40 @@ func (c *Conn) GetUserPropertiesContext(ctx context.Context, userPath dbus.Objec
}

// GetUserPropertyContext takes a user path and a property name and returns the property value.
func (c *Conn) GetUserPropertyContext(ctx context.Context, userPath dbus.ObjectPath, property string) (dbus.Variant, error) {
func (c *Conn) GetUserPropertyContext(ctx context.Context, userPath dbus.ObjectPath, property string) (*dbus.Variant, error) {
return c.getProperty(ctx, userPath, dbusUserInterface, property)
}

// LockSession asks the session with the specified ID to activate the screen lock.
func (c *Conn) LockSession(id string) {
c.object.Call(dbusInterface+".LockSession", 0, id)
c.object.Call(dbusManagerInterface+".LockSession", 0, id)
}

// LockSessions asks all sessions to activate the screen locks. This may be used to lock any access to the machine in one action.
func (c *Conn) LockSessions() {
c.object.Call(dbusInterface+".LockSessions", 0)
c.object.Call(dbusManagerInterface+".LockSessions", 0)
}

// TerminateSession forcibly terminate one specific session.
func (c *Conn) TerminateSession(id string) {
c.object.Call(dbusInterface+".TerminateSession", 0, id)
c.object.Call(dbusManagerInterface+".TerminateSession", 0, id)
}

// TerminateUser forcibly terminates all processes of a user.
func (c *Conn) TerminateUser(uid uint32) {
c.object.Call(dbusInterface+".TerminateUser", 0, uid)
c.object.Call(dbusManagerInterface+".TerminateUser", 0, uid)
}

// Reboot asks logind for a reboot optionally asking for auth.
func (c *Conn) Reboot(askForAuth bool) {
c.object.Call(dbusInterface+".Reboot", 0, askForAuth)
c.object.Call(dbusManagerInterface+".Reboot", 0, askForAuth)
}

// Inhibit takes inhibition lock in logind.
func (c *Conn) Inhibit(what, who, why, mode string) (*os.File, error) {
var fd dbus.UnixFD

err := c.object.Call(dbusInterface+".Inhibit", 0, what, who, why, mode).Store(&fd)
err := c.object.Call(dbusManagerInterface+".Inhibit", 0, what, who, why, mode).Store(&fd)
if err != nil {
return nil, err
}
Expand All @@ -362,7 +362,7 @@ func (c *Conn) Subscribe(members ...string) chan *dbus.Signal {

// PowerOff asks logind for a power off optionally asking for auth.
func (c *Conn) PowerOff(askForAuth bool) {
c.object.Call(dbusInterface+".PowerOff", 0, askForAuth)
c.object.Call(dbusManagerInterface+".PowerOff", 0, askForAuth)
}

func (c *Conn) getProperties(ctx context.Context, path dbus.ObjectPath, dbusInterface string) (map[string]dbus.Variant, error) {
Expand All @@ -381,18 +381,18 @@ func (c *Conn) getProperties(ctx context.Context, path dbus.ObjectPath, dbusInte
return props, nil
}

func (c *Conn) getProperty(ctx context.Context, path dbus.ObjectPath, dbusInterface, property string) (dbus.Variant, error) {
func (c *Conn) getProperty(ctx context.Context, path dbus.ObjectPath, dbusInterface, property string) (*dbus.Variant, error) {
if !path.IsValid() {
return dbus.Variant{}, fmt.Errorf("invalid object path (%s)", path)
return nil, fmt.Errorf("invalid object path (%s)", path)
}

obj := c.conn.Object(dbusDest, path)

var prop dbus.Variant
err := obj.CallWithContext(ctx, "org.freedesktop.DBus.Properties.Get", 0, dbusInterface, property).Store(&prop)
if err != nil {
return dbus.Variant{}, err
return nil, err
}

return prop, nil
return &prop, nil
}

0 comments on commit 5020cdb

Please sign in to comment.