logind

package
v0.3.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 9 Imported by: 5 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package logind is systemd-logind (org.freedesktop.login1) on the system bus as every lys process uses it: its names declared once, typed manager, session, seat and user handles, the calls, properties and signals lys makes and reads, and one context-bounded call path whose errors name the method and the object.

Index

Constants

View Source
const (
	BusName          = "org.freedesktop.login1"
	ManagerPath      = dbus.ObjectPath("/org/freedesktop/login1")
	ManagerInterface = BusName + ".Manager"
	SessionInterface = BusName + ".Session"
	SeatInterface    = BusName + ".Seat"
	UserInterface    = BusName + ".User"
)

The logind service, its manager object, and its interfaces.

View Source
const (
	ErrNoSuchSession       = BusName + ".NoSuchSession"
	ErrNoSessionForPID     = BusName + ".NoSessionForPID"
	ErrOperationInProgress = BusName + ".OperationInProgress"
)

The logind errors lys tells apart.

View Source
const CallTimeout = 5 * time.Second

CallTimeout bounds every call to logind, whatever the caller's context allows: a logind that does not answer never hangs its caller.

Variables

View Source
var (
	PrepareForSleep = dbusx.NewSignal[Sleep](ManagerInterface, "PrepareForSleep")
	Lock            = dbusx.NewSignal[Locked](SessionInterface, "Lock")
	Unlock          = dbusx.NewSignal[Unlocked](SessionInterface, "Unlock")
	PauseDevice     = dbusx.NewSignal[DevicePaused](SessionInterface, "PauseDevice")
	ResumeDevice    = dbusx.NewSignal[DeviceResumed](SessionInterface, "ResumeDevice")
)

The logind signals lys reads, each declared once: PrepareForSleep from the manager, the rest from a session.

View Source
var ErrDisconnected = dbusx.ErrDisconnected

ErrDisconnected is what Watch.Stop reports when the watch ended because its connection closed.

View Source
var ErrNoDisplay = errors.New("no display session")

ErrNoDisplay is User.Display for a user with no display session.

Functions

func Dial

func Dial(ctx context.Context) (*dbus.Conn, error)

Dial connects to the system bus, where logind is, giving up when ctx ends or after CallTimeout, whichever comes first, as every call does; once made, the connection outlives ctx and is the caller's to close.

func PrepareForSleepMatch

func PrepareForSleepMatch() []dbus.MatchOption

PrepareForSleepMatch matches PrepareForSleep from logind's manager.

func SessionPath

func SessionPath(id SessionID) dbus.ObjectPath

SessionPath is the object path logind serves the session id at: the id escaped as systemd escapes an object path label.

Types

type ActiveChanged

type ActiveChanged struct{ Active bool }

ActiveChanged is the session's Active property changing.

type Device

type Device struct{ Major, Minor uint32 }

Device is a character device by number, as logind's device calls and signals name it.

type DevicePaused

type DevicePaused struct {
	Major, Minor uint32
	Kind         PauseKind
}

DevicePaused is the session's PauseDevice signal.

func (DevicePaused) Device

func (p DevicePaused) Device() Device

Device is the paused device.

type DeviceResumed

type DeviceResumed struct {
	Major, Minor uint32
	FD           dbus.UnixFD
}

DeviceResumed is the session's ResumeDevice signal. FD is a new descriptor for the device, the handler's to close.

func (DeviceResumed) Device

func (r DeviceResumed) Device() Device

Device is the resumed device.

type Event

type Event interface {
	// contains filtered or unexported methods
}

Event is one decoded logind signal about a watched session: Sleep, Locked, Unlocked, DevicePaused, DeviceResumed, ActiveChanged or LockedHintChanged.

type InhibitMode

type InhibitMode uint8

InhibitMode is how an inhibitor holds its operations off.

const (
	InhibitBlock InhibitMode = iota + 1
	InhibitDelay
)

The inhibitor modes: InhibitBlock refuses the operations while held, InhibitDelay holds them off until released, at most logind's InhibitDelayMaxSec.

func (InhibitMode) String

func (m InhibitMode) String() string

String is the mode as logind's Inhibit takes it.

type InhibitWhat

type InhibitWhat uint8

InhibitWhat is the set of operations an inhibitor holds off.

const (
	InhibitShutdown InhibitWhat = 1 << iota
	InhibitSleep
	InhibitIdle
	InhibitLidSwitch
)

The operations an inhibitor can hold off.

func (InhibitWhat) String

