From 8f86aedeae12c6bb7e30591f3a8c772c9984fb3f Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 01:17:26 +0100 Subject: [PATCH] systemd-resolved: checkUnknownPaths knows exactly its own files (review r2 (4)) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It treated the verb's own uplink-names.new as unknown and accepted any bare *.tmp; it now knows exactly uplink-names, uplink-names.new, uplink-names.applied and uplink-names.applied.tmp, as §6 and §8 name them, and nothing else. Builds: design 08 sign-in-page §6, §8, C-7 --- .../cmd/resolver-tools/guard.go | 11 +++++++--- .../cmd/resolver-tools/guard_test.go | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/modules/systemd-resolved/cmd/resolver-tools/guard.go b/modules/systemd-resolved/cmd/resolver-tools/guard.go index 4f54d14fa..4552d03d1 100644 --- a/modules/systemd-resolved/cmd/resolver-tools/guard.go +++ b/modules/systemd-resolved/cmd/resolver-tools/guard.go @@ -571,13 +571,18 @@ func (g *Guard) checkUnknownPaths() { if err != nil { return } + // Exactly what this module writes there (review r2 (4)): the names file and the one §6 writes it + // beside (uplink-names, uplink-names.new), the applied record and the one it is written beside (§8: + // uplink-names.applied, uplink-names.applied.tmp). Nothing else, a bare *.tmp included. known := map[string]bool{ - filepath.Base(g.Resolver.UplinkNamesFile): true, - filepath.Base(g.Resolver.UplinkNamesAppliedFile): true, + filepath.Base(g.Resolver.UplinkNamesFile): true, + filepath.Base(g.Resolver.UplinkNamesFile) + ".new": true, + filepath.Base(g.Resolver.UplinkNamesAppliedFile): true, + filepath.Base(g.Resolver.UplinkNamesAppliedFile) + ".tmp": true, } for _, e := range entries { name := e.Name() - if known[name] || strings.HasSuffix(name, ".tmp") || g.unknownSaid[name] { + if known[name] || g.unknownSaid[name] { continue } if g.unknownSaid == nil { diff --git a/modules/systemd-resolved/cmd/resolver-tools/guard_test.go b/modules/systemd-resolved/cmd/resolver-tools/guard_test.go index f1b1a7070..6271f4b6d 100644 --- a/modules/systemd-resolved/cmd/resolver-tools/guard_test.go +++ b/modules/systemd-resolved/cmd/resolver-tools/guard_test.go @@ -364,6 +364,28 @@ func TestAnUnknownPathIsLeftAndJournalledOnce(t *testing.T) { } } +// The verb's own uplink-names.new and the guard's own uplink-names.applied.tmp are this module's, never +// said as unknown (design 08 sign-in-page §6, §8; review r2 (4)). +func TestItsOwnTemporaryFilesAreNeverSaidUnknown(t *testing.T) { + g, _, _, r := aGuardedMachineWithLinks(t, "wlan0") + // A directory of its own: /var/lib/node-resolver holds nothing but this module's files, unlike the + // fixture's shared one, which also keeps net/ and suffix for the Resolver's other paths. + dir := t.TempDir() + r.UplinkNamesFile = filepath.Join(dir, "uplink-names") + r.UplinkNamesAppliedFile = filepath.Join(dir, "uplink-names.applied") + for _, name := range []string{r.UplinkNamesFile + ".new", r.UplinkNamesAppliedFile + ".tmp"} { + if err := os.WriteFile(name, []byte(""), 0o644); err != nil { + t.Fatal(err) + } + } + var said []string + g.Log = func(format string, a ...any) { said = append(said, fmt.Sprintf(format, a...)) } + g.checkUnknownPaths() + if len(said) != 0 { + t.Errorf("said %v, want nothing for this module's own files", said) + } +} + // A changed list replaces the old one on the link, the route itself staying put (design 08 sign-in-page §9). func TestAChangedListReplacesTheOldOneOnTheLink(t *testing.T) { g, _, f, r := aGuardedMachineWithLinks(t, "wlan0")