Skip to content

platform: fix reversed bytes.Contains arguments in CheckMachine's systemd state check - #920

Draft
AdityaShome wants to merge 2 commits into
flatcar:mainfrom
AdityaShome:checkmachine-systemd-state
Draft

platform: fix reversed bytes.Contains arguments in CheckMachine's systemd state check#920
AdityaShome wants to merge 2 commits into
flatcar:mainfrom
AdityaShome:checkmachine-systemd-state

Conversation

@AdityaShome

Copy link
Copy Markdown

Description

CheckMachine checks systemctl is-system-running output against a list of known states, but both bytes.Contains(b, subslice) calls had their arguments backwards checking "is the state a substring of this literal" instead of "is the state one of these known values." It happened to work today because every real state name is a substring of the literal, but empty SSH output was silently treated as "still starting" instead of as an anomaly.

This PR extracts the check into a small systemRunningState helper. Empty or unrecognized output now stops polling immediately, same as "degraded", instead of being silently accepted.

How to use

No behavior change for real systemd states check that platform/platform.go's diff is small and that systemRunningState covers the same four states the old literal did. Run the test below to see the empty-output case is now handled.

Testing done

$ go build ./platform/... && go vet ./platform/...
$ gofmt -l platform/platform.go platform/platform_test.go
(clean)

$ go test ./platform/... -run TestSystemRunningState -v
--- PASS: TestSystemRunningState (0.00s)
    (9 subtests, all PASS, incl. empty_output)
PASS
  • Changelog entries added
  • Inspected CI output for image differences

Not applicable Go source change in mantle, not an OS image/ebuild change.

…ck and add a test for it

Signed-off-by: AdityaShome <shomeaditya65@gmail.com>
Copilot AI lite review requested due to automatic review settings August 11, 2026 19:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the systemd readiness-state parsing in CheckMachine by extracting it into a helper that correctly classifies systemctl is-system-running output, and adds a focused unit test to cover known states plus empty output.

Changes:

  • Extracted systemctl is-system-running output parsing into systemRunningState, replacing the prior bytes.Contains substring checks.
  • Changed polling behavior so empty/unrecognized output stops retrying immediately (matching the existing “degraded stops retrying” behavior).
  • Added TestSystemRunningState with subtests, including the empty-output case.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
platform/platform.go Introduces systemRunningState and uses it in CheckMachine to avoid reversed/unsafe substring matching.
platform/platform_test.go Adds unit tests for state classification, including empty output handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread platform/platform.go
Comment on lines +344 to +346
// systemRunningState classifies `systemctl is-system-running` output. keep
// is true while still on the way to "running"; anything else, including
// empty output, means stop retrying.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep=true doesn't actually mean retries continue. util.Retry stops on any nil return, which happens both when keep=false and when keep=true with state=="running" (success case). Retries only continue when keep=true and err != nil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants