From 35a8e78f10ce8cf6a9c42f390d2862ec7ff67844 Mon Sep 17 00:00:00 2001 From: "Ronald G. Minnich" Date: Sat, 20 Jul 2024 15:58:50 -0700 Subject: [PATCH] cpu: add CPU_PWD environment variable sshd simulates a login and starts the process in $HOME. Add CPU_PWD, derived from PWD on the client, which cpuns can use to set the correct directory. Signed-off-by: Ronald G. Minnich --- cmds/cpu/cpu.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmds/cpu/cpu.go b/cmds/cpu/cpu.go index 8f4d816d..9d16fc4a 100644 --- a/cmds/cpu/cpu.go +++ b/cmds/cpu/cpu.go @@ -116,7 +116,7 @@ func getPort(host, port string) string { p = cp } } - if len(p) == 0 { + if len(p) == 0 { p = defaultPort verbose("getPort: return default %q", p) } @@ -134,8 +134,12 @@ func newCPU(host string, args ...string) (retErr error) { // If running over ssh, *srvnfs is true, then // we need to start cpuns, and pass the environment // as an argument. + // Also, because of how sshd works, we need to pass in + // a PWD that is correct; otherwise it gets lost, since + // since ssh wants to simulate a login.. if *ssh { - envargs := "-env=" + strings.Join(os.Environ(), "\n") + env := append(os.Environ(), "CPU_PWD="+os.Getenv("PWD")) + envargs := "-env=" + strings.Join(env, "\n") args = append([]string{"cpuns", envargs}, args...) } c := client.Command(host, args...)