Skip to content

fix(rootfs): boot with the assembled hostname, not a literal "eos" - #198

Open
harshini-5040 wants to merge 1 commit into
embeddedos-org:masterfrom
harshini-5040:fix/rootfs-rcs-hostname
Open

harshini-5040 wants to merge 1 commit into
embeddedos-org:masterfrom
harshini-5040:fix/rootfs-rcs-hostname

Conversation

@harshini-5040

@harshini-5040 harshini-5040 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Bug

RootfsBuilder.assemble(hostname=...) writes the hostname to /etc/hostname and /etc/hosts, but the generated /etc/init.d/rcS ran a literal hostname eos at boot. The board build calls assemble(hostname="eos-" + board.lower()) (ebuild/cli/commands.py), so for example an rpi4 image has eos-rpi4 in /etc/hostname and /etc/hosts but boots as eos. Its own /etc/hosts does not resolve that name, which leads to errors like "unable to resolve host" from tools such as sudo.

Root cause

install_init() wrote the rcS script with a hard-coded hostname. It ignored the value that configure_network() writes to /etc/hostname.

Fix

One line of rcS changes from:

hostname eos

to:

[ -s /etc/hostname ] && hostname -F /etc/hostname || hostname eos

BusyBox hostname supports -F FILE. The eos fallback keeps the previous behaviour when install_init() is used without configure_network(), or when /etc/hostname is empty. No signature or API changes.

Reproduction

from pathlib import Path
from ebuild.system.rootfs import RootfsBuilder
r = RootfsBuilder(Path("out")).assemble(hostname="eos-rpi4")
print((r / "etc/hostname").read_text(), (r / "etc/init.d/rcS").read_text())
  • Before: /etc/hostname contains eos-rpi4, but rcS runs hostname eos.
  • After: rcS sets the hostname from /etc/hostname.

Tests

New file tests/unit/test_rootfs_hostname.py with 2 tests: rcS takes the hostname from /etc/hostname, and the eos fallback still applies when install_init() is used on its own.

  • Without the fix: 2 failed. With the fix: the new tests plus test_rootfs_accounts.py give 30 passed.
  • I ran the new rcS line under sh with a stub hostname function: it ran hostname -F <file> when the file existed and hostname eos when it did not.
  • Full suite (Windows, Python 3.13, --ignore=tests/unit/test_hardware_validation_gate.py): 995 passed, 25 skipped, 3 failed. On master without this change: 993 passed, 25 skipped, and the same 3 failed. Those 3 are environment-only: jsonschema is not installed and gcc is not on PATH.
  • git diff --check: clean.

Not tested: booting a real image on BusyBox.

🤖 Generated with Claude Code

Summary by Sourcery

Boot assembled root filesystems with their configured hostname instead of a hard-coded name.

Bug Fixes:

  • Ensure root filesystems boot with the hostname assembled into /etc/hostname, while retaining eos as a fallback when no hostname is configured.

Tests:

  • Add unit coverage for configured-hostname boot behavior and the standalone install_init() fallback.

Closes #224

assemble(hostname=...) writes the name to /etc/hostname and /etc/hosts,
but rcS ran "hostname eos" at boot. The board build assembles with
hostname "eos-<board>", so those images booted as "eos" -- a name their
own /etc/hosts does not resolve. rcS now sets the hostname from
/etc/hostname and falls back to "eos" only when that file is absent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@claude claude Bot 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Update generated rcS to set the assembled hostname from /etc/hostname, retaining eos as the fallback, and explain the fallback in the script comment.

  • ebuild/system/rootfs.py L142-144

Documentation

Document the hostname mismatch and its fix in the changelog.

  • CHANGELOG.md L25-29

Tests

Add tests covering hostname selection from /etc/hostname and the fallback when the file is absent.

  • tests/unit/test_rootfs_hostname.py L1-40

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@kody-ai

kody-ai Bot commented Nov 16, 2026

Copy link
Copy Markdown

You've used all your free Kodus-paid PR reviews 🎁

Your trial is still active — this just means the PR reviews we cover during the trial are used up.

Connect your own AI key to keep Kody reviewing — unlimited reviews, on any plan (Free included).

Want more trial reviews to finish evaluating before adding a key? Talk to our founders. 😎

@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 263ed870-252c-4e5e-8871-d31dad65ff1f
Commits

Reviewing files that changed from the base of the PR and between 92a7138 and 0613251.

Files selected for processing: 3

  • CHANGELOG.md
  • ebuild/system/rootfs.py
  • tests/unit/test_rootfs_hostname.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="ebuild/system/rootfs.py" line_range="144" />
<code_context>
-            "hostname eos\n"
+            # configure_network() writes the assembled hostname here; "eos"
+            # only if it is absent (install_init() used on its own).
+            "[ -s /etc/hostname ] && hostname -F /etc/hostname || hostname eos\n"
             "echo 'EoS booted successfully'\n"
         )
</code_context>
<issue_to_address>
**Configured hostname gets replaced**

When `/etc/hostname` is non-empty and `hostname -F /etc/hostname` exits nonzero, the `|| hostname eos` branch in `rcS` masks the load failure and continues booting with `eos`, even though `/etc/hostname` and `/etc/hosts` name the configured host.

Use `eos` only when `/etc/hostname` is absent or empty, and let a failed hostname load remain an error.
</issue_to_address>

### Comment 2
<location path="tests/unit/test_rootfs_hostname.py" line_range="27" />
<code_context>
+    assert (rootfs / "etc" / "hostname").read_text() == "eos-rpi4\n"
+    rcs_lines = _rcs(rootfs).splitlines()
+    assert "hostname eos" not in rcs_lines
+    assert any("hostname -F /etc/hostname" in line for line in rcs_lines)
+
+
</code_context>
<issue_to_address>
**Hostname tests only inspect script text**

When rcS contains the expected command text in a non-executing or incorrectly branched command, `test_rcs_sets_the_hostname_from_etc_hostname` (line 27) and `test_rcs_keeps_eos_as_the_fallback_without_etc_hostname` (lines 38–39) only look for command strings. A broken rcS line such as `[ -s /etc/hostname ] && echo hostname -F /etc/hostname || hostname eos` satisfies both checks but never sets the configured hostname, so the tests pass while the bug remains.

Run the generated rcS under a shell with a stub `hostname` and assert which arguments are invoked for present and absent hostname files.

Also at `tests/unit/test_rootfs_hostname.py:38-39`.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: ebuild/system/rootfs.py:144, tests/unit/test_rootfs_hostname.py:27


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread ebuild/system/rootfs.py
"hostname eos\n"
# configure_network() writes the assembled hostname here; "eos"
# only if it is absent (install_init() used on its own).
"[ -s /etc/hostname ] && hostname -F /etc/hostname || hostname eos\n"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Configured hostname gets replaced

When /etc/hostname is non-empty and hostname -F /etc/hostname exits nonzero, the || hostname eos branch in rcS masks the load failure and continues booting with eos, even though /etc/hostname and /etc/hosts name the configured host.

Use eos only when /etc/hostname is absent or empty, and let a failed hostname load remain an error.

Prompt for AI agents
In `ebuild/system/rootfs.py` at line 144:

**Configured hostname gets replaced**

When `/etc/hostname` is non-empty and `hostname -F /etc/hostname` exits nonzero, the `|| hostname eos` branch in `rcS` masks the load failure and continues booting with `eos`, even though `/etc/hostname` and `/etc/hosts` name the configured host.

Use `eos` only when `/etc/hostname` is absent or empty, and let a failed hostname load remain an error.

From QUALITY.md L37-38:

- Never fail silently. A swallowed error is a defect that will be found later
  and cost more.

assert (rootfs / "etc" / "hostname").read_text() == "eos-rpi4\n"
rcs_lines = _rcs(rootfs).splitlines()
assert "hostname eos" not in rcs_lines
assert any("hostname -F /etc/hostname" in line for line in rcs_lines)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Hostname tests only inspect script text

When rcS contains the expected command text in a non-executing or incorrectly branched command, test_rcs_sets_the_hostname_from_etc_hostname (line 27) and test_rcs_keeps_eos_as_the_fallback_without_etc_hostname (lines 38–39) only look for command strings. A broken rcS line such as [ -s /etc/hostname ] && echo hostname -F /etc/hostname || hostname eos satisfies both checks but never sets the configured hostname, so the tests pass while the bug remains.

Run the generated rcS under a shell with a stub hostname and assert which arguments are invoked for present and absent hostname files.

Also at tests/unit/test_rootfs_hostname.py:38-39.

Prompt for AI agents
In `tests/unit/test_rootfs_hostname.py` at line 27:

**Hostname tests only inspect script text**

When rcS contains the expected command text in a non-executing or incorrectly branched command, `test_rcs_sets_the_hostname_from_etc_hostname` (line 27) and `test_rcs_keeps_eos_as_the_fallback_without_etc_hostname` (lines 38–39) only look for command strings. A broken rcS line such as `[ -s /etc/hostname ] && echo hostname -F /etc/hostname || hostname eos` satisfies both checks but never sets the configured hostname, so the tests pass while the bug remains.

Run the generated rcS under a shell with a stub `hostname` and assert which arguments are invoked for present and absent hostname files.

Also at `tests/unit/test_rootfs_hostname.py:38-39`.

@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026

Copy link
Copy Markdown

Linked issues

Checked at commit 0613251

#224 Rootfs boots with a literal "eos" hostname instead of the assembled one · 1 of 1 met

# Requirement Status Notes
1 Have rcS read the hostname from /etc/hostname when present, falling back to eos. ✅ Met rcS checks for a non-empty /etc/hostname and uses hostname -F; otherwise it runs hostname eos.

@Aswin-V

Aswin-V commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Held for rebase: this PR is in merge conflict with current master (9f49ca8) — the conflict is the shared CHANGELOG.md entry, which PR #195 also edited when it merged today. The source files do not overlap any merged PR, and premise + CI both passed on the current head, so this is merge-ready once rebased. Please rebase onto master, resolve the CHANGELOG conflict (keep both entries), and push — CI will re-run and the PR returns to the next merge train. — av_mando

This branch has not been deployed

No deployments
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.

Rootfs boots with a literal "eos" hostname instead of the assembled one

3 participants