M3 networkmanager: the person's session

The watcher finds the person's graphical session from logind and the user manager's
environment, and acts on a session's start once that environment names a display; the
user manager sends no PropertiesChanged for Environment, so it is read again at the
file events on the X server's socket folder and the session's runtime directory, for
at most 60 s.

Builds: design 08 sign-in-page §15, §16, §17
This commit is contained in:
jochen
2026-11-24 21:18:36 +01:00
parent dc59860541
commit fee3f8ab8b
5 changed files with 584 additions and 16 deletions
@@ -14,12 +14,13 @@ import (
// The system bus stood in: the rating the test sets, each connection's signals on an unbuffered channel (a send
// returns once the watcher's loop took it), and the system bus's socket fired by the test.
type fakeSystem struct {
mu sync.Mutex
now Rating
reads int
dials int
buses []*fakeBus
socket chan struct{}
mu sync.Mutex
now Rating
sessions []loginSession
reads int
dials int
buses []*fakeBus
socket chan struct{}
}
type fakeBus struct {
@@ -56,7 +57,28 @@ func (s *fakeSystem) counts() (int, int) {
}
func (b *fakeBus) listen() (<-chan signal, error) { return b.signals, nil }
func (b *fakeBus) close() { b.closed = true }
func (b *fakeBus) sessions(uid uint32) ([]loginSession, error) {
b.sys.mu.Lock()
defer b.sys.mu.Unlock()
var out []loginSession
for _, s := range b.sys.sessions {
if s.UID == uid {
out = append(out, s)
}
}
return out, nil
}
func (b *fakeBus) session(path string) (loginSession, error) {
b.sys.mu.Lock()
defer b.sys.mu.Unlock()
for _, s := range b.sys.sessions {
if s.Path == path {
return s, nil
}
}
return loginSession{}, fmt.Errorf("no session %s", path)
}
func (b *fakeBus) close() { b.closed = true }
func (b *fakeBus) rating() (Rating, error) {
b.sys.mu.Lock()
defer b.sys.mu.Unlock()
@@ -95,7 +117,34 @@ func aWatcher(t *testing.T, sys *fakeSystem) *Watcher {
defer mu.Unlock()
tick = tick.Add(time.Second)
return tick
}, SocketThere: func(stop <-chan struct{}) <-chan struct{} { return sys.socket }, asks: make(chan asked)}
}, SocketThere: func(stop <-chan struct{}) <-chan struct{} { return sys.socket }, asks: make(chan asked),
UID: 1000, Desk: &fakeDesk{}, Environment: func(string) ([]string, error) { return nil, nil },
FileEvents: func([]string, <-chan struct{}) <-chan struct{} { return nil },
After: func(time.Duration) <-chan time.Time { return nil }}
}
// The desktop stood in: each open it was asked, answered with outcome.
type fakeDesk struct {
mu sync.Mutex
opens []string
outcome openOutcome
}
func (d *fakeDesk) open(s Session, address string) openOutcome {
d.mu.Lock()
defer d.mu.Unlock()
d.opens = append(d.opens, s.ID+" "+address)
o := d.outcome
if o.Outcome == "" {
o = openOutcome{Address: address, Program: "browser.desktop", Outcome: outcomeOpened}
}
return o
}
func (d *fakeDesk) opened() []string {
d.mu.Lock()
defer d.mu.Unlock()
return append([]string(nil), d.opens...)
}
// keptSaid is every kept event as `<event> <why> <network> <link>`, in order.