From 349ef43a36c559445252c1311289effab458b611 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 01:12:23 +0100 Subject: [PATCH] networkmanager: a watcher refused at its start by a bus that is there exits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the first subscribe fails while the system bus's socket is already there, no file event will make it again: the watcher writes the reason to its journal and exits non-zero, so its unit shows failing instead of staying active and deaf. Builds: design 08 sign-in-page §14; lead answer C2-1 (hq f15bc2fd) --- .../networkmanager/cmd/uplink-tools/dbus.go | 6 +++++ .../networkmanager/cmd/uplink-tools/watch.go | 13 ++++++++-- .../cmd/uplink-tools/watch_test.go | 26 +++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/modules/networkmanager/cmd/uplink-tools/dbus.go b/modules/networkmanager/cmd/uplink-tools/dbus.go index 1d048070f..d2ba4f2b7 100644 --- a/modules/networkmanager/cmd/uplink-tools/dbus.go +++ b/modules/networkmanager/cmd/uplink-tools/dbus.go @@ -136,6 +136,12 @@ func (d *dbusSystem) rating() (Rating, error) { return r, nil } +// systemSocketExists says whether the system bus's socket is there now. +func systemSocketExists() bool { + _, err := os.Stat(systemSocket) + return err == nil +} + // systemSocketThere fires at each file event of the kernel that makes the system bus's socket in its folder, until stop // closes: the one moment, beside rating-again, the watcher dials the system bus again (§14; note d). It never fires // for a socket that is merely there, so a bus that refuses the watcher is not dialled again in a loop. diff --git a/modules/networkmanager/cmd/uplink-tools/watch.go b/modules/networkmanager/cmd/uplink-tools/watch.go index 21143627d..ce4108c0e 100644 --- a/modules/networkmanager/cmd/uplink-tools/watch.go +++ b/modules/networkmanager/cmd/uplink-tools/watch.go @@ -136,7 +136,9 @@ type Watcher struct { // SocketThere fires at the file event of the kernel that makes the system bus's socket in its folder; closing stop // ends the wait. SocketThere func(stop <-chan struct{}) <-chan struct{} - Now func() time.Time + // SocketExists says whether the system bus's socket is there now. + SocketExists func() bool + Now func() time.Time // UID is the watcher's account, whose sessions are the person's. UID uint32 // Environment reads the user manager's environment over a session's bus. @@ -170,7 +172,7 @@ type Watcher struct { func newWatcher(f Folder) *Watcher { w := &Watcher{Folder: f, Dial: dialSystemBus, SocketThere: systemSocketThere, Now: time.Now, asks: make(chan asked), - UID: uint32(os.Getuid()), Environment: userEnvironment, FileEvents: fileEvents, After: time.After, + UID: uint32(os.Getuid()), SocketExists: systemSocketExists, Environment: userEnvironment, FileEvents: fileEvents, After: time.After, Desk: newSessionDesk(), ends: make(chan func()), Made: pathsMade} w.Beside = w.besideLoop return w @@ -220,6 +222,13 @@ func (w *Watcher) run(stop <-chan struct{}) error { w.strange(p) } w.subscribe() + if !w.state.Subscribed && w.SocketExists != nil && w.SocketExists() { + // The socket is there and refused the watcher: no file event will make it again, so waiting would leave the + // unit active and the watcher deaf (design 08 sign-in-page §14; lead answer C2-1). + w.unsubscribe() + journal("the system bus's socket is there and the watcher could not subscribe on it at its start") + return errors.New("the system bus's socket is there and the watcher could not subscribe on it at its start") + } for { select { case <-stop: diff --git a/modules/networkmanager/cmd/uplink-tools/watch_test.go b/modules/networkmanager/cmd/uplink-tools/watch_test.go index 06f301bd9..b5225bf5a 100644 --- a/modules/networkmanager/cmd/uplink-tools/watch_test.go +++ b/modules/networkmanager/cmd/uplink-tools/watch_test.go @@ -439,6 +439,32 @@ func TestTheWatcherRedialsOnlyAtTheSocketsEventAndRatingAgain(t *testing.T) { close(stop) } +// When its first subscribe at its start fails while the system bus's socket is there, no file event will come: the +// watcher writes the reason to its journal and ends with an error, so its process exits non-zero (§14; lead answer +// C2-1). With no socket there it waits for the one that makes it, as above. +func TestARefusedStartWithTheSocketThereEndsTheWatcher(t *testing.T) { + lines := journalLines(t) + sys := &fakeSystem{socket: make(chan struct{}), refuse: 1} + w := aWatcher(t, sys) + w.SocketExists = func() bool { return true } + ended := make(chan error, 1) + go func() { ended <- w.run(make(chan struct{})) }() + answered := make(chan struct{}) + go func() { w.askLoop(askState); close(answered) }() + var err error + select { + case err = <-ended: + case <-answered: + t.Fatal("the watcher waits for a file event that will not come, its unit left active") + } + if _, dials := sys.counts(); err == nil || !strings.Contains(err.Error(), "at its start") || dials != 1 { + t.Fatalf("the watcher ended with %v after %d dials", err, dials) + } + if !strings.Contains(strings.Join(lines(), "\n"), "could not subscribe on it at its start") { + t.Fatalf("the reason is not in the journal: %q", lines()) + } +} + // The real wait fires at the file event that makes the system bus's socket, not for one that is merely there (note d). func TestTheSocketsWaitFiresWhenTheSocketIsMade(t *testing.T) { journalLines(t)