From f52d12020cea94dc4e6c9e4d5b010ba82fe957e3 Mon Sep 17 00:00:00 2001 From: Luc Varoqui Date: Thu, 15 Oct 2026 18:16:30 +0200 Subject: [PATCH] fix: keep the user's HOME when wrapping commands with sudo Since we pass only `--preserve-env=` (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 --- src/executor/helpers/run_with_sudo.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/executor/helpers/run_with_sudo.rs b/src/executor/helpers/run_with_sudo.rs index 6b963222..f47c7ecc 100644 --- a/src/executor/helpers/run_with_sudo.rs +++ b/src/executor/helpers/run_with_sudo.rs @@ -111,6 +111,10 @@ pub fn wrap_with_sudo(mut cmd_builder: CommandBuilder) -> Result [ // Password prompt should not appear here since it has already been validated OsStr::new("--non-interactive"), + // Both forms are needed: sudo-rs ignores the bare flag, and with only the + // list classic sudo keeps `env_reset`, which lets variables exported by PAM + // session modules (e.g. HOME from pam_systemd) override the preserved ones. + OsStr::new("--preserve-env"), &preserve_env_arg(&cmd_builder), ], );