func (w InhibitWhat) String() string

String is the set as logind's Inhibit takes it: the names joined by colons.

type Locked

type Locked struct{}

Locked is the session's Lock signal: its lock screen is to lock it.

type LockedHintChanged

type LockedHintChanged struct{ Locked bool }

LockedHintChanged is the session's LockedHint property changing.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is logind's manager object on one connection.

func NewManager

func NewManager(conn *dbus.Conn) Manager

NewManager is logind's manager on conn, the system bus.

func (Manager) ActivateSession

func (m Manager) ActivateSession(ctx context.Context, id SessionID) error

ActivateSession brings session id to the foreground of its seat, switching VT when it is on another.

func (Manager) GetSession

func (m Manager) GetSession(ctx context.Context, id SessionID) (Session, error)

GetSession resolves id, or AutoSession or SelfSession, to its session. The handle is the session's real path: logind sends its signals from that one, never from the auto or self alias.

func (Manager) GetSessionByPID

func (m Manager) GetSessionByPID(ctx context.Context, pid uint32) (Session, error)

GetSessionByPID is the session process pid belongs to; a process in none is logind's ErrNoSessionForPID.

func (Manager) Inhibit

func (m Manager) Inhibit(ctx context.Context, what InhibitWhat, who, why string, mode InhibitMode) (*os.File, error)

Inhibit takes an inhibitor on what for who, saying why: it holds until the returned file is closed.

func (Manager) LockSession

func (m Manager) LockSession(ctx context.Context, id SessionID) error

LockSession asks logind to lock session id: logind sends the session's Lock signal, which its lock screen answers.

func (Manager) Power

func (m Manager) Power(ctx context.Context, action PowerAction) error

Power asks logind to suspend, reboot or power off the system, never interactively: polkit decides without a prompt, as it does for the active local session.

func (Manager) SelfSession

func (m Manager) SelfSession() Session

SelfSession is logind's alias object for the caller's own session, for calls that need no signals: logind sends those from the real path (GetSession).

func (Manager) SelfUser

func (m Manager) SelfUser() User

SelfUser is logind's alias object for the calling user.

type PauseKind

type PauseKind string

PauseKind is how a PauseDevice pauses its device.

const (
	PausePause PauseKind = "pause"
	PauseForce PauseKind = "force"
	PauseGone  PauseKind = "gone"
)

The PauseDevice kinds: PausePause waits for PauseDeviceComplete, PauseForce has paused the device already, PauseGone says it was removed.

type PowerAction

type PowerAction uint8

PowerAction is what Manager.Power asks of the system.

const (
	Suspend PowerAction = iota + 1
	Reboot
	PowerOff
)

The power actions.

func (PowerAction) String

func (a PowerAction) String() string

String is the action as systemctl names it.

type Seat

type Seat struct {
	// contains filtered or unexported fields
}

Seat is one logind seat on one connection.

func (Seat) ID

func (s Seat) ID() SeatID

ID is the seat's id.

func (Seat) Path

func (s Seat) Path() dbus.ObjectPath

Path is the seat's object path.

func (Seat) SwitchTo

func (s Seat) SwitchTo(ctx context.Context, vt uint32) error

SwitchTo switches the seat to virtual terminal vt.

type SeatID

type SeatID string

SeatID is a logind seat id, such as seat0.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session is one logind session on one connection.

func (Session) Active

func (s Session) Active(ctx context.Context) (bool, error)

Active reads whether the session is in the foreground of its seat.

func (Session) ID

func (s Session) ID(ctx context.Context) (SessionID, error)

ID reads the session's Id.

func (Session) Lock

func (s Session) Lock(ctx context.Context) error

Lock asks logind to lock the session: logind sends the session's Lock signal, which its lock screen answers.

func (Session) LockedHint

func (s Session) LockedHint(ctx context.Context) (bool, error)

LockedHint reads whether the session's lock screen says it is locked.

func (Session) Path

func (s Session) Path() dbus.ObjectPath

Path is the session's object path.

func (Session) PauseDeviceComplete

func (s Session) PauseDeviceComplete(ctx context.Context, d Device) error

PauseDeviceComplete acknowledges a PauseDevice of kind PausePause: logind waits for it before switching the session away.

func (Session) ReleaseControl

func (s Session) ReleaseControl(ctx context.Context) error

ReleaseControl gives up control of the session, releasing every device the controller took.

func (Session) ReleaseDevice

func (s Session) ReleaseDevice(ctx context.Context, d Device) error

ReleaseDevice gives d back.

func (Session) Seat

func (s Session) Seat(ctx context.Context) (Seat, error)

Seat reads the seat the session is on; a session on none is an error.

func (Session) SetBrightness

func (s Session) SetBrightness(ctx context.Context, subsystem Subsystem, name string, value uint32) error

SetBrightness sets the raw brightness of the subsystem's device name, which the session may do without write access to sysfs.

func (Session) SetLockedHint

func (s Session) SetLockedHint(ctx context.Context, locked bool) error

SetLockedHint tells logind whether the session is locked.

func (Session) TakeControl

func (s Session) TakeControl(ctx context.Context, force bool) error

TakeControl makes the caller the session's controller, the one process that takes its devices; force takes it from another controller, which only root may.

func (Session) TakeDevice

func (s Session) TakeDevice(ctx context.Context, d Device) (fd int, inactive bool, err error)

TakeDevice opens d for the session's controller. The descriptor is the caller's to close; inactive says the session is in the background, where the device stays paused until ResumeDevice.

func (Session) Terminate

func (s Session) Terminate(ctx context.Context) error

Terminate ends the session and every process in it.

func (Session) WaitLocked

func (s Session) WaitLocked(ctx context.Context) (err error)

WaitLocked returns once the session's LockedHint is true, with ctx's error when it ends first, or with the failure to read a change of the session's properties that logind announced meanwhile: the hint may have been in it.

func (Session) Watch

func (s Session) Watch(ctx context.Context, handle func(Event, error)) (*Watch, error)

Watch runs handle, on the watch's goroutine and in arrival order, for every signal logind sends about the session (Lock, Unlock, PauseDevice, ResumeDevice, its Active and LockedHint changing) and for the manager's PrepareForSleep. Exactly one of handle's arguments is non-nil: the decoded Event, or why a signal from logind could not be decoded. Only signals from whoever owns logind's name as they arrive count, so the watch outlives a restart of logind; a ResumeDevice from anyone else has its descriptor closed. A DeviceResumed's descriptor is this watch's own: every watch of the session, on this connection or another, is handed one of its own. The watch holds match rules and a signal channel on the session's connection until it ends, and then removes them, leaving a shared connection as it was.

type SessionID

type SessionID string

SessionID is a logind session id, as XDG_SESSION_ID and the Id property carry it.

const (
	AutoSession SessionID = "auto"
	SelfSession SessionID = "self"
)

The session names logind resolves for the caller: AutoSession is the caller's own session or, for a caller outside any session (a service of the systemd user manager), the user's display session; SelfSession is the caller's own session only.

type Sleep

type Sleep struct{ Start bool }

Sleep is PrepareForSleep's argument: Start is true as the system is about to sleep, false once it has woken.

type Subsystem

type Subsystem uint8

Subsystem is the kind of device Session.SetBrightness drives.

const (
	Backlight Subsystem = iota + 1
	LEDs
)

The brightness subsystems.

func (Subsystem) String

func (s Subsystem) String() string

String is the subsystem as the kernel and logind name it.

type Unlocked

type Unlocked struct{}

Unlocked is the session's Unlock signal: its lock screen is to unlock it.

type User

type User struct {
	// contains filtered or unexported fields
}

User is one logind user on one connection.

func (User) Display

func (u User) Display(ctx context.Context) (Session, error)

Display reads the user's display session, the one a caller outside any session belongs to; a user with none is ErrNoDisplay.

func (User) Path

func (u User) Path() dbus.ObjectPath

Path is the user's object path.

type Watch

type Watch struct {
	// contains filtered or unexported fields
}

Watch follows one session's signals until its context ends, it is stopped, or its connection closes.

func (*Watch) Done

func (w *Watch) Done() <-chan struct{}

Done is closed once the watch has ended and removed what it held.

func (*Watch) Stop

func (w *Watch) Stop() error

Stop ends the watch and returns once it has removed what it held: with ErrDisconnected when its connection had closed, with the error removing its match rules met, or nil. Calling it again waits for the same end and reports the same error. Stop must not be called from the watch's handler.

Directories

Path Synopsis
Package logindtest is a fake systemd-logind on a private bus: the manager, the user's sessions on seat0, the calling user, the calls lys makes of them, and the signals logind sends.
Package logindtest is a fake systemd-logind on a private bus: the manager, the user's sessions on seat0, the calling user, the calls lys makes of them, and the signals logind sends.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL