hostenv

package
v0.24.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hostenv is the single owner of the correction a GUI-launched process applies to the environment it hands to the shells it starts (GDK-2032).

Finder/Dock launches a process with launchd's environment: a four-entry PATH and no locale. A terminal pane started under it runs a non-login shell, which never reads the profiles that would fix either (/etc/zprofile's path_helper, ~/.zprofile's brew shellenv) — so brew-installed tools are invisible in the pane, and zsh's line editor cannot see multibyte input for want of LANG. The fix belongs in one place, not patched per call site: Resolve asks the login shell once what its environment is, Augment applies it to the current environment under a whitelist, and every child-spawning surface composes the two.

The whitelist is the load-bearing rule. A login shell's rc files can say anything — GADAK_WORKSPACE among them — and a variable some other window's identity exported must never overwrite this process's own: the pane's bare `gadak` points at the workspace the pane's serve named (internal/server/terminal.go), not at whatever a profile last set. Only PATH and the locale trio ever cross from the login environment.

Index

Constants

View Source
const GuardEnv = "GADAK_HOSTENV"

GuardEnv marks the probe child so a gadak started under it does not probe again: a login shell's rc file that launches a serve would otherwise recurse (login shell → rc → serve → Resolve → login shell …). The probe child carries GuardEnv=1, and Resolve refuses to run while the current process's own environment has it.

Variables

This section is empty.

Functions

func Augment

func Augment(goos string, base []string, login Login) []string

Augment returns the environment a child process should get: base (the current process environment, os.Environ()) plus what the login shell is allowed to contribute.

The rules, which the tests pin one by one:

  • PATH keeps every base entry in place and in order; entries that only the login PATH has are appended after them, in login order, with no duplicates. A base with no PATH at all takes the login PATH whole.
  • Locale: if base already carries a value in LC_ALL, LANG or LC_CTYPE, nothing is touched. Otherwise the login environment's trio is taken, and if it has none either, LANG is set — en_US.UTF-8 on darwin, C.UTF-8 elsewhere.
  • The whitelist: only PATH and the locale trio ever come from login. A login shell that says GADAK_WORKSPACE=other is ignored, because that variable names this process's own window.
  • windows returns base unchanged, and a failed Login leaves PATH as base had it and applies only the locale default: neither failure mode may keep a session from opening.

Path entries are split on os.PathListSeparator — ":" on every GOOS that reaches the merge, since windows returns before it.

func LocaleSource

func LocaleSource(goos string, base []string, login Login) string

LocaleSource names where Augment's locale came from: "base" (base already carried one, or the platform does no augmenting), "login" (the login shell's), or "default" (the floor Augment set itself). It is the diagnostic half of the same rule Augment applies, exposed once so a report cannot disagree with the merge it reports on.

Types

type Login

type Login struct {
	// Env is the "K=V" pairs the login shell reported; nil when
	// resolution failed. It carries only the keys Augment may consume —
	// PATH and the locale trio — because those are the whole whitelist;
	// the probe never asks for the rest.
	Env []string
	// Err is non-nil when the login shell could not be asked or did not
	// answer within the timeout. A failure is never fatal to the caller:
	// Augment still applies its locale default and the session opens on
	// the unaugmented environment.
	Err error
}

Login is what a login shell said its environment is.

func Resolve

func Resolve(ctx context.Context, goos, shell string) Login

Resolve runs `<shell> -l -c '<env dump>'` once and caches the result. goos is an argument, never runtime.GOOS inside this package: the same binary must be testable against all three platforms from one host.

An empty shell takes $SHELL, then /bin/sh — the same fallback order the terminal itself uses, so doctor's report and the pane's environment answer for the same shell. On windows there is no login shell to ask and no process is started.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL