hooks: skip non-existent CWD for remote sessions
If the session CWD does not exist locally (remote execution), do not set cmd.Dir. This prevents fork/exec failures when the CWD only exists on the remote host.
This commit is contained in:
parent
01e97daefc
commit
64ab94f121
|
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
|
@ -132,7 +133,12 @@ func runHookCmd(ctx context.Context, name, cmdStr string, payloadJSON []byte, cw
|
|||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
cmd.Stdin = bytes.NewReader(payloadJSON)
|
||||
if cwd != "" {
|
||||
cmd.Dir = paths.ExpandHome(cwd)
|
||||
expanded := paths.ExpandHome(cwd)
|
||||
// Only set Dir if the path exists locally (remote sessions
|
||||
// have a CWD that only exists on the remote host).
|
||||
if _, err := os.Stat(expanded); err == nil {
|
||||
cmd.Dir = expanded
|
||||
}
|
||||
}
|
||||
|
||||
// Inject payload map keys as OLLIE_* environment variables so hook
|
||||
|
|
|
|||
Reference in New Issue