Skip to content

Symlink /etc/localtime and decide the hardware clock mode - #10

Merged
ericbsd merged 1 commit into
masterfrom
fix-390-utc-clock
Aug 29, 2026
Merged

ericbsd merged 1 commit into
masterfrom
fix-390-utc-clock

Conversation

@ericbsd

@ericbsd ericbsd commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

The first-boot setup picked a timezone but copied the zoneinfo file over /etc/localtime. A copy freezes the zone at setup time so tzdata updates never reach the system, and tools that read the zone name from the link target see nothing configured. /var/db/zoneinfo was never written either, which re-opened issue #49 on OEM images. Link it the way tzsetup(8) does and record the zone name.

The page also never asked whether the hardware clock keeps UTC or local time, so the system kept whatever the image shipped, which was local time. On a machine whose RTC keeps UTC the clock was then off by one UTC offset. Add a checkbox, checked by default, that adds or removes /etc/wall_cmos_clock and runs adjkerntz -i so the answer applies without a second reboot. The widget takes its initial state from SetupData so the page and the default cannot drift apart.

Resolves: ghostbsd/issues#390

Summary by Sourcery

Configure timezone links and hardware clock mode during first-boot setup.

New Features:

  • Add first-boot configuration for whether the hardware clock uses UTC or local time, defaulting to UTC and applying the choice immediately.

Bug Fixes:

  • Keep timezone configuration synchronized with tzdata updates and system tools by recording the zone name and using a symbolic link for /etc/localtime.
  • Correct the system clock according to the selected hardware clock mode without requiring an additional reboot.

Enhancements:

  • Expose the hardware clock preference in the timezone setup page and keep its initial state synchronized with setup data.

The first-boot setup picked a timezone but copied the zoneinfo file over
/etc/localtime. A copy freezes the zone at setup time so tzdata updates
never reach the system, and tools that read the zone name from the link
target see nothing configured. /var/db/zoneinfo was never written either,
which re-opened issue #49 on OEM images. Link it the way tzsetup(8) does
and record the zone name.

The page also never asked whether the hardware clock keeps UTC or local
time, so the system kept whatever the image shipped, which was local
time. On a machine whose RTC keeps UTC the clock was then off by one UTC
offset. Add a checkbox, checked by default, that adds or removes
/etc/wall_cmos_clock and runs adjkerntz -i so the answer applies without
a second reboot. The widget takes its initial state from SetupData so the
page and the default cannot drift apart.

Resolves: ghostbsd/issues#390
@ericbsd
ericbsd requested review from a team as code owners August 28, 2026 00:43
@sourcery-ai

sourcery-ai Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

The first-boot setup now configures timezones with a tzsetup-compatible symlink and persisted zone name, and adds a SetupData-backed hardware-clock choice that updates /etc/wall_cmos_clock and applies the setting immediately with adjkerntz.

Sequence diagram for timezone and hardware clock setup

sequenceDiagram
    participant User
    participant TimeZone
    participant SetupData
    participant SystemCalls
    participant Filesystem

    User->>TimeZone: toggle utc_selection(check_button)
    TimeZone->>SetupData: update utc_clock
    User->>TimeZone: complete setup
    TimeZone->>SystemCalls: apply_timezone()
    SystemCalls->>Filesystem: symlink /etc/localtime to zoneinfo
    SystemCalls->>Filesystem: write /var/db/zoneinfo
    TimeZone->>SystemCalls: apply_utc_clock()
    SystemCalls->>Filesystem: add or remove /etc/wall_cmos_clock
    SystemCalls->>SystemCalls: run(['adjkerntz', '-i'], check=True)
Loading

File-Level Changes

Change Details Files
Persist timezone configuration using a live zoneinfo symlink and the standard zone-name database file.
  • Validate the selected zoneinfo path as a regular file.
  • Replace /etc/localtime safely with a symlink to the selected zoneinfo file.
  • Write the selected zone name to /var/db/zoneinfo.
setup_station/system_calls.py
Add hardware-clock mode configuration that takes effect during first boot.
  • Track UTC-versus-local RTC mode in SetupData and reset it to the UTC default.
  • Add a checked-by-default timezone-page checkbox with Windows dual-boot guidance.
  • Create or remove /etc/wall_cmos_clock and run adjkerntz -i to apply the selection immediately.
  • Invoke hardware-clock configuration alongside timezone setup.
setup_station/data.py
setup_station/setup_system.py
setup_station/system_calls.py
setup_station/timezone.py

Assessment against linked issues

Issue Objective Addressed Explanation
ghostbsd/issues#390 Persist the selected time zone during installation so that the installed system has the correct zone configured and continues receiving tzdata updates. ✅
ghostbsd/issues#390 Configure the hardware clock mode during installation so the system clock remains correct across shutdowns and boots, including applying the setting immediately. ✅

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

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

## Individual Comments

### Comment 1
<location path="setup_station/system_calls.py" line_range="352-358" />
<code_context>

     try:
-        run(['cp', zoneinfo_path, localtime_path], check=True)
+        if os.path.lexists(localtime_path):
+            os.remove(localtime_path)
+        os.symlink(zoneinfo_path, localtime_path)
+        # Saved for tzsetup -r and for the login / lock screens
+        with open('/var/db/zoneinfo', 'w') as zoneinfo:
+            zoneinfo.write(f'{timezone}\n')
     except Exception as e:
         raise RuntimeError(f"Failed to set timezone '{timezone}': {e}") from e

</code_context>
<issue_to_address>
**issue (bug_risk):** The function removes the existing `/etc/localtime` before creating the replacement symlink and writing `/var/db/zoneinfo`; if either `os.symlink` or the zoneinfo file write fails, setup raises while leaving `/etc/localtime` missing or leaving the symlink and `/var/db/zoneinfo` out of sync.

**Triggers:** When the symlink creation or `/var/db/zoneinfo` write fails, such as from a filesystem or permission error.

**Suggested fix:** Build the new configuration atomically or restore the previous `/etc/localtime` and `/var/db/zoneinfo` values on failure.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and this changes persistent system time configuration and immediately adjusts the running clock with adjkerntz; if the timezone or UTC/local-clock choice is wrong, services can observe incorrect time and timestamps or fail time-sensitive operations. Reverting the files does not undo clock adjustments or timestamps already produced, although the system can be corrected by applying the proper configuration again.

Blocking findings: setup_station/system_calls.py:358


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread setup_station/system_calls.py Resolved
@ericbsd
ericbsd merged commit f633a27 into master Aug 29, 2026
2 checks passed
@ericbsd
ericbsd deleted the fix-390-utc-clock branch August 29, 2026 16:10
@github-project-automation github-project-automation Bot moved this from In Review to Done in Development Tracker Aug 29, 2026
@ericbsd ericbsd self-assigned this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Location and time zone not set during install

1 participant