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 ¶
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
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 ¶
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
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
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
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
ReadFacts asks logind for KillUserProcesses and uid's lingering. Both are unknown off Linux.
func (Facts) Survives ¶ added in v0.4.0
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
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 )
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
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.
func (Result) SurvivesLogout ¶ added in v0.4.0
SurvivesLogout reports whether the process outlives logout where it is now; known is false off Linux and when it cannot be told.