Skip to content

Read /etc/locale.conf when configuring the distro locale#40940

Open
i4M1k0SU wants to merge 1 commit into
microsoft:masterfrom
i4M1k0SU:init-read-locale-conf
Open

Read /etc/locale.conf when configuring the distro locale#40940
i4M1k0SU wants to merge 1 commit into
microsoft:masterfrom
i4M1k0SU:init-read-locale-conf

Conversation

@i4M1k0SU

Copy link
Copy Markdown

Summary of the Pull Request

init populates the distro's $LANG environment variable from
/etc/default/locale, but that was the only path checked. /etc/default/locale
is the Debian/Ubuntu convention; systemd-based distributions (Fedora, Arch,
openSUSE, ...) store the locale in /etc/locale.conf instead. On those distros
$LANG was never propagated from the distro's configuration.

This change makes ConfigUpdateLanguage check both locations and use the first
one that exists.

PR Checklist

Detailed Description of the Pull Request / Additional comments

  • Added LOCALE_CONF_FILE_PATH (/etc/locale.conf).
  • ConfigUpdateLanguage now tries /etc/default/locale then /etc/locale.conf,
    opening the first file that exists.
  • Both files use the same KEY=value format with a LANG= line, so the existing
    line-parsing logic is reused unchanged.
  • Behavior is preserved:
    • /etc/default/locale takes precedence when both files exist.
    • A missing file (ENOENT) is skipped silently; other fopen errors are still
      logged.
    • If neither file exists, $LANG is left unchanged.

Validation Steps Performed

  • Built the Linux init target (cross-compiled via the in-tree clang/LINUXSDK
    toolchain) — compiles cleanly.
  • Verified on Ubuntu (uses /etc/default/locale): existing behavior is
    preserved — $LANG is still propagated correctly.
  • Verified on Arch Linux (uses /etc/locale.conf): $LANG is now correctly
    propagated from the distro's locale configuration.

ConfigUpdateLanguage only read /etc/default/locale to populate the $LANG
environment variable. That path is used by Debian/Ubuntu, but systemd-based
distributions (Fedora, Arch, openSUSE, ...) store the locale in
/etc/locale.conf instead, so $LANG was never set on those distros.

Check both locations and use the first one that exists. Both files share the
same "LANG=" line format, so the existing parsing is reused unchanged.

Fixes microsoft#13207
Copilot AI review requested due to automatic review settings June 29, 2026 09:08
@i4M1k0SU i4M1k0SU requested a review from a team as a code owner June 29, 2026 09:08

Copilot AI 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.

Pull request overview

This PR updates Linux init locale propagation so $LANG can be sourced from both Debian/Ubuntu-style /etc/default/locale and systemd-style /etc/locale.conf, improving correctness for systemd-based distributions.

Changes:

  • Added /etc/locale.conf as an additional locale configuration path.
  • Updated ConfigUpdateLanguage to try multiple locale file locations and use the first successfully opened file.
  • Expanded function comments to document the multiple supported locations.

Comment thread src/linux/init/config.cpp
Comment thread src/linux/init/config.cpp
@i4M1k0SU

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@benhillis

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@benhillis

Copy link
Copy Markdown
Member

@i4M1k0SU - this change looks good, I am not sure why the policy bot check isn't working...

@i4M1k0SU

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@i4M1k0SU

Copy link
Copy Markdown
Author

@i4M1k0SU - this change looks good, I am not sure why the policy bot check isn't working...

Thanks! I re-commented and the policy bot check went green now.

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.

3 participants