Running all commands in the same context

This commit is contained in:
Lilleman auf Larv 2024-02-03 10:40:54 +01:00
parent a4a2e15541
commit 0fa444ae74

12
main.go
View File

@ -156,6 +156,7 @@ func runCmd(log go_log.Log, workDir string, cmdStr string, uid int, gid int) (in
}
// Create the command
response += "Running command: " + cmdStr + "\n"
cmd := exec.Command("/bin/sh", "-c", cmdStr)
cmd.Dir = workDir
cmd.SysProcAttr = &syscall.SysProcAttr{}
@ -344,9 +345,13 @@ func main() {
res.Header().Set("Cache-Control", "no-cache")
res.Header().Set("Connection", "keep-alive")
for idx, command := range payload.Commands {
response += "Running command #" + fmt.Sprint(idx) + ": " + command + "\n"
exitCode, cmdRes, err := runCmd(log, workDir, command, uid, gid)
allCommands := "true"
for _, command := range payload.Commands {
allCommands += " && " + command
}
exitCode, cmdRes, err := runCmd(log, workDir, allCommands, uid, gid)
response += cmdRes
if err != nil {
response += "Command failed, err: " + err.Error() + "\n"
@ -360,7 +365,6 @@ func main() {
res.Write([]byte(response))
return
}
}
// If we get here, nothing have broken down, so 200 OK and send the full response
res.WriteHeader(200)