logind

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 10 Imported by: 0 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 asks systemd-logind whether processes a user leaves running survive the end of the login session they were started from, and moves stagent's long-lived processes where they do.

With KillUserProcesses=yes (logind.conf) logind kills every process of a session's scope when the session ends, which would take holders started from an SSH or tty login with it. Processes in a scope of the user's service manager (what `systemd-run --user --scope` creates) are out of the session; they still end with the service manager at the user's last logout unless lingering is enabled. Terminals of a graphical session already run under the service manager, so they need lingering too.

Index

Constants

This section is empty.

Variables

View Source
var KillUserProcessesCmd = []string{
	"busctl", "get-property", "org.freedesktop.login1", "/org/freedesktop/login1",
	"org.freedesktop.login1.Manager", "KillUserProcesses",
}

KillUserProcessesCmd reads logind's KillUserProcesses setting; the output is parsed with ParseBusctlBool.

Functions

func LingerCmd added in v0.4.0

func LingerCmd(uid int) []string

LingerCmd reads whether lingering is enabled for uid; the output is parsed with ParseBusctlBool. It fails when the user has no logind user object (never logged in, no lingering).

func ParseBusctlBool

func ParseBusctlBool(out string) (v, ok bool)

ParseBusctlBool parses a boolean property as printed by busctl get-property ("b true"). ok is false for any other output.

func StartScopeCmd added in v0.4.0

func StartScopeCmd(unit string, pid int) []string

StartScopeCmd asks the user's service manager for a new transient scope unit holding pid: the D-Bus call `systemd-run --user --scope` makes.

func SystemdCgroup added in v0.4.0

func SystemdCgroup(procCgroup string) string

SystemdCgroup returns the cgroup path systemd tracks units by from the content of /proc/<pid>/cgroup: the name=systemd hierarchy of cgroup v1, else the unified (v2) one. "" when neither is there.

Types

type Facts added in v0.4.0

type Facts struct {
	Kill, KillKnown     bool // KillUserProcesses
	Linger, LingerKnown bool
}

Facts are logind's settings that decide whether a user's processes outlive logout. A *Known field false means logind could not be asked.

func ReadFacts added in v0.4.0

func ReadFacts(uid int) Facts

ReadFacts asks logind for KillUserProcesses and uid's lingering. Both are unknown off Linux.

func (Facts) Survives added in v0.4.0

func (f Facts) Survives(p Placement) (survives, known bool)

Survives reports whether a process placed at p outlives the user's logout (the last one, for the service manager); known is false when the placement or the logind setting it depends on is unknown.

func (Facts) WantScope added in v0.4.0

func (f Facts) WantScope() bool

WantScope reports whether a process should move into a scope of the user's service manager: it leaves a login session that would kill it (KillUserProcesses=yes), or lingering keeps the service manager past every logout. With KillUserProcesses=no and no lingering the login session outlives the last logout while the service manager does not, so moving would make things worse.

type Placement added in v0.4.0

type Placement int

Placement is where a process runs as far as logout is concerned.

const (
	PlaceUnknown Placement = iota
	// PlaceSession: the scope of a login session (session-N.scope).
	PlaceSession
	// PlaceManager: under the user's service manager (user@UID.service).
	PlaceManager
	// PlaceOther: outside the user's slice (a system service, a container
	// without systemd); logout does not end it.
	PlaceOther
)

func ParsePlacement added in v0.4.1

func ParsePlacement(s string) Placement

ParsePlacement returns the placement named s (String); PlaceUnknown for any other s.

func Place added in v0.4.0

func Place(cgroup string) Placement

Place classifies a cgroup path (SystemdCgroup).

func (Placement) String added in v0.4.1

func (p Placement) String() string

String is the placement's name ("session", "manager", "other"); "" for PlaceUnknown.

type Result added in v0.4.0

type Result struct {
	Facts
	// Cgroup is the process's systemd cgroup after Escape ("" unknown).
	Cgroup string
	// Moved: the process is in the new scope.
	Moved bool
}

Result is what Escape found and did.

func Escape added in v0.4.0

func Escape(prefix string) Result

Escape is the first thing `stagent run` and `stagent daemon` do on Linux: when Facts.WantScope, the process moves itself into a new transient scope of the user's service manager (unit "<prefix>-<pid>-<random>.scope") and waits until its cgroup has changed, so that everything it starts later (the agent, the daemon) starts there too. A process already in a service unit stays. Failing to move is not an error: the process runs on where it is, and Result says where that is.

Jump to

Keyboard shortcuts

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