Bug ignored signals (#257)

* bugfix: Signals, like SIGKILL etc were ignored. Now we capture them and add the err to stderr

* bugfix: Signals, like SIGKILL etc were ignored. Now we capture them and add the err to stderr
This commit is contained in:
James Read 2024-04-01 21:30:34 +01:00 committed by GitHub
parent c4d1a2a105
commit ce670cf58c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 13 deletions

View File

@ -275,6 +275,12 @@ func wrapCommandInShell(ctx context.Context, finalParsedCommand string) *exec.Cm
return exec.CommandContext(ctx, "sh", "-c", finalParsedCommand)
}
func appendErrorToStderr(err error, logEntry *InternalLogEntry) {
if err != nil {
logEntry.Stderr = err.Error() + "\n\n" + logEntry.Stderr
}
}
func stepExec(req *ExecutionRequest) bool {
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(req.Action.Timeout)*time.Second)
defer cancel()
@ -292,18 +298,14 @@ func stepExec(req *ExecutionRequest) bool {
runerr := cmd.Start()
cmd.Wait()
// req.logEntry.Stdout = req.logEntry.StdoutBuffer.String()
// req.logEntry.Stderr = req.logEntry.StderrBuffer.String()
waiterr := cmd.Wait()
req.logEntry.ExitCode = int32(cmd.ProcessState.ExitCode())
req.logEntry.Stdout = stdout.String()
req.logEntry.Stderr = stderr.String()
if runerr != nil {
req.logEntry.Stderr = runerr.Error() + "\n\n" + req.logEntry.Stderr
}
appendErrorToStderr(runerr, req.logEntry)
appendErrorToStderr(waiterr, req.logEntry)
if ctx.Err() == context.DeadlineExceeded {
req.logEntry.TimedOut = true
@ -336,19 +338,16 @@ func stepExecAfter(req *ExecutionRequest) bool {
cmd := wrapCommandInShell(ctx, finalParsedCommand)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
req.logEntry.StdoutBuffer, _ = cmd.StdoutPipe()
req.logEntry.StderrBuffer, _ = cmd.StderrPipe()
runerr := cmd.Start()
cmd.Wait()
waiterr := cmd.Wait()
req.logEntry.Stdout += "---\n" + stdout.String()
req.logEntry.Stderr += "---\n" + stderr.String()
if runerr != nil {
req.logEntry.Stderr = runerr.Error() + "\n\n" + req.logEntry.Stderr
}
appendErrorToStderr(runerr, req.logEntry)
appendErrorToStderr(waiterr, req.logEntry)
if ctx.Err() == context.DeadlineExceeded {
req.logEntry.Stderr += "Your shellAfterCommand command timed out."