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