From 5020cdb7d7179092527e91ad9c7766daf40b2719 Mon Sep 17 00:00:00 2001 From: ilyam8 Date: Wed, 31 Aug 2022 20:46:47 +0300 Subject: [PATCH] address review comments --- login1/dbus.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/login1/dbus.go b/login1/dbus.go index 15b3e4b..3ec7773 100644 --- a/login1/dbus.go +++ b/login1/dbus.go @@ -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" @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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) } @@ -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 } @@ -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) { @@ -381,9 +381,9 @@ 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) @@ -391,8 +391,8 @@ func (c *Conn) getProperty(ctx context.Context, path dbus.ObjectPath, dbusInterf 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 }