systemd-resolved: the names file write refuses naming its bound on the deadline (review r2 (3))

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
This commit is contained in:
jochen
2026-11-25 01:18:09 +01:00
parent d859380669
commit ac50980ba1
2 changed files with 24 additions and 2 deletions
@@ -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
@@ -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")