systemd-resolved: checkUnknownPaths knows exactly its own files (review r2 (4))

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
This commit is contained in:
jochen
2026-11-25 01:17:26 +01:00
parent a74afe71f3
commit 8f86aedeae
2 changed files with 30 additions and 3 deletions
@@ -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 {
@@ -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")