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
- Variables
- func Dial(ctx context.Context) (*dbus.Conn, error)
- func PrepareForSleepMatch() []dbus.MatchOption
- func SessionPath(id SessionID) dbus.ObjectPath
- type ActiveChanged
- type Device
- type DevicePaused
- type DeviceResumed
- type Event
- type InhibitMode
- type InhibitWhat
- type Locked
- type LockedHintChanged
- type Manager
- func (m Manager) ActivateSession(ctx context.Context, id SessionID) error
- func (m Manager) FollowLid(ctx context.Context, failed func(error), onChange func(closed bool)) (closed bool, w *Watch, err error)
- func (m Manager) GetSession(ctx context.Context, id SessionID) (Session, error)
- func (m Manager) GetSessionByPID(ctx context.Context, pid uint32) (Session, error)
- func (m Manager) Inhibit(ctx context.Context, what InhibitWhat, who, why string, mode InhibitMode) (*os.File, error)
- func (m Manager) LidClosed(ctx context.Context) (bool, error)
- func (m Manager) LockSession(ctx context.Context, id SessionID) error
- func (m Manager) Power(ctx context.Context, action PowerAction) error
- func (m Manager) SelfSession() Session
- func (m Manager) SelfUser() User
- type PauseKind
- type PowerAction
- type Seat
- type SeatID
- type Session
- func (s Session) Active(ctx context.Context) (bool, error)
- func (s Session) ID(ctx context.Context) (SessionID, error)
- func (s Session) IdleHint(ctx context.Context) (bool, error)
- func (s Session) Lock(ctx context.Context) error
- func (s Session) LockedHint(ctx context.Context) (bool, error)
- func (s Session) Path() dbus.ObjectPath
- func (s Session) PauseDeviceComplete(ctx context.Context, d Device) error
- func (s Session) ReleaseControl(ctx context.Context) error
- func (s Session) ReleaseDevice(ctx context.Context, d Device) error
- func (s Session) Seat(ctx context.Context) (Seat, error)
- func (s Session) SetBrightness(ctx context.Context, subsystem Subsystem, name string, value uint32) error
- func (s Session) SetIdleHint(ctx context.Context, idle bool) error
- func (s Session) SetLockedHint(ctx context.Context, locked bool) error
- func (s Session) TakeControl(ctx context.Context, force bool) error
- func (s Session) TakeDevice(ctx context.Context, d Device) (fd int, inactive bool, err error)
- func (s Session) Terminate(ctx context.Context) error
- func (s Session) WaitLocked(ctx context.Context) (err error)
- func (s Session) Watch(ctx context.Context, handle func(Event, error)) (*Watch, error)
- type SessionID
- type Sleep
- type Subsystem
- type Unlocked
- type User
- type Watch
Constants ¶
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.
const ( ErrNoSuchSession = BusName + ".NoSuchSession" ErrNoSessionForPID = BusName + ".NoSessionForPID" ErrOperationInProgress = BusName + ".OperationInProgress" )
The logind errors lys tells apart.
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 ¶
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.
var ErrDisconnected = dbusx.ErrDisconnected
ErrDisconnected is what Watch.Stop reports when the watch ended because its connection closed.
var ErrNoDisplay = errors.New("no display session")
ErrNoDisplay is User.Display for a user with no display session.
Functions ¶
func Dial ¶
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 ¶
DevicePaused is the session's PauseDevice signal.
type DeviceResumed ¶
DeviceResumed is the session's ResumeDevice signal. FD is a new descriptor for the device, the handler's to close.
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 ¶
NewManager is logind's manager on conn, the system bus.
func (Manager) ActivateSession ¶
ActivateSession brings session id to the foreground of its seat, switching VT when it is on another.
func (Manager) FollowLid ¶
func (m Manager) FollowLid(ctx context.Context, failed func(error), onChange func(closed bool)) (closed bool, w *Watch, err error)
FollowLid reads whether the lid is closed and then runs onChange, on the watch's goroutine and in arrival order, with every LidClosed logind announces. The read follows setting the watch up, so no change falls between the two. failed gets an announcement that could not be decoded and the watch's own failure.
func (Manager) GetSession ¶
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 ¶
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) LidClosed ¶
LidClosed reads whether the lid is closed: the switch state logind keeps from the lid devices, known at startup when no lid event has come yet.
func (Manager) LockSession ¶
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 ¶
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).
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.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is one logind session on one connection.
func (Session) Lock ¶
Lock asks logind to lock the session: logind sends the session's Lock signal, which its lock screen answers.
func (Session) LockedHint ¶
LockedHint reads whether the session's lock screen says it is locked.
func (Session) PauseDeviceComplete ¶
PauseDeviceComplete acknowledges a PauseDevice of kind PausePause: logind waits for it before switching the session away.
func (Session) ReleaseControl ¶
ReleaseControl gives up control of the session, releasing every device the controller took.
func (Session) ReleaseDevice ¶
ReleaseDevice gives d back.
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) SetIdleHint ¶
SetIdleHint tells logind whether the session is idle.
func (Session) SetLockedHint ¶
SetLockedHint tells logind whether the session is locked.
func (Session) TakeControl ¶
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 ¶
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) WaitLocked ¶
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 ¶
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.
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 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.
type Watch ¶
type Watch struct {
// contains filtered or unexported fields
}
Watch follows one logind object'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 ¶
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. |