From ac50980ba1c9b69217b794b860b6fddf18c28bc5 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 01:18:09 +0100 Subject: [PATCH] systemd-resolved: the names file write refuses naming its bound on the deadline (review r2 (3)) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Past WriteUplinkNamesBound (15 s) the refusal read the bare signal the deadline killed the process with ("install failed: signal: killed"); it now names the bound and says the file was left as it was, for either step (install or mv). Builds: design 08 sign-in-page §6, C-8 --- .../cmd/resolver-tools/resolver.go | 14 ++++++++++++-- .../cmd/resolver-tools/resolver_test.go | 12 ++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/systemd-resolved/cmd/resolver-tools/resolver.go b/modules/systemd-resolved/cmd/resolver-tools/resolver.go index 982bd2c8e..47bfb061a 100644 --- a/modules/systemd-resolved/cmd/resolver-tools/resolver.go +++ b/modules/systemd-resolved/cmd/resolver-tools/resolver.go @@ -579,13 +579,23 @@ func (r *Resolver) writeUplinkNamesFile(ctx context.Context, content []byte) err var stderr bytes.Buffer cmd.Stderr = &stderr if err := cmd.Run(); err != nil { + // Past the bound, name it and say the file was left as it was (review r2 (3)), never the bare + // signal the deadline killed the process with. + if ctx.Err() == context.DeadlineExceeded { + return fmt.Errorf("the names file's write did not finish within %s; it was left as it was", WriteUplinkNamesBound) + } if said := strings.TrimSpace(stderr.String()); said != "" { return fmt.Errorf("install: %s", said) } return fmt.Errorf("install failed: %w", err) } - _, err := r.Change(ctx, "mv", "-f", newPath, r.UplinkNamesFile) - return err + if _, err := r.Change(ctx, "mv", "-f", newPath, r.UplinkNamesFile); err != nil { + if ctx.Err() == context.DeadlineExceeded { + return fmt.Errorf("the names file's write did not finish within %s; it was left as it was", WriteUplinkNamesBound) + } + return err + } + return nil } // SetUplinkNames writes the host names the uplink's holder gives for its network's own check, through diff --git a/modules/systemd-resolved/cmd/resolver-tools/resolver_test.go b/modules/systemd-resolved/cmd/resolver-tools/resolver_test.go index f49345a3c..967da14d2 100644 --- a/modules/systemd-resolved/cmd/resolver-tools/resolver_test.go +++ b/modules/systemd-resolved/cmd/resolver-tools/resolver_test.go @@ -192,6 +192,18 @@ func TestChangesAreEscalatedOnlyWhenNotRoot(t *testing.T) { // Given names, uplink-names writes the file one a line and answers them (design 08 sign-in-page §2, §6; // R-1). +// Past the names file write's bound, the refusal names it and says the file was left as it was, never the +// bare signal the deadline killed the process with (design 08 sign-in-page §6; C-8, review r2 (3)). +func TestTheWriteRefusesNamingTheBoundOnTheDeadline(t *testing.T) { + r := aMachine(t, &fakeResolved{}, "tun0") + ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(-time.Minute)) + defer cancel() + err := r.writeUplinkNamesFile(ctx, []byte("check.example\n")) + if err == nil || !strings.Contains(err.Error(), WriteUplinkNamesBound.String()) || !strings.Contains(err.Error(), "left as it was") { + t.Errorf("the refusal is %v, want it to name %s and say the file was left as it was", err, WriteUplinkNamesBound) + } +} + func TestUplinkNamesWritesTheFileAndAnswersThem(t *testing.T) { f := &fakeResolved{} r := aMachine(t, f, "tun0")