Skip to content

Commit

Permalink
fallback to cwd if unable to create tmpdir in /tmp amidaware/tactical…
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Mar 24, 2022
1 parent 1186089 commit c57c5a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
12 changes: 6 additions & 6 deletions agent/agent_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ func (a *Agent) RunScript(code string, shell string, args []string, timeout int)
code = removeWinNewLines(code)
content := []byte(code)

f, err := os.CreateTemp("", "trmm")
f, err := createTmpFile()
if err != nil {
a.Logger.Errorln(err)
a.Logger.Errorln("RunScript createTmpFile()", err)
return "", err.Error(), 85, err
}
defer os.Remove(f.Name())
Expand Down Expand Up @@ -187,9 +187,9 @@ func (a *Agent) AgentUpdate(url, inno, version string) {
return
}

f, err := os.CreateTemp("", "")
f, err := createTmpFile()
if err != nil {
a.Logger.Errorln("AgentUpdate()", err)
a.Logger.Errorln("AgentUpdate createTmpFile()", err)
return
}
defer os.Remove(f.Name())
Expand Down Expand Up @@ -232,9 +232,9 @@ func (a *Agent) AgentUpdate(url, inno, version string) {
}

func (a *Agent) AgentUninstall(code string) {
f, err := os.CreateTemp("", "trmm")
f, err := createTmpFile()
if err != nil {
a.Logger.Errorln("AgentUninstall CreateTemp:", err)
a.Logger.Errorln("AgentUninstall createTmpFile():", err)
return
}

Expand Down
16 changes: 16 additions & 0 deletions agent/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,19 @@ func randomCheckDelay() {
func removeWinNewLines(s string) string {
return strings.ReplaceAll(s, "\r\n", "\n")
}

func createTmpFile() (*os.File, error) {
var f *os.File
f, err := os.CreateTemp("", "trmm")
if err != nil {
cwd, err := os.Getwd()
if err != nil {
return f, err
}
f, err = os.CreateTemp(cwd, "trmm")
if err != nil {
return f, err
}
}
return f, nil
}

0 comments on commit c57c5a0

Please sign in to comment.