2021-09-09 14:25:25 +02:00
|
|
|
//go:build !windows && !plan9
|
|
|
|
// +build !windows,!plan9
|
2019-02-27 23:49:22 +01:00
|
|
|
|
|
|
|
package atexit
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"syscall"
|
2021-07-05 23:51:12 +02:00
|
|
|
|
|
|
|
"github.com/rclone/rclone/lib/exitcode"
|
2019-02-27 23:49:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var exitSignals = []os.Signal{syscall.SIGINT, syscall.SIGTERM} // Not syscall.SIGQUIT as we want the default behaviour
|
2021-07-05 23:51:12 +02:00
|
|
|
|
|
|
|
// exitCode calculates the exit code for the given signal. Many Unix programs
|
|
|
|
// exit with 128+signum if they handle signals. Most shell also implement the
|
|
|
|
// same convention if a program is terminated by an uncaught and/or fatal
|
|
|
|
// signal.
|
|
|
|
func exitCode(sig os.Signal) int {
|
|
|
|
if real, ok := sig.(syscall.Signal); ok && int(real) > 0 {
|
|
|
|
return 128 + int(real)
|
|
|
|
}
|
|
|
|
|
|
|
|
return exitcode.UncategorizedError
|
|
|
|
}
|