Repository navigation
fix: keep the user's HOME when wrapping commands with sudo - #588
Conversation
Since we pass only `--preserve-env=<list>` (for sudo-rs, which ignores the bare flag), classic sudo keeps `env_reset` on. Variables exported by PAM session modules then override the preserved ones: systemd >= 260's pam_systemd exports HOME, so on distros whose sudo PAM stack loads it (e.g. Arch) commands ran with HOME=/root. The samply re-exec then read root's CodSpeed config and failed when the selected profile only existed in the user's. Pass the bare `--preserve-env` as well: classic sudo disables `env_reset` and keeps HOME as before, and sudo-rs still honors the list. Refs COD-3305 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
[Medium impact] The change appears safe to merge. SummaryUpdates
Reviews (1) · Last reviewed commit: "fix: keep the user's HOME when wrapping ..." · Reviewed by Greptile |
Merging this PR will not alter performance
|
Pass the bare
--preserve-envto sudo alongside the explicit--preserve-env=<list>, so commands wrapped with sudo keep the invoking user'sHOMEagain.#574 switched to the list form because sudo-rs ignores the bare flag. With only the list, classic sudo keeps
env_reseton, and in that mode variables exported by PAM session modules override the preserved ones (env_mergeonly skips variables inenv_keep). Since systemd v260,pam_systemdalways exportsHOMEwith the target user's home directory, so on distros whose/etc/pam.d/sudoloads it (Arch:session optional pam_systemd.so class=none), wrapped commands ran withHOME=/root.One visible effect: the walltime samply re-exec inherits
CODSPEED_PROFILE, reads root's CodSpeed config, and fails withCodSpeed profile `<name>` does not existwhen the profile only exists in the user's config. Anything else run throughwrap_with_sudothat relies on the user'sHOME(toolchains, caches) was affected too.With both flags, classic sudo disables
env_reset(as before #574) and sudo-rs still honors the list.HOME,CODSPEED_PROFILEand an arbitrary variable reach the command unchanged with both flags on:HOME=/rootsudo.ws), Ubuntu 26.04HOME=/rootRefs COD-3305: that issue tracks Ubuntu 26.04 support, which this keeps working while fixing a regression it introduced elsewhere.