From 22fbdbca40efa02556f47f6049c67c1fd3c99645 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 29 Aug 2022 20:58:48 +0530 Subject: [PATCH] Fix a regression in 0.26.0 that caused kitty to no longer set the LANG environment variable on macOS Happened because reading the locale uses cocoa APIs and they are not fork safe, so it was moved to after prewarm forking, but at that point the default child env had already been set. Fixes #5439 --- docs/changelog.rst | 2 ++ kitty/child.py | 4 ++++ kitty/main.py | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 2502605e5..06a407fd2 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -40,6 +40,8 @@ Detailed list of changes - ssh kitten: Fix executable permission missing from kitty bootstrap script (:iss:`5438`) +- Fix a regression in 0.26.0 that caused kitty to no longer set the ``LANG`` environment variable on macOS (:iss:`5439`) + 0.26.0 [2022-08-29] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/child.py b/kitty/child.py index b8095619f..400caf342 100644 --- a/kitty/child.py +++ b/kitty/child.py @@ -168,6 +168,10 @@ def set_default_env(val: Optional[Dict[str, str]] = None) -> None: setattr(default_env, 'lc_ctype_set_by_user', has_lctype) +def set_LANG_in_default_env(val: str) -> None: + default_env()['LANG'] = val + + def openpty() -> Tuple[int, int]: master, slave = os.openpty() # Note that master and slave are in blocking mode os.set_inheritable(slave, True) diff --git a/kitty/main.py b/kitty/main.py index 069466400..4cc37217b 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -10,7 +10,7 @@ from typing import Dict, Generator, List, Optional, Sequence, Tuple from .borders import load_borders_program from .boss import Boss -from .child import set_default_env +from .child import set_default_env, set_LANG_in_default_env from .cli import create_opts, parse_args from .cli_stub import CLIOptions from .conf.utils import BadLine @@ -229,6 +229,7 @@ def ensure_macos_locale() -> None: else: log_error(f'Could not set LANG Cocoa returns language as: {lang}') os.environ['LANG'] = f'{lang}.UTF-8' + set_LANG_in_default_env(os.environ['LANG']) @contextmanager @@ -368,6 +369,7 @@ def set_locale() -> None: except Exception: log_error('Failed to set locale with no LANG') os.environ['LANG'] = old_lang + set_LANG_in_default_env(old_lang) def _main() -> None: