Skip to content

Commit

Permalink
check: Support SIGTERM with --pause-on-fail
Browse files Browse the repository at this point in the history
If the user does --pause-on-fail and then does ctrl+c, it should
terminate the program rather than waiting for the user to input a line
first.

Signed-off-by: Joe Stringer <[email protected]>
  • Loading branch information
joestringer authored and michi-covalent committed Oct 13, 2023
1 parent f6d43e9 commit 8a38f71
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion connectivity/check/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
package check

import (
"context"
"fmt"
"io"
"os"
"os/signal"
"runtime"
"syscall"
"time"
)

Expand Down Expand Up @@ -286,7 +290,16 @@ func (t *Test) failCommon() {
t.flush()
if t.ctx.params.PauseOnFail {
t.log("Pausing after action failure, press the Enter key to continue:")
fmt.Scanln()
cont := make(chan struct{})
go func() {
fmt.Scanln()
close(cont)
}()
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
select {
case <-cont:
case <-ctx.Done():
}
}
if t.ctx.params.CollectSysdumpOnFailure {
t.collectSysdump()
Expand Down

0 comments on commit 8a38f71

Please sign in to comment.