Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

login1: add context-aware ListSessions and ListUsers methods #408

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions login1/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package login1

import (
"context"
"fmt"
"os"
"strconv"
Expand Down Expand Up @@ -253,10 +254,15 @@ func (c *Conn) GetSession(id string) (dbus.ObjectPath, error) {
return ret, nil
}

// ListSessions returns an array with all current sessions.
// Deprecated: use ListSessionsContext instead.
func (c *Conn) ListSessions() ([]Session, error) {
return c.ListSessionsContext(context.Background())
}

// ListSessionsContext returns an array with all current sessions.
func (c *Conn) ListSessionsContext(ctx context.Context) ([]Session, error) {
out := [][]interface{}{}
if err := c.object.Call(dbusInterface+".ListSessions", 0).Store(&out); err != nil {
if err := c.object.CallWithContext(ctx, dbusInterface+".ListSessions", 0).Store(&out); err != nil {
return nil, err
}

Expand All @@ -271,10 +277,15 @@ func (c *Conn) ListSessions() ([]Session, error) {
return ret, nil
}

// ListUsers returns an array with all currently logged in users.
// Deprecated: use ListUsersContext instead.
func (c *Conn) ListUsers() ([]User, error) {
return c.ListUsersContext(context.Background())
}

// ListUsersContext returns an array with all currently logged-in users.
func (c *Conn) ListUsersContext(ctx context.Context) ([]User, error) {
out := [][]interface{}{}
if err := c.object.Call(dbusInterface+".ListUsers", 0).Store(&out); err != nil {
if err := c.object.CallWithContext(ctx, dbusInterface+".ListUsers", 0).Store(&out); err != nil {
return nil, err
}

Expand Down