Adds error exit codes for SIGINT, SIGTERM and SIGKILL (#3662)

This commit is contained in:
ebozduman
2021-04-15 16:58:49 -07:00
committed by GitHub
parent b537ee408b
commit ef59238007
2 changed files with 22 additions and 2 deletions
+9
View File
@@ -42,6 +42,15 @@ const (
// Global error exit status.
globalErrorExitStatus = 1
// Global CTRL-C (SIGINT, #2) exit status.
globalCancelExitStatus = 130
// Global SIGKILL (#9) exit status.
globalKillExitStatus = 137
// Global SIGTERM (#15) exit status
globalTerminatExitStatus = 143
)
var (
+13 -2
View File
@@ -32,13 +32,24 @@ func trapSignals(sig ...os.Signal) {
signal.Notify(sigCh, sig...)
// Wait for the signal.
<-sigCh
s := <-sigCh
// Once signal has been received stop signal Notify handler.
signal.Stop(sigCh)
// Cancel the global context
globalCancel()
var exitCode int
switch s.String() {
case "interrupt":
exitCode = globalCancelExitStatus
case "killed":
exitCode = globalKillExitStatus
case "terminated":
exitCode = globalTerminatExitStatus
default:
exitCode = globalErrorExitStatus
}
os.Exit(exitCode)
}