Skip to content

Commit

Permalink
fix: chdir error when running custom modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jm33-m0 committed Dec 18, 2024
1 parent 40fd645 commit 66a699f
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions core/lib/agent/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ func moduleHandler(modName, checksum string) (out string) {
modDir := filepath.Join(RuntimeConfig.AgentRoot, modName)
startScript := fmt.Sprintf("%s.%s", modName, getScriptExtension())

var err error

// cd to module dir
cwd, err := os.Getwd()
if err != nil {
return fmt.Sprintf("getwd: %v", err)
}
defer os.Chdir(cwd)
defer os.Chdir(RuntimeConfig.AgentRoot)
os.Chdir(modDir)

// in memory execution?
Expand Down Expand Up @@ -100,11 +98,7 @@ func processModuleFiles(modDir string) error {

func runStartScript(startScript, modDir string) (string, error) {
// cd to module dir
cwd, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("getwd: %w", err)
}
defer os.Chdir(cwd)
defer os.Chdir(RuntimeConfig.AgentRoot)
os.Chdir(modDir)

// Download the script payload
Expand Down

0 comments on commit 66a699f

Please sign in to comment.