forceExitAfter3TerminationSignals waits for the first termination signal to be caught and the context to be marked as done, then registers a new signal handler for subsequent signals. It forces the process to exit after 3 SIGTERM/SIGINT signals.
(ctx context.Context, streams command.Streams)
| 445 | // signal handler for subsequent signals. It forces the process to exit |
| 446 | // after 3 SIGTERM/SIGINT signals. |
| 447 | func forceExitAfter3TerminationSignals(ctx context.Context, streams command.Streams) { |
| 448 | // wait for the first signal to be caught and the context to be marked as done |
| 449 | <-ctx.Done() |
| 450 | // register a new signal handler for subsequent signals |
| 451 | sig := make(chan os.Signal, 2) |
| 452 | signal.Notify(sig, platformsignals.TerminationSignals...) |
| 453 | |
| 454 | // once we have received a total of 3 signals we force exit the cli |
| 455 | for range 2 { |
| 456 | <-sig |
| 457 | } |
| 458 | _, _ = fmt.Fprint(streams.Err(), "\ngot 3 SIGTERM/SIGINTs, forcefully exiting\n") |
| 459 | |
| 460 | // Restore terminal in case it was in raw mode. |
| 461 | restoreTerminal(streams) |
| 462 | os.Exit(1) |
| 463 | } |
| 464 | |
| 465 | // restoreTerminal restores the terminal if it was in raw mode; this prevents |
| 466 | // local echo from being disabled for the current terminal after forceful |
no test coverage detected
searching dependent graphs